diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 4e622dc2..4b44d3e5 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -439,6 +439,11 @@ public final class Settings { */ public final Setting simplifyUnloadedYCoord = new Setting<>(true); + /** + * Whenever a block changes, repack the whole chunk that it's in + */ + public final Setting repackOnAnyBlockChange = new Setting<>(true); + /** * If a movement takes this many ticks more than its initial cost estimate, cancel it */ diff --git a/src/launch/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java b/src/launch/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java index 96e9cc29..f1c1f797 100644 --- a/src/launch/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java +++ b/src/launch/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java @@ -17,14 +17,19 @@ package baritone.launch.mixins; +import baritone.Baritone; import baritone.api.BaritoneAPI; import baritone.api.IBaritone; import baritone.api.event.events.ChunkEvent; import baritone.api.event.events.type.EventState; +import baritone.cache.CachedChunk; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.network.NetHandlerPlayClient; +import net.minecraft.network.play.server.SPacketBlockChange; import net.minecraft.network.play.server.SPacketChunkData; import net.minecraft.network.play.server.SPacketCombatEvent; +import net.minecraft.network.play.server.SPacketMultiBlockChange; +import net.minecraft.util.math.ChunkPos; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -80,6 +85,68 @@ public class MixinNetHandlerPlayClient { } } + @Inject( + method = "handleBlockChange", + at = @At("RETURN") + ) + private void postHandleBlockChange(SPacketBlockChange packetIn, CallbackInfo ci) { + if (!Baritone.settings().repackOnAnyBlockChange.value) { + return; + } + if (!CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(packetIn.getBlockState().getBlock())) { + return; + } + for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { + EntityPlayerSP player = ibaritone.getPlayerContext().player(); + if (player != null && player.connection == (NetHandlerPlayClient) (Object) this) { + ibaritone.getGameEventHandler().onChunkEvent( + new ChunkEvent( + EventState.POST, + ChunkEvent.Type.POPULATE_FULL, + packetIn.getBlockPosition().getX() >> 4, + packetIn.getBlockPosition().getZ() >> 4 + ) + ); + } + } + } + + @Inject( + method = "handleMultiBlockChange", + at = @At("RETURN") + ) + private void postHandleMultiBlockChange(SPacketMultiBlockChange packetIn, CallbackInfo ci) { + if (!Baritone.settings().repackOnAnyBlockChange.value) { + return; + } + if (packetIn.getChangedBlocks().length == 0) { + return; + } + https://docs.oracle.com/javase/specs/jls/se7/html/jls-14.html#jls-14.15 + { + for (SPacketMultiBlockChange.BlockUpdateData update : packetIn.getChangedBlocks()) { + if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(update.getBlockState().getBlock())) { + break https; + } + } + return; + } + ChunkPos pos = new ChunkPos(packetIn.getChangedBlocks()[0].getPos()); + for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { + EntityPlayerSP player = ibaritone.getPlayerContext().player(); + if (player != null && player.connection == (NetHandlerPlayClient) (Object) this) { + ibaritone.getGameEventHandler().onChunkEvent( + new ChunkEvent( + EventState.POST, + ChunkEvent.Type.POPULATE_FULL, + pos.x, + pos.z + ) + ); + } + } + } + @Inject( method = "handleCombatEvent", at = @At(