From e44cf0d79b8d84d731d7a2c52b82763f5bdb4f70 Mon Sep 17 00:00:00 2001 From: gnembon Date: Fri, 10 Jan 2020 21:48:55 -0400 Subject: [PATCH] action pack improvements --- .../java/carpet/commands/PlayerCommand.java | 7 ++-- .../helpers/EntityPlayerActionPack.java | 38 ++++++++++++++----- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/main/java/carpet/commands/PlayerCommand.java b/src/main/java/carpet/commands/PlayerCommand.java index 1607bcd2..47c63e59 100644 --- a/src/main/java/carpet/commands/PlayerCommand.java +++ b/src/main/java/carpet/commands/PlayerCommand.java @@ -57,7 +57,8 @@ public class PlayerCommand .then(makeActionCommand("swapHands", EntityPlayerActionPack.ActionType.SWAP_HANDS)) .then(literal("kill").executes(PlayerCommand::kill)) .then(literal("shadow"). executes(PlayerCommand::shadow)) - .then(literal("mount").executes(manipulation(EntityPlayerActionPack::mount))) + .then(literal("mount").executes(manipulation(ap -> ap.mount(true))) + .then(literal("anything").executes(manipulation(ap -> ap.mount(false))))) .then(literal("dismount").executes(manipulation(EntityPlayerActionPack::dismount))) .then(literal("sneak").executes(manipulation(ap -> ap.setSneaking(true)))) .then(literal("unsneak").executes(manipulation(ap -> ap.setSneaking(false)))) @@ -78,7 +79,7 @@ public class PlayerCommand .then(literal("back").executes(c -> manipulate(c, ap -> ap.turn(180, 0)))) .then(argument("rotation", RotationArgumentType.rotation()) .executes(c -> manipulate(c, ap -> ap.turn(RotationArgumentType.getRotation(c, "rotation").toAbsoluteRotation(c.getSource()))))) - ).then(literal("move") + ).then(literal("move").executes(c -> manipulate(c, EntityPlayerActionPack::stopMovement)) .then(literal("forward").executes(c -> manipulate(c, ap -> ap.setForward(1)))) .then(literal("backward").executes(c -> manipulate(c, ap -> ap.setForward(-1)))) .then(literal("left").executes(c -> manipulate(c, ap -> ap.setStrafing(1)))) @@ -244,7 +245,7 @@ public class PlayerCommand { if (cantManipulate(context)) return 0; ServerPlayerEntity player = getPlayer(context); - ((ServerPlayerEntityInterface) player).getActionPack().stop(); + ((ServerPlayerEntityInterface) player).getActionPack().stopAll(); return 1; } diff --git a/src/main/java/carpet/helpers/EntityPlayerActionPack.java b/src/main/java/carpet/helpers/EntityPlayerActionPack.java index 346de1f4..f49a9fb0 100644 --- a/src/main/java/carpet/helpers/EntityPlayerActionPack.java +++ b/src/main/java/carpet/helpers/EntityPlayerActionPack.java @@ -1,9 +1,11 @@ package carpet.helpers; import carpet.fakes.ServerPlayerEntityInterface; -import carpet.mixins.PlayerActionC2SPacketMixin; import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; +import net.minecraft.entity.passive.HorseBaseEntity; +import net.minecraft.entity.vehicle.BoatEntity; +import net.minecraft.entity.vehicle.MinecartEntity; import net.minecraft.item.ItemStack; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.packet.PlayerActionC2SPacket; @@ -42,7 +44,7 @@ public class EntityPlayerActionPack public EntityPlayerActionPack(ServerPlayerEntity playerIn) { player = playerIn; - stop(); + stopAll(); } public void copyFrom(EntityPlayerActionPack other) { @@ -133,11 +135,8 @@ public class EntityPlayerActionPack return turn(rotation.x, rotation.y); } - - public EntityPlayerActionPack stop() + public EntityPlayerActionPack stopMovement() { - for (ActionType type : actions.keySet()) type.stop(player, actions.get(type)); - actions.clear(); setSneaking(false); setSprinting(false); forward = 0.0F; @@ -145,10 +144,27 @@ public class EntityPlayerActionPack return this; } - public EntityPlayerActionPack mount() + + public EntityPlayerActionPack stopAll() + { + for (ActionType type : actions.keySet()) type.stop(player, actions.get(type)); + actions.clear(); + return stopMovement(); + } + + public EntityPlayerActionPack mount(boolean onlyRideables) { //test what happens - List entities = player.world.getEntities(player,player.getBoundingBox().expand(3.0D, 1.0D, 3.0D)); + List entities; + if (onlyRideables) + { + entities = player.world.getEntities(player, player.getBoundingBox().expand(3.0D, 1.0D, 3.0D), + e -> e instanceof MinecartEntity || e instanceof BoatEntity || e instanceof HorseBaseEntity); + } + else + { + entities = player.world.getEntities(player, player.getBoundingBox().expand(3.0D, 1.0D, 3.0D)); + } if (entities.size()==0) return this; Entity closest = null; @@ -165,7 +181,11 @@ public class EntityPlayerActionPack closest = e; } } - if (closest != null) player.startRiding(closest,true); + if (closest == null) return this; + if (closest instanceof HorseBaseEntity && onlyRideables) + ((HorseBaseEntity) closest).interactMob(player, Hand.MAIN_HAND); + else + player.startRiding(closest,true); return this; } public EntityPlayerActionPack dismount()