Merge branch 'master' of github.com:cabaletta/baritone
This commit is contained in:
commit
9e8154dd5e
@ -102,6 +102,16 @@ public final class GameEventHandler implements IGameEventListener {
|
|||||||
dispatch(behavior -> behavior.onWorldEvent(event));
|
dispatch(behavior -> behavior.onWorldEvent(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSendPacket(PacketEvent event) {
|
||||||
|
dispatch(behavior -> behavior.onSendPacket(event));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceivePacket(PacketEvent event) {
|
||||||
|
dispatch(behavior -> behavior.onReceivePacket(event));
|
||||||
|
}
|
||||||
|
|
||||||
private void dispatch(Consumer<Behavior> dispatchFunction) {
|
private void dispatch(Consumer<Behavior> dispatchFunction) {
|
||||||
Baritone.INSTANCE.getBehaviors().stream().filter(Behavior::isEnabled).forEach(dispatchFunction);
|
Baritone.INSTANCE.getBehaviors().stream().filter(Behavior::isEnabled).forEach(dispatchFunction);
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,6 @@ import baritone.bot.event.events.*;
|
|||||||
* overridden with empty bodies, allowing inheritors of this class to choose
|
* overridden with empty bodies, allowing inheritors of this class to choose
|
||||||
* which events they would like to listen in on.
|
* which events they would like to listen in on.
|
||||||
*
|
*
|
||||||
* Has no implementors at the moment, but will likely be used with the
|
|
||||||
* manager/behavior system is ported over to the new system.
|
|
||||||
*
|
|
||||||
* @see IGameEventListener
|
* @see IGameEventListener
|
||||||
*
|
*
|
||||||
* @author Brady
|
* @author Brady
|
||||||
@ -37,4 +34,10 @@ public interface AbstractGameEventListener extends IGameEventListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void onWorldEvent(WorldEvent event) {}
|
default void onWorldEvent(WorldEvent event) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default void onSendPacket(PacketEvent event) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default void onReceivePacket(PacketEvent event) {}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
package baritone.bot.event;
|
package baritone.bot.event;
|
||||||
|
|
||||||
import baritone.bot.event.events.*;
|
import baritone.bot.event.events.*;
|
||||||
|
import io.netty.util.concurrent.GenericFutureListener;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
import net.minecraft.client.multiplayer.WorldClient;
|
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.network.NetworkManager;
|
||||||
|
import net.minecraft.network.Packet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Brady
|
* @author Brady
|
||||||
@ -40,7 +43,6 @@ public interface IGameEventListener {
|
|||||||
*/
|
*/
|
||||||
void onSendChatMessage(ChatEvent event);
|
void onSendChatMessage(ChatEvent event);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs before and after whenever a chunk is either loaded, unloaded, or populated.
|
* Runs before and after whenever a chunk is either loaded, unloaded, or populated.
|
||||||
*
|
*
|
||||||
@ -63,4 +65,18 @@ public interface IGameEventListener {
|
|||||||
* @see Minecraft#loadWorld(WorldClient, String)
|
* @see Minecraft#loadWorld(WorldClient, String)
|
||||||
*/
|
*/
|
||||||
void onWorldEvent(WorldEvent event);
|
void onWorldEvent(WorldEvent event);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs before a outbound packet is sent
|
||||||
|
*
|
||||||
|
* @see NetworkManager#dispatchPacket(Packet, GenericFutureListener[])
|
||||||
|
*/
|
||||||
|
void onSendPacket(PacketEvent event);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs before an inbound packet is processed
|
||||||
|
*
|
||||||
|
* @see NetworkManager#dispatchPacket(Packet, GenericFutureListener[])
|
||||||
|
*/
|
||||||
|
void onReceivePacket(PacketEvent event);
|
||||||
}
|
}
|
||||||
|
20
src/main/java/baritone/bot/event/events/PacketEvent.java
Normal file
20
src/main/java/baritone/bot/event/events/PacketEvent.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package baritone.bot.event.events;
|
||||||
|
|
||||||
|
import net.minecraft.network.Packet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brady
|
||||||
|
* @since 8/6/2018 9:31 PM
|
||||||
|
*/
|
||||||
|
public final class PacketEvent {
|
||||||
|
|
||||||
|
private final Packet<?> packet;
|
||||||
|
|
||||||
|
public PacketEvent(Packet<?> packet) {
|
||||||
|
this.packet = packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final Packet<?> getPacket() {
|
||||||
|
return this.packet;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package baritone.launch.mixins;
|
||||||
|
|
||||||
|
import baritone.bot.Baritone;
|
||||||
|
import baritone.bot.event.events.PacketEvent;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import io.netty.util.concurrent.Future;
|
||||||
|
import io.netty.util.concurrent.GenericFutureListener;
|
||||||
|
import net.minecraft.network.NetworkManager;
|
||||||
|
import net.minecraft.network.Packet;
|
||||||
|
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 8/6/2018 9:30 PM
|
||||||
|
*/
|
||||||
|
@Mixin(NetworkManager.class)
|
||||||
|
public class MixinNetworkManager {
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "dispatchPacket",
|
||||||
|
at = @At("HEAD")
|
||||||
|
)
|
||||||
|
private void dispatchPacket(Packet<?> inPacket, final GenericFutureListener<? extends Future<? super Void >>[] futureListeners, CallbackInfo ci) {
|
||||||
|
Baritone.INSTANCE.getGameEventHandler().onSendPacket(new PacketEvent(inPacket));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "channelRead0",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "net/minecraft/network/Packet.processPacket(Lnet/minecraft/network/INetHandler;)V"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private void preProcessPacket(ChannelHandlerContext context, Packet<?> packet, CallbackInfo ci) {
|
||||||
|
Baritone.INSTANCE.getGameEventHandler().onReceivePacket(new PacketEvent(packet));
|
||||||
|
}
|
||||||
|
}
|
@ -15,6 +15,7 @@
|
|||||||
"MixinMain",
|
"MixinMain",
|
||||||
"MixinMinecraft",
|
"MixinMinecraft",
|
||||||
"MixinNetHandlerPlayClient",
|
"MixinNetHandlerPlayClient",
|
||||||
|
"MixinNetworkManager",
|
||||||
"MixinWorldClient",
|
"MixinWorldClient",
|
||||||
|
|
||||||
"accessor.IAnvilChunkLoader",
|
"accessor.IAnvilChunkLoader",
|
||||||
|
Loading…
Reference in New Issue
Block a user