From 08eddf5d62231d76543d930a56e4b257fee4e43f Mon Sep 17 00:00:00 2001 From: Oth3r Date: Wed, 2 Aug 2023 23:04:36 -0500 Subject: [PATCH] added '/sit' to sit on current block --- src/main/java/one/oth3r/sit/SitCommand.java | 26 +++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/one/oth3r/sit/SitCommand.java b/src/main/java/one/oth3r/sit/SitCommand.java index 68f64f1..ed05388 100644 --- a/src/main/java/one/oth3r/sit/SitCommand.java +++ b/src/main/java/one/oth3r/sit/SitCommand.java @@ -7,11 +7,15 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.decoration.DisplayEntity; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.TextColor; import net.minecraft.util.Formatting; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; import java.util.Objects; import java.util.concurrent.CompletableFuture; @@ -19,9 +23,10 @@ import java.util.concurrent.CompletableFuture; public class SitCommand { public static void register(CommandDispatcher dispatcher) { dispatcher.register(CommandManager.literal("sit") - .requires((commandSource) -> commandSource.hasPermissionLevel(2)) + .requires((commandSource) -> commandSource.hasPermissionLevel(0)) .executes((context2) -> command(context2.getSource(), context2.getInput())) .then(CommandManager.argument("args", StringArgumentType.string()) + .requires((commandSource) -> commandSource.hasPermissionLevel(2)) .suggests(SitCommand::getSuggestions) .executes((context2) -> command(context2.getSource(), context2.getInput())))); } @@ -44,7 +49,24 @@ public class SitCommand { String[] args = arg.split(" "); if (args[0].equalsIgnoreCase("sit")) args = arg.replaceFirst("sit ", "").split(" "); - + if (args[0].equalsIgnoreCase("sit")) { + BlockPos pos = player.getBlockPos(); + if (!(player.getY() -((int) player.getY()) > 0.00)) { + pos = pos.add(0,-1,0); + } + World world = player.getWorld(); + if (Events.checkBlocks(pos,world)) { + if (Events.entities.containsKey(player)) { + return 1; + } + DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld()); + Events.setEntity(pos,world,entity); + player.getServerWorld().spawnEntity(entity); + player.startRiding(entity); + Events.entities.put(player,entity); + return 1; + } + } if (args[0].equalsIgnoreCase("reload")) { config.load(); player.sendMessage(Sit.lang("key.sit.command.reloaded").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GREEN))));