diff --git a/src/launch/java/baritone/launch/mixins/MixinEntity.java b/src/launch/java/baritone/launch/mixins/MixinEntity.java index 2a0134d3..22be4154 100644 --- a/src/launch/java/baritone/launch/mixins/MixinEntity.java +++ b/src/launch/java/baritone/launch/mixins/MixinEntity.java @@ -18,7 +18,7 @@ package baritone.launch.mixins; import baritone.Baritone; -import baritone.api.event.events.RelativeMoveEvent; +import baritone.api.event.events.RotationMoveEvent; import baritone.api.event.events.type.EventState; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; @@ -41,7 +41,7 @@ public class MixinEntity { private void preMoveRelative(float strafe, float up, float forward, float friction, CallbackInfo ci) { Entity _this = (Entity) (Object) this; if (_this == Minecraft.getMinecraft().player) - Baritone.INSTANCE.getGameEventHandler().onPlayerRelativeMove(new RelativeMoveEvent(EventState.PRE)); + Baritone.INSTANCE.getGameEventHandler().onPlayerRotationMove(new RotationMoveEvent(EventState.PRE, RotationMoveEvent.Type.MOTION_UPDATE)); } @Inject( @@ -51,6 +51,6 @@ public class MixinEntity { private void postMoveRelative(float strafe, float up, float forward, float friction, CallbackInfo ci) { Entity _this = (Entity) (Object) this; if (_this == Minecraft.getMinecraft().player) - Baritone.INSTANCE.getGameEventHandler().onPlayerRelativeMove(new RelativeMoveEvent(EventState.POST)); + Baritone.INSTANCE.getGameEventHandler().onPlayerRotationMove(new RotationMoveEvent(EventState.POST, RotationMoveEvent.Type.MOTION_UPDATE)); } } diff --git a/src/launch/java/baritone/launch/mixins/MixinEntityLivingBase.java b/src/launch/java/baritone/launch/mixins/MixinEntityLivingBase.java new file mode 100644 index 00000000..61f6db7a --- /dev/null +++ b/src/launch/java/baritone/launch/mixins/MixinEntityLivingBase.java @@ -0,0 +1,57 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Baritone. If not, see . + */ + +package baritone.launch.mixins; + +import baritone.Baritone; +import baritone.api.event.events.RotationMoveEvent; +import baritone.api.event.events.type.EventState; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +/** + * @author Brady + * @since 9/10/2018 + */ +@Mixin(EntityLivingBase.class) +public class MixinEntityLivingBase { + + @Inject( + method = "jump", + at = @At("HEAD") + ) + private void preJump(CallbackInfo ci) { + Entity _this = (Entity) (Object) this; + if (_this == Minecraft.getMinecraft().player) + Baritone.INSTANCE.getGameEventHandler().onPlayerRotationMove(new RotationMoveEvent(EventState.PRE, RotationMoveEvent.Type.JUMP)); + } + + @Inject( + method = "jump", + at = @At("RETURN") + ) + private void postJump(CallbackInfo ci) { + Entity _this = (Entity) (Object) this; + if (_this == Minecraft.getMinecraft().player) + Baritone.INSTANCE.getGameEventHandler().onPlayerRotationMove(new RotationMoveEvent(EventState.POST, RotationMoveEvent.Type.JUMP)); + } +} diff --git a/src/launch/resources/mixins.baritone.json b/src/launch/resources/mixins.baritone.json index b1a8ed31..413bbbe7 100644 --- a/src/launch/resources/mixins.baritone.json +++ b/src/launch/resources/mixins.baritone.json @@ -12,6 +12,7 @@ "MixinBlockPos", "MixinChunkProviderServer", "MixinEntity", + "MixinEntityLivingBase", "MixinEntityPlayerSP", "MixinEntityRenderer", "MixinGameSettings", diff --git a/src/main/java/baritone/api/event/GameEventHandler.java b/src/main/java/baritone/api/event/GameEventHandler.java index 2ac27792..299ff323 100644 --- a/src/main/java/baritone/api/event/GameEventHandler.java +++ b/src/main/java/baritone/api/event/GameEventHandler.java @@ -190,10 +190,10 @@ public final class GameEventHandler implements IGameEventListener, Helper { } @Override - public void onPlayerRelativeMove(RelativeMoveEvent event) { + public void onPlayerRotationMove(RotationMoveEvent event) { listeners.forEach(l -> { if (canDispatch(l)) { - l.onPlayerRelativeMove(event); + l.onPlayerRotationMove(event); } }); } diff --git a/src/main/java/baritone/api/event/events/ItemSlotEvent.java b/src/main/java/baritone/api/event/events/ItemSlotEvent.java deleted file mode 100644 index 82e69177..00000000 --- a/src/main/java/baritone/api/event/events/ItemSlotEvent.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Baritone. If not, see . - */ - -package baritone.api.event.events; - -import baritone.api.event.listener.IGameEventListener; - -/** - * Called in some cases where a player's inventory has it's current slot queried. - *

- * @see IGameEventListener#onQueryItemSlotForBlocks() - * - * @author Brady - * @since 8/20/2018 - */ -public final class ItemSlotEvent { - - /** - * The current slot index - */ - private int slot; - - public ItemSlotEvent(int slot) { - this.slot = slot; - } - - /** - * Sets the new slot index that will be used - * - * @param slot The slot index - */ - public final void setSlot(int slot) { - this.slot = slot; - } - - /** - * @return The current slot index - */ - public final int getSlot() { - return this.slot; - } -} diff --git a/src/main/java/baritone/api/event/events/RelativeMoveEvent.java b/src/main/java/baritone/api/event/events/RotationMoveEvent.java similarity index 59% rename from src/main/java/baritone/api/event/events/RelativeMoveEvent.java rename to src/main/java/baritone/api/event/events/RotationMoveEvent.java index 14798fd5..7bedf857 100644 --- a/src/main/java/baritone/api/event/events/RelativeMoveEvent.java +++ b/src/main/java/baritone/api/event/events/RotationMoveEvent.java @@ -18,20 +18,28 @@ package baritone.api.event.events; import baritone.api.event.events.type.EventState; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; /** * @author Brady * @since 8/21/2018 */ -public final class RelativeMoveEvent { +public final class RotationMoveEvent { + + /** + * The type of event + */ + private final Type type; /** * The state of the event */ private final EventState state; - public RelativeMoveEvent(EventState state) { + public RotationMoveEvent(EventState state, Type type) { this.state = state; + this.type = type; } /** @@ -40,4 +48,28 @@ public final class RelativeMoveEvent { public final EventState getState() { return this.state; } + + /** + * @return The type of the event + */ + public final Type getType() { + return this.type; + } + + public enum Type { + + /** + * Called when the player's motion is updated. + * + * @see Entity#moveRelative(float, float, float, float) + */ + MOTION_UPDATE, + + /** + * Called when the player jumps. + * + * @see EntityLivingBase#jump + */ + JUMP + } } diff --git a/src/main/java/baritone/api/event/listener/AbstractGameEventListener.java b/src/main/java/baritone/api/event/listener/AbstractGameEventListener.java index 3b228e9d..5839e6d5 100644 --- a/src/main/java/baritone/api/event/listener/AbstractGameEventListener.java +++ b/src/main/java/baritone/api/event/listener/AbstractGameEventListener.java @@ -75,7 +75,7 @@ public interface AbstractGameEventListener extends IGameEventListener { default void onReceivePacket(PacketEvent event) {} @Override - default void onPlayerRelativeMove(RelativeMoveEvent event) {} + default void onPlayerRotationMove(RotationMoveEvent event) {} @Override default void onBlockInteract(BlockInteractEvent event) {} diff --git a/src/main/java/baritone/api/event/listener/IGameEventListener.java b/src/main/java/baritone/api/event/listener/IGameEventListener.java index 81f91774..c63cbfbc 100644 --- a/src/main/java/baritone/api/event/listener/IGameEventListener.java +++ b/src/main/java/baritone/api/event/listener/IGameEventListener.java @@ -43,6 +43,7 @@ import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.renderer.EntityRenderer; import net.minecraft.client.settings.GameSettings; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.util.text.ITextComponent; @@ -120,10 +121,12 @@ public interface IGameEventListener { /** * Run once per game tick from before and after the player's moveRelative method is called + * and before and after the player jumps. * * @see Entity#moveRelative(float, float, float, float) + * @see EntityLivingBase#jump() */ - void onPlayerRelativeMove(RelativeMoveEvent event); + void onPlayerRotationMove(RotationMoveEvent event); /** * Called when the local player interacts with a block, whether it is breaking or opening/placing. diff --git a/src/main/java/baritone/behavior/impl/LookBehavior.java b/src/main/java/baritone/behavior/impl/LookBehavior.java index b740618a..904087ab 100644 --- a/src/main/java/baritone/behavior/impl/LookBehavior.java +++ b/src/main/java/baritone/behavior/impl/LookBehavior.java @@ -20,7 +20,7 @@ package baritone.behavior.impl; import baritone.Baritone; import baritone.Settings; import baritone.api.event.events.PlayerUpdateEvent; -import baritone.api.event.events.RelativeMoveEvent; +import baritone.api.event.events.RotationMoveEvent; import baritone.behavior.Behavior; import baritone.utils.Rotation; @@ -92,7 +92,7 @@ public class LookBehavior extends Behavior { } @Override - public void onPlayerRelativeMove(RelativeMoveEvent event) { + public void onPlayerRotationMove(RotationMoveEvent event) { if (this.target != null && !this.force) { switch (event.getState()) { case PRE: @@ -103,7 +103,8 @@ public class LookBehavior extends Behavior { player().rotationYaw = this.lastYaw; // If we have antiCheatCompatibility on, we're going to use the target value later in onPlayerUpdate() - if (!Baritone.settings().antiCheatCompatibility.get()) { + // Also the type has to be MOTION_UPDATE because that is called after JUMP + if (!Baritone.settings().antiCheatCompatibility.get() && event.getType() == RotationMoveEvent.Type.MOTION_UPDATE) { this.target = null; } break;