Fix ChunkEvent Y->Z and add POPULATE Type

This commit is contained in:
Brady 2018-08-03 01:03:36 -07:00
parent 35a60d5ed7
commit b8817f2929
No known key found for this signature in database
GPG Key ID: 73A788379A197567
4 changed files with 78 additions and 13 deletions

View File

@ -35,7 +35,7 @@ public interface IGameEventListener {
/**
* Runs before and after whenever a chunk is either loaded or unloaded.
* Runs before and after whenever a chunk is either loaded, unloaded, or populated.
*
* @see WorldClient#doPreChunk(int, int, boolean)
*/

View File

@ -24,15 +24,15 @@ public final class ChunkEvent {
private final int x;
/**
* The Chunk Y position.
* The Chunk Z position.
*/
private final int y;
private final int z;
public ChunkEvent(EventState state, Type type, int x, int y) {
public ChunkEvent(EventState state, Type type, int x, int z) {
this.state = state;
this.type = type;
this.x = x;
this.y = y;
this.z = z;
}
/**
@ -57,14 +57,27 @@ public final class ChunkEvent {
}
/**
* @return The Chunk Y position.
* @return The Chunk Z position.
*/
public final int getY() {
return this.y;
public final int getZ() {
return this.z;
}
public enum Type {
/**
* When the chunk is constructed.
*/
LOAD,
UNLOAD
/**
* When the chunk is deconstructed.
*/
UNLOAD,
/**
* When the chunk is being populated with blocks, tile entities, etc.
*/
POPULATE
}
}

View File

@ -0,0 +1,52 @@
package baritone.launch.mixins;
import baritone.bot.Baritone;
import baritone.bot.event.events.ChunkEvent;
import baritone.bot.event.events.type.EventState;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.network.play.server.SPacketChunkData;
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/3/2018 12:54 AM
*/
@Mixin(NetHandlerPlayClient.class)
public class MixinNetHandlerPlayClient {
@Inject(
method = "handleChunkData",
at = @At(
value = "INVOKE",
target = "net/minecraft/world/chunk/Chunk.read(Lnet/minecraft/network/PacketBuffer;IZ)V"
)
)
private void preRead(SPacketChunkData packetIn, CallbackInfo ci) {
Baritone.INSTANCE.getGameEventHandler().onChunkEvent(
new ChunkEvent(
EventState.PRE,
ChunkEvent.Type.POPULATE,
packetIn.getChunkX(),
packetIn.getChunkZ()
)
);
}
@Inject(
method = "handleChunkData",
at = @At("RETURN")
)
private void postHandleChunkData(SPacketChunkData packetIn, CallbackInfo ci) {
Baritone.INSTANCE.getGameEventHandler().onChunkEvent(
new ChunkEvent(
EventState.POST,
ChunkEvent.Type.POPULATE,
packetIn.getChunkX(),
packetIn.getChunkZ()
)
);
}
}

View File

@ -20,13 +20,13 @@ public class MixinWorldClient {
method = "doPreChunk",
at = @At("HEAD")
)
private void preDoPreChunk(int chunkX, int chunkY, boolean loadChunk, CallbackInfo ci) {
private void preDoPreChunk(int chunkX, int chunkZ, boolean loadChunk, CallbackInfo ci) {
Baritone.INSTANCE.getGameEventHandler().onChunkEvent(
new ChunkEvent(
EventState.PRE,
loadChunk ? ChunkEvent.Type.LOAD : ChunkEvent.Type.UNLOAD,
chunkX,
chunkY
chunkZ
)
);
}
@ -35,13 +35,13 @@ public class MixinWorldClient {
method = "doPreChunk",
at = @At("RETURN")
)
private void postDoPreChunk(int chunkX, int chunkY, boolean loadChunk, CallbackInfo ci) {
private void postDoPreChunk(int chunkX, int chunkZ, boolean loadChunk, CallbackInfo ci) {
Baritone.INSTANCE.getGameEventHandler().onChunkEvent(
new ChunkEvent(
EventState.POST,
loadChunk ? ChunkEvent.Type.LOAD : ChunkEvent.Type.UNLOAD,
chunkX,
chunkY
chunkZ
)
);
}