Merge branch 'master' of github.com:cabaletta/baritone

This commit is contained in:
Leijurv 2018-08-06 19:52:41 -07:00
commit 9e8154dd5e
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
6 changed files with 94 additions and 4 deletions

View File

@ -102,6 +102,16 @@ public final class GameEventHandler implements IGameEventListener {
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) {
Baritone.INSTANCE.getBehaviors().stream().filter(Behavior::isEnabled).forEach(dispatchFunction);
}

View File

@ -7,9 +7,6 @@ import baritone.bot.event.events.*;
* overridden with empty bodies, allowing inheritors of this class to choose
* 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
*
* @author Brady
@ -37,4 +34,10 @@ public interface AbstractGameEventListener extends IGameEventListener {
@Override
default void onWorldEvent(WorldEvent event) {}
@Override
default void onSendPacket(PacketEvent event) {}
@Override
default void onReceivePacket(PacketEvent event) {}
}

View File

@ -1,11 +1,14 @@
package baritone.bot.event;
import baritone.bot.event.events.*;
import io.netty.util.concurrent.GenericFutureListener;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
/**
* @author Brady
@ -40,7 +43,6 @@ public interface IGameEventListener {
*/
void onSendChatMessage(ChatEvent event);
/**
* 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)
*/
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);
}

View 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;
}
}

View File

@ -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));
}
}

View File

@ -15,6 +15,7 @@
"MixinMain",
"MixinMinecraft",
"MixinNetHandlerPlayClient",
"MixinNetworkManager",
"MixinWorldClient",
"accessor.IAnvilChunkLoader",