Create and use injection point on pre/post jump, fixes #146

Also removed ItemSlotEvent because @leijurv is retarded
This commit is contained in:
Brady 2018-09-10 17:18:01 -05:00
parent d8790e1dc6
commit a67e6fd163
No known key found for this signature in database
GPG Key ID: 73A788379A197567
9 changed files with 106 additions and 68 deletions

View File

@ -18,7 +18,7 @@
package baritone.launch.mixins; package baritone.launch.mixins;
import baritone.Baritone; import baritone.Baritone;
import baritone.api.event.events.RelativeMoveEvent; import baritone.api.event.events.RotationMoveEvent;
import baritone.api.event.events.type.EventState; import baritone.api.event.events.type.EventState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity; 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) { private void preMoveRelative(float strafe, float up, float forward, float friction, CallbackInfo ci) {
Entity _this = (Entity) (Object) this; Entity _this = (Entity) (Object) this;
if (_this == Minecraft.getMinecraft().player) 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( @Inject(
@ -51,6 +51,6 @@ public class MixinEntity {
private void postMoveRelative(float strafe, float up, float forward, float friction, CallbackInfo ci) { private void postMoveRelative(float strafe, float up, float forward, float friction, CallbackInfo ci) {
Entity _this = (Entity) (Object) this; Entity _this = (Entity) (Object) this;
if (_this == Minecraft.getMinecraft().player) 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));
} }
} }

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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));
}
}

View File

@ -12,6 +12,7 @@
"MixinBlockPos", "MixinBlockPos",
"MixinChunkProviderServer", "MixinChunkProviderServer",
"MixinEntity", "MixinEntity",
"MixinEntityLivingBase",
"MixinEntityPlayerSP", "MixinEntityPlayerSP",
"MixinEntityRenderer", "MixinEntityRenderer",
"MixinGameSettings", "MixinGameSettings",

View File

@ -190,10 +190,10 @@ public final class GameEventHandler implements IGameEventListener, Helper {
} }
@Override @Override
public void onPlayerRelativeMove(RelativeMoveEvent event) { public void onPlayerRotationMove(RotationMoveEvent event) {
listeners.forEach(l -> { listeners.forEach(l -> {
if (canDispatch(l)) { if (canDispatch(l)) {
l.onPlayerRelativeMove(event); l.onPlayerRotationMove(event);
} }
}); });
} }

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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.
* <p>
* @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;
}
}

View File

@ -18,20 +18,28 @@
package baritone.api.event.events; package baritone.api.event.events;
import baritone.api.event.events.type.EventState; import baritone.api.event.events.type.EventState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
/** /**
* @author Brady * @author Brady
* @since 8/21/2018 * @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 * The state of the event
*/ */
private final EventState state; private final EventState state;
public RelativeMoveEvent(EventState state) { public RotationMoveEvent(EventState state, Type type) {
this.state = state; this.state = state;
this.type = type;
} }
/** /**
@ -40,4 +48,28 @@ public final class RelativeMoveEvent {
public final EventState getState() { public final EventState getState() {
return this.state; 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
}
} }

View File

@ -75,7 +75,7 @@ public interface AbstractGameEventListener extends IGameEventListener {
default void onReceivePacket(PacketEvent event) {} default void onReceivePacket(PacketEvent event) {}
@Override @Override
default void onPlayerRelativeMove(RelativeMoveEvent event) {} default void onPlayerRotationMove(RotationMoveEvent event) {}
@Override @Override
default void onBlockInteract(BlockInteractEvent event) {} default void onBlockInteract(BlockInteractEvent event) {}

View File

@ -43,6 +43,7 @@ import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.renderer.EntityRenderer; import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.settings.GameSettings; import net.minecraft.client.settings.GameSettings;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.network.NetworkManager; import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet; import net.minecraft.network.Packet;
import net.minecraft.util.text.ITextComponent; 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 * 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 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. * Called when the local player interacts with a block, whether it is breaking or opening/placing.

View File

@ -20,7 +20,7 @@ package baritone.behavior.impl;
import baritone.Baritone; import baritone.Baritone;
import baritone.Settings; import baritone.Settings;
import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.PlayerUpdateEvent;
import baritone.api.event.events.RelativeMoveEvent; import baritone.api.event.events.RotationMoveEvent;
import baritone.behavior.Behavior; import baritone.behavior.Behavior;
import baritone.utils.Rotation; import baritone.utils.Rotation;
@ -92,7 +92,7 @@ public class LookBehavior extends Behavior {
} }
@Override @Override
public void onPlayerRelativeMove(RelativeMoveEvent event) { public void onPlayerRotationMove(RotationMoveEvent event) {
if (this.target != null && !this.force) { if (this.target != null && !this.force) {
switch (event.getState()) { switch (event.getState()) {
case PRE: case PRE:
@ -103,7 +103,8 @@ public class LookBehavior extends Behavior {
player().rotationYaw = this.lastYaw; player().rotationYaw = this.lastYaw;
// If we have antiCheatCompatibility on, we're going to use the target value later in onPlayerUpdate() // 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; this.target = null;
} }
break; break;