Remove Baritone casts
This commit is contained in:
parent
f6dee1ecb7
commit
237f1846d3
@ -21,7 +21,7 @@ import baritone.api.behavior.ILookBehavior;
|
||||
import baritone.api.behavior.IMemoryBehavior;
|
||||
import baritone.api.behavior.IPathingBehavior;
|
||||
import baritone.api.cache.IWorldProvider;
|
||||
import baritone.api.event.listener.IGameEventListener;
|
||||
import baritone.api.event.listener.IEventBus;
|
||||
import baritone.api.process.ICustomGoalProcess;
|
||||
import baritone.api.process.IFollowProcess;
|
||||
import baritone.api.process.IGetToBlockProcess;
|
||||
@ -79,10 +79,5 @@ public interface IBaritone {
|
||||
|
||||
IPlayerContext getPlayerContext();
|
||||
|
||||
/**
|
||||
* Registers a {@link IGameEventListener} with Baritone's "event bus".
|
||||
*
|
||||
* @param listener The listener
|
||||
*/
|
||||
void registerEventListener(IGameEventListener listener);
|
||||
IEventBus getGameEventHandler();
|
||||
}
|
||||
|
36
src/api/java/baritone/api/event/listener/IEventBus.java
Normal file
36
src/api/java/baritone/api/event/listener/IEventBus.java
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.api.event.listener;
|
||||
|
||||
/**
|
||||
* A type of {@link IGameEventListener} that can have additional listeners
|
||||
* registered so that they receive the events that are dispatched to this
|
||||
* listener.
|
||||
*
|
||||
* @author Brady
|
||||
* @since 11/14/2018
|
||||
*/
|
||||
public interface IEventBus extends IGameEventListener {
|
||||
|
||||
/**
|
||||
* Registers the specified {@link IGameEventListener} to this event bus
|
||||
*
|
||||
* @param listener The listener
|
||||
*/
|
||||
void registerEventListener(IGameEventListener listener);
|
||||
}
|
@ -17,7 +17,6 @@
|
||||
|
||||
package baritone.launch.mixins;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.event.events.RotationMoveEvent;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
@ -54,7 +53,7 @@ public class MixinEntity {
|
||||
// noinspection ConstantConditions
|
||||
if (EntityPlayerSP.class.isInstance(this)) {
|
||||
this.motionUpdateRotationEvent = new RotationMoveEvent((EntityPlayerSP) (Object) this, RotationMoveEvent.Type.MOTION_UPDATE, this.rotationYaw);
|
||||
((Baritone) BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this)).getGameEventHandler().onPlayerRotationMove(this.motionUpdateRotationEvent);
|
||||
BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerRotationMove(this.motionUpdateRotationEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
package baritone.launch.mixins;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.event.events.RotationMoveEvent;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
@ -57,7 +56,7 @@ public abstract class MixinEntityLivingBase extends Entity {
|
||||
// noinspection ConstantConditions
|
||||
if (EntityPlayerSP.class.isInstance(this)) {
|
||||
this.jumpRotationEvent = new RotationMoveEvent((EntityPlayerSP) (Object) this, RotationMoveEvent.Type.JUMP, this.rotationYaw);
|
||||
((Baritone) BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this)).getGameEventHandler().onPlayerRotationMove(this.jumpRotationEvent);
|
||||
BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerRotationMove(this.jumpRotationEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
package baritone.launch.mixins;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.behavior.IPathingBehavior;
|
||||
import baritone.api.event.events.ChatEvent;
|
||||
@ -45,7 +44,7 @@ public class MixinEntityPlayerSP {
|
||||
)
|
||||
private void sendChatMessage(String msg, CallbackInfo ci) {
|
||||
ChatEvent event = new ChatEvent((EntityPlayerSP) (Object) this, msg);
|
||||
((Baritone) BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this)).getGameEventHandler().onSendChatMessage(event);
|
||||
BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onSendChatMessage(event);
|
||||
if (event.isCancelled()) {
|
||||
ci.cancel();
|
||||
}
|
||||
@ -61,7 +60,7 @@ public class MixinEntityPlayerSP {
|
||||
)
|
||||
)
|
||||
private void onPreUpdate(CallbackInfo ci) {
|
||||
((Baritone) BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this)).getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent((EntityPlayerSP) (Object) this, EventState.PRE));
|
||||
BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent((EntityPlayerSP) (Object) this, EventState.PRE));
|
||||
}
|
||||
|
||||
@Inject(
|
||||
@ -74,7 +73,7 @@ public class MixinEntityPlayerSP {
|
||||
)
|
||||
)
|
||||
private void onPostUpdate(CallbackInfo ci) {
|
||||
((Baritone) BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this)).getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent((EntityPlayerSP) (Object) this, EventState.POST));
|
||||
BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent((EntityPlayerSP) (Object) this, EventState.POST));
|
||||
}
|
||||
|
||||
@Redirect(
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
package baritone.launch.mixins;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.event.events.RenderEvent;
|
||||
@ -40,7 +39,7 @@ public class MixinEntityRenderer {
|
||||
)
|
||||
private void renderWorldPass(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) {
|
||||
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
|
||||
((Baritone) ibaritone).getGameEventHandler().onRenderPass(new RenderEvent(partialTicks));
|
||||
ibaritone.getGameEventHandler().onRenderPass(new RenderEvent(partialTicks));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ public class MixinMinecraft {
|
||||
? TickEvent.Type.IN
|
||||
: TickEvent.Type.OUT;
|
||||
|
||||
((Baritone) ibaritone).getGameEventHandler().onTick(new TickEvent(EventState.PRE, type));
|
||||
ibaritone.getGameEventHandler().onTick(new TickEvent(EventState.PRE, type));
|
||||
}
|
||||
|
||||
}
|
||||
@ -102,7 +102,7 @@ public class MixinMinecraft {
|
||||
)
|
||||
private void runTickKeyboard(CallbackInfo ci) {
|
||||
// keyboard input is only the primary baritone
|
||||
((Baritone) BaritoneAPI.getProvider().getPrimaryBaritone()).getGameEventHandler().onProcessKeyBinds();
|
||||
BaritoneAPI.getProvider().getPrimaryBaritone().getGameEventHandler().onProcessKeyBinds();
|
||||
}
|
||||
|
||||
@Inject(
|
||||
@ -117,7 +117,7 @@ public class MixinMinecraft {
|
||||
|
||||
// mc.world changing is only the primary baritone
|
||||
|
||||
((Baritone) BaritoneAPI.getProvider().getPrimaryBaritone()).getGameEventHandler().onWorldEvent(
|
||||
BaritoneAPI.getProvider().getPrimaryBaritone().getGameEventHandler().onWorldEvent(
|
||||
new WorldEvent(
|
||||
world,
|
||||
EventState.PRE
|
||||
@ -133,8 +133,7 @@ public class MixinMinecraft {
|
||||
// still fire event for both null, as that means we've just finished exiting a world
|
||||
|
||||
// mc.world changing is only the primary baritone
|
||||
|
||||
((Baritone) BaritoneAPI.getProvider().getPrimaryBaritone()).getGameEventHandler().onWorldEvent(
|
||||
BaritoneAPI.getProvider().getPrimaryBaritone().getGameEventHandler().onWorldEvent(
|
||||
new WorldEvent(
|
||||
world,
|
||||
EventState.POST
|
||||
@ -165,7 +164,7 @@ public class MixinMinecraft {
|
||||
)
|
||||
private void onBlockBreak(CallbackInfo ci, BlockPos pos) {
|
||||
// clickMouse is only for the main player
|
||||
((Baritone) BaritoneAPI.getProvider().getPrimaryBaritone()).getGameEventHandler().onBlockInteract(new BlockInteractEvent(pos, BlockInteractEvent.Type.BREAK));
|
||||
BaritoneAPI.getProvider().getPrimaryBaritone().getGameEventHandler().onBlockInteract(new BlockInteractEvent(pos, BlockInteractEvent.Type.BREAK));
|
||||
}
|
||||
|
||||
@Inject(
|
||||
@ -178,6 +177,6 @@ public class MixinMinecraft {
|
||||
)
|
||||
private void onBlockUse(CallbackInfo ci, EnumHand var1[], int var2, int var3, EnumHand enumhand, ItemStack itemstack, BlockPos blockpos, int i, EnumActionResult enumactionresult) {
|
||||
// rightClickMouse is only for the main player
|
||||
((Baritone) BaritoneAPI.getProvider().getPrimaryBaritone()).getGameEventHandler().onBlockInteract(new BlockInteractEvent(blockpos, BlockInteractEvent.Type.USE));
|
||||
BaritoneAPI.getProvider().getPrimaryBaritone().getGameEventHandler().onBlockInteract(new BlockInteractEvent(blockpos, BlockInteractEvent.Type.USE));
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
package baritone.launch.mixins;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.event.events.ChunkEvent;
|
||||
@ -47,7 +46,7 @@ public class MixinNetHandlerPlayClient {
|
||||
private void preRead(SPacketChunkData packetIn, CallbackInfo ci) {
|
||||
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
|
||||
if (ibaritone.getPlayerContext().player().connection == (NetHandlerPlayClient) (Object) this) {
|
||||
((Baritone) ibaritone).getGameEventHandler().onChunkEvent(
|
||||
ibaritone.getGameEventHandler().onChunkEvent(
|
||||
new ChunkEvent(
|
||||
EventState.PRE,
|
||||
ChunkEvent.Type.POPULATE,
|
||||
@ -66,7 +65,7 @@ public class MixinNetHandlerPlayClient {
|
||||
private void postHandleChunkData(SPacketChunkData packetIn, CallbackInfo ci) {
|
||||
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
|
||||
if (ibaritone.getPlayerContext().player().connection == (NetHandlerPlayClient) (Object) this) {
|
||||
((Baritone) ibaritone).getGameEventHandler().onChunkEvent(
|
||||
ibaritone.getGameEventHandler().onChunkEvent(
|
||||
new ChunkEvent(
|
||||
EventState.POST,
|
||||
ChunkEvent.Type.POPULATE,
|
||||
@ -88,7 +87,7 @@ public class MixinNetHandlerPlayClient {
|
||||
private void onPlayerDeath(SPacketCombatEvent packetIn, CallbackInfo ci) {
|
||||
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
|
||||
if (ibaritone.getPlayerContext().player().connection == (NetHandlerPlayClient) (Object) this) {
|
||||
((Baritone) ibaritone).getGameEventHandler().onPlayerDeath();
|
||||
ibaritone.getGameEventHandler().onPlayerDeath();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
package baritone.launch.mixins;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.event.events.PacketEvent;
|
||||
@ -61,7 +60,7 @@ public class MixinNetworkManager {
|
||||
|
||||
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
|
||||
if (ibaritone.getPlayerContext().player() != null && ibaritone.getPlayerContext().player().connection.getNetworkManager() == (NetworkManager) (Object) this) {
|
||||
((Baritone) ibaritone).getGameEventHandler().onSendPacket(new PacketEvent((NetworkManager) (Object) this, EventState.PRE, inPacket));
|
||||
ibaritone.getGameEventHandler().onSendPacket(new PacketEvent((NetworkManager) (Object) this, EventState.PRE, inPacket));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -77,7 +76,7 @@ public class MixinNetworkManager {
|
||||
|
||||
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
|
||||
if (ibaritone.getPlayerContext().player() != null && ibaritone.getPlayerContext().player().connection.getNetworkManager() == (NetworkManager) (Object) this) {
|
||||
((Baritone) ibaritone).getGameEventHandler().onSendPacket(new PacketEvent((NetworkManager) (Object) this, EventState.POST, inPacket));
|
||||
ibaritone.getGameEventHandler().onSendPacket(new PacketEvent((NetworkManager) (Object) this, EventState.POST, inPacket));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -95,7 +94,7 @@ public class MixinNetworkManager {
|
||||
}
|
||||
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
|
||||
if (ibaritone.getPlayerContext().player() != null && ibaritone.getPlayerContext().player().connection.getNetworkManager() == (NetworkManager) (Object) this) {
|
||||
((Baritone) ibaritone).getGameEventHandler().onReceivePacket(new PacketEvent((NetworkManager) (Object) this, EventState.PRE, packet));
|
||||
ibaritone.getGameEventHandler().onReceivePacket(new PacketEvent((NetworkManager) (Object) this, EventState.PRE, packet));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -110,7 +109,7 @@ public class MixinNetworkManager {
|
||||
}
|
||||
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
|
||||
if (ibaritone.getPlayerContext().player() != null && ibaritone.getPlayerContext().player().connection.getNetworkManager() == (NetworkManager) (Object) this) {
|
||||
((Baritone) ibaritone).getGameEventHandler().onReceivePacket(new PacketEvent((NetworkManager) (Object) this, EventState.POST, packet));
|
||||
ibaritone.getGameEventHandler().onReceivePacket(new PacketEvent((NetworkManager) (Object) this, EventState.POST, packet));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
package baritone.launch.mixins;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.event.events.ChunkEvent;
|
||||
@ -42,7 +41,7 @@ public class MixinWorldClient {
|
||||
private void preDoPreChunk(int chunkX, int chunkZ, boolean loadChunk, CallbackInfo ci) {
|
||||
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
|
||||
if (ibaritone.getPlayerContext().world() == (WorldClient) (Object) this) {
|
||||
((Baritone) ibaritone).getGameEventHandler().onChunkEvent(
|
||||
ibaritone.getGameEventHandler().onChunkEvent(
|
||||
new ChunkEvent(
|
||||
EventState.PRE,
|
||||
loadChunk ? ChunkEvent.Type.LOAD : ChunkEvent.Type.UNLOAD,
|
||||
@ -62,7 +61,7 @@ public class MixinWorldClient {
|
||||
private void postDoPreChunk(int chunkX, int chunkZ, boolean loadChunk, CallbackInfo ci) {
|
||||
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
|
||||
if (ibaritone.getPlayerContext().world() == (WorldClient) (Object) this) {
|
||||
((Baritone) ibaritone).getGameEventHandler().onChunkEvent(
|
||||
ibaritone.getGameEventHandler().onChunkEvent(
|
||||
new ChunkEvent(
|
||||
EventState.POST,
|
||||
loadChunk ? ChunkEvent.Type.LOAD : ChunkEvent.Type.UNLOAD,
|
||||
|
@ -20,7 +20,7 @@ package baritone;
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.event.listener.IGameEventListener;
|
||||
import baritone.api.event.listener.IEventBus;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.behavior.Behavior;
|
||||
import baritone.behavior.LookBehavior;
|
||||
@ -125,7 +125,7 @@ public class Baritone implements IBaritone {
|
||||
this.worldProvider = new WorldProvider();
|
||||
|
||||
if (BaritoneAutoTest.ENABLE_AUTO_TEST) {
|
||||
registerEventListener(BaritoneAutoTest.INSTANCE);
|
||||
this.gameEventHandler.registerEventListener(BaritoneAutoTest.INSTANCE);
|
||||
}
|
||||
|
||||
this.initialized = true;
|
||||
@ -135,17 +135,13 @@ public class Baritone implements IBaritone {
|
||||
return this.pathingControlManager;
|
||||
}
|
||||
|
||||
public IGameEventListener getGameEventHandler() {
|
||||
return this.gameEventHandler;
|
||||
}
|
||||
|
||||
public List<Behavior> getBehaviors() {
|
||||
return this.behaviors;
|
||||
}
|
||||
|
||||
public void registerBehavior(Behavior behavior) {
|
||||
this.behaviors.add(behavior);
|
||||
this.registerEventListener(behavior);
|
||||
this.gameEventHandler.registerEventListener(behavior);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -199,8 +195,8 @@ public class Baritone implements IBaritone {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerEventListener(IGameEventListener listener) {
|
||||
this.gameEventHandler.registerEventListener(listener);
|
||||
public IEventBus getGameEventHandler() {
|
||||
return this.gameEventHandler;
|
||||
}
|
||||
|
||||
public static Settings settings() {
|
||||
|
@ -20,6 +20,7 @@ package baritone.event;
|
||||
import baritone.Baritone;
|
||||
import baritone.api.event.events.*;
|
||||
import baritone.api.event.events.type.EventState;
|
||||
import baritone.api.event.listener.IEventBus;
|
||||
import baritone.api.event.listener.IGameEventListener;
|
||||
import baritone.cache.WorldProvider;
|
||||
import baritone.utils.Helper;
|
||||
@ -33,7 +34,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
* @author Brady
|
||||
* @since 7/31/2018
|
||||
*/
|
||||
public final class GameEventHandler implements IGameEventListener, Helper {
|
||||
public final class GameEventHandler implements IEventBus, Helper {
|
||||
|
||||
private final Baritone baritone;
|
||||
|
||||
@ -140,8 +141,8 @@ public final class GameEventHandler implements IGameEventListener, Helper {
|
||||
listeners.forEach(l -> l.onPathEvent(event));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void registerEventListener(IGameEventListener listener) {
|
||||
this.listeners.add(listener);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class PathingControlManager {
|
||||
public PathingControlManager(Baritone baritone) {
|
||||
this.baritone = baritone;
|
||||
this.processes = new HashSet<>();
|
||||
baritone.registerEventListener(new AbstractGameEventListener() { // needs to be after all behavior ticks
|
||||
baritone.getGameEventHandler().registerEventListener(new AbstractGameEventListener() { // needs to be after all behavior ticks
|
||||
@Override
|
||||
public void onTick(TickEvent event) {
|
||||
if (event.getType() == TickEvent.Type.OUT) {
|
||||
|
Loading…
Reference in New Issue
Block a user