diff --git a/src/main/java/one/oth3r/sit/Events.java b/src/main/java/one/oth3r/sit/Events.java index 9fd9ef8..5a610d7 100644 --- a/src/main/java/one/oth3r/sit/Events.java +++ b/src/main/java/one/oth3r/sit/Events.java @@ -167,6 +167,24 @@ public class Events { if (entity.getY() <= pos.getY()+.35+oneTwentyTwo) entity.setPitch(90); // below else entity.setPitch(-90); // above } + public static boolean sit(ServerPlayerEntity player, BlockPos pos) { + // todo interactions entity to make the sitting hitbox? + World world = player.getWorld(); + DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld()); + setEntity(pos,world,entity); + if (checkBlocks(pos,world,isAboveBlockheight(entity))) { + if (entities.containsKey(player)) { + if (!config.sitWhileSeated) return false; + entities.get(player).setRemoved(Entity.RemovalReason.DISCARDED); + entities.remove(player); + } + player.getServerWorld().spawnEntity(entity); + player.startRiding(entity); + entities.put(player,entity); + return true; + } + return false; + } public static void register() { ServerTickEvents.END_SERVER_TICK.register(minecraftServer -> minecraftServer.execute(Events::cleanUp)); // PLAYER JOIN @@ -196,22 +214,12 @@ public class Events { if (player == null) return ActionResult.PASS; if (hand == net.minecraft.util.Hand.MAIN_HAND && hitResult.getType() == HitResult.Type.BLOCK) { BlockPos pos = hitResult.getBlockPos(); + // check the players hands if (!checkLogic(player)) return ActionResult.PASS; - // todo interactions entity to make the hitbox? - // make the entity first before checking to make sure the blocks around are fine - DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld()); - setEntity(pos,world,entity); - if (checkBlocks(pos,world,isAboveBlockheight(entity))) { - if (entities.containsKey(player)) { - if (!config.sitWhileSeated) return ActionResult.PASS; - entities.get(player).setRemoved(Entity.RemovalReason.DISCARDED); - entities.remove(player); - } - player.getServerWorld().spawnEntity(entity); - player.startRiding(entity); - entities.put(player,entity); - return ActionResult.FAIL; - } + // make the player sit + boolean status = sit(player,pos); + // if sat, cancel / FAIL the use block event + if (status) return ActionResult.FAIL; } return ActionResult.PASS; }); diff --git a/src/main/java/one/oth3r/sit/SitCommand.java b/src/main/java/one/oth3r/sit/SitCommand.java index 0fee18c..281cd94 100644 --- a/src/main/java/one/oth3r/sit/SitCommand.java +++ b/src/main/java/one/oth3r/sit/SitCommand.java @@ -7,15 +7,12 @@ 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.concurrent.CompletableFuture; @@ -55,21 +52,14 @@ public class SitCommand { } if (args[0].equalsIgnoreCase("sit")) { BlockPos pos = player.getBlockPos(); - if (!(player.getY() -((int) player.getY()) > 0.00)) { + // get the block under the player if player on top of a solid + if (!(player.getY() - ((int) player.getY()) > 0.00)) { pos = pos.add(0,-1,0); } - World world = player.getWorld(); // if already sitting, ignore if (Events.entities.containsKey(player)) return 1; - // make entity first to check the blocks - DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld()); - Events.setEntity(pos,world,entity); - if (Events.checkBlocks(pos,world,Events.isAboveBlockheight(entity))) { - player.getServerWorld().spawnEntity(entity); - player.startRiding(entity); - Events.entities.put(player,entity); - return 1; - } + // sit + Events.sit(player,pos); } if (args[0].equalsIgnoreCase("reload")) { config.load();