not every player is a baritone
This commit is contained in:
		@@ -61,7 +61,7 @@ public interface IBaritoneProvider {
 | 
			
		||||
                return baritone;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        throw new IllegalStateException("No baritone for player " + player);
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,7 @@
 | 
			
		||||
package baritone.launch.mixins;
 | 
			
		||||
 | 
			
		||||
import baritone.api.BaritoneAPI;
 | 
			
		||||
import baritone.api.IBaritone;
 | 
			
		||||
import baritone.api.event.events.RotationMoveEvent;
 | 
			
		||||
import net.minecraft.client.entity.EntityPlayerSP;
 | 
			
		||||
import net.minecraft.entity.Entity;
 | 
			
		||||
@@ -55,8 +56,11 @@ public abstract class MixinEntityLivingBase extends Entity {
 | 
			
		||||
    private void preMoveRelative(CallbackInfo ci) {
 | 
			
		||||
        // noinspection ConstantConditions
 | 
			
		||||
        if (EntityPlayerSP.class.isInstance(this)) {
 | 
			
		||||
            this.jumpRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.JUMP, this.rotationYaw);
 | 
			
		||||
            BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerRotationMove(this.jumpRotationEvent);
 | 
			
		||||
            IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
 | 
			
		||||
            if (baritone != null) {
 | 
			
		||||
                this.jumpRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.JUMP, this.rotationYaw);
 | 
			
		||||
                baritone.getGameEventHandler().onPlayerRotationMove(this.jumpRotationEvent);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -69,7 +73,7 @@ public abstract class MixinEntityLivingBase extends Entity {
 | 
			
		||||
            )
 | 
			
		||||
    )
 | 
			
		||||
    private float overrideYaw(EntityLivingBase self) {
 | 
			
		||||
        if (self instanceof EntityPlayerSP) {
 | 
			
		||||
        if (self instanceof EntityPlayerSP && BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this) != null) {
 | 
			
		||||
            return this.jumpRotationEvent.getYaw();
 | 
			
		||||
        }
 | 
			
		||||
        return self.rotationYaw;
 | 
			
		||||
@@ -84,7 +88,7 @@ public abstract class MixinEntityLivingBase extends Entity {
 | 
			
		||||
    )
 | 
			
		||||
    private void travel(EntityLivingBase self, float strafe, float up, float forward, float friction) {
 | 
			
		||||
        // noinspection ConstantConditions
 | 
			
		||||
        if (!EntityPlayerSP.class.isInstance(this)) {
 | 
			
		||||
        if (!EntityPlayerSP.class.isInstance(this) || BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this) == null) {
 | 
			
		||||
            moveRelative(strafe, up, forward, friction);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,6 @@ package baritone.launch.mixins;
 | 
			
		||||
 | 
			
		||||
import baritone.api.BaritoneAPI;
 | 
			
		||||
import baritone.api.IBaritone;
 | 
			
		||||
import baritone.api.behavior.IPathingBehavior;
 | 
			
		||||
import baritone.api.event.events.ChatEvent;
 | 
			
		||||
import baritone.api.event.events.PlayerUpdateEvent;
 | 
			
		||||
import baritone.api.event.events.SprintStateEvent;
 | 
			
		||||
@@ -41,6 +40,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
 | 
			
		||||
@Mixin(EntityPlayerSP.class)
 | 
			
		||||
public class MixinEntityPlayerSP {
 | 
			
		||||
 | 
			
		||||
    private IBaritone baritone() {
 | 
			
		||||
        return
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Inject(
 | 
			
		||||
            method = "sendChatMessage",
 | 
			
		||||
            at = @At("HEAD"),
 | 
			
		||||
@@ -48,7 +51,11 @@ public class MixinEntityPlayerSP {
 | 
			
		||||
    )
 | 
			
		||||
    private void sendChatMessage(String msg, CallbackInfo ci) {
 | 
			
		||||
        ChatEvent event = new ChatEvent(msg);
 | 
			
		||||
        BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onSendChatMessage(event);
 | 
			
		||||
        IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
 | 
			
		||||
        if (baritone == null) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        baritone.getGameEventHandler().onSendChatMessage(event);
 | 
			
		||||
        if (event.isCancelled()) {
 | 
			
		||||
            ci.cancel();
 | 
			
		||||
        }
 | 
			
		||||
@@ -64,7 +71,10 @@ public class MixinEntityPlayerSP {
 | 
			
		||||
            )
 | 
			
		||||
    )
 | 
			
		||||
    private void onPreUpdate(CallbackInfo ci) {
 | 
			
		||||
        BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent(EventState.PRE));
 | 
			
		||||
        IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
 | 
			
		||||
        if (baritone != null) {
 | 
			
		||||
            baritone.getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent(EventState.PRE));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Inject(
 | 
			
		||||
@@ -77,7 +87,10 @@ public class MixinEntityPlayerSP {
 | 
			
		||||
            )
 | 
			
		||||
    )
 | 
			
		||||
    private void onPostUpdate(CallbackInfo ci) {
 | 
			
		||||
        BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent(EventState.POST));
 | 
			
		||||
        IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
 | 
			
		||||
        if (baritone != null) {
 | 
			
		||||
            baritone.getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent(EventState.POST));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Redirect(
 | 
			
		||||
@@ -88,8 +101,11 @@ public class MixinEntityPlayerSP {
 | 
			
		||||
            )
 | 
			
		||||
    )
 | 
			
		||||
    private boolean isAllowFlying(PlayerCapabilities capabilities) {
 | 
			
		||||
        IPathingBehavior pathingBehavior = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getPathingBehavior();
 | 
			
		||||
        return !pathingBehavior.isPathing() && capabilities.allowFlying;
 | 
			
		||||
        IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
 | 
			
		||||
        if (baritone == null) {
 | 
			
		||||
            return capabilities.allowFlying;
 | 
			
		||||
        }
 | 
			
		||||
        return !baritone.getPathingBehavior().isPathing() && capabilities.allowFlying;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Redirect(
 | 
			
		||||
@@ -100,8 +116,11 @@ public class MixinEntityPlayerSP {
 | 
			
		||||
            )
 | 
			
		||||
    )
 | 
			
		||||
    private boolean isKeyDown(KeyBinding keyBinding) {
 | 
			
		||||
        SprintStateEvent event = new SprintStateEvent();
 | 
			
		||||
        IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
 | 
			
		||||
        if (baritone == null) {
 | 
			
		||||
            return keyBinding.isKeyDown();
 | 
			
		||||
        }
 | 
			
		||||
        SprintStateEvent event = new SprintStateEvent();
 | 
			
		||||
        baritone.getGameEventHandler().onPlayerSprintState(event);
 | 
			
		||||
        if (event.getState() != null) {
 | 
			
		||||
            return event.getState();
 | 
			
		||||
@@ -120,6 +139,9 @@ public class MixinEntityPlayerSP {
 | 
			
		||||
            )
 | 
			
		||||
    )
 | 
			
		||||
    private void updateRidden(CallbackInfo cb) {
 | 
			
		||||
        ((LookBehavior) BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getLookBehavior()).pig();
 | 
			
		||||
        IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
 | 
			
		||||
        if (baritone != null) {
 | 
			
		||||
            ((LookBehavior) baritone.getLookBehavior()).pig();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user