From b471d7419efaa24053c9128b2efcbf9b68cda864 Mon Sep 17 00:00:00 2001 From: Brady Date: Tue, 29 Jan 2019 12:41:14 -0600 Subject: [PATCH] Replace most of the @Inject usages for cancer render with @Redirect --- .../launch/mixins/MixinChunkCache.java | 58 -------------- .../mixins/MixinChunkRenderContainer.java | 1 + .../launch/mixins/MixinChunkRenderWorker.java | 33 +++++--- .../launch/mixins/MixinRenderChunk.java | 75 +++++++++++++++++++ src/launch/resources/mixins.baritone.json | 2 +- 5 files changed, 98 insertions(+), 71 deletions(-) delete mode 100644 src/launch/java/baritone/launch/mixins/MixinChunkCache.java create mode 100644 src/launch/java/baritone/launch/mixins/MixinRenderChunk.java diff --git a/src/launch/java/baritone/launch/mixins/MixinChunkCache.java b/src/launch/java/baritone/launch/mixins/MixinChunkCache.java deleted file mode 100644 index f8d0a0bfb..000000000 --- a/src/launch/java/baritone/launch/mixins/MixinChunkCache.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 . - */ - -package baritone.launch.mixins; - -import baritone.Baritone; -import baritone.api.BaritoneAPI; -import baritone.api.utils.IPlayerContext; -import net.minecraft.block.state.IBlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.ChunkCache; -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.CallbackInfoReturnable; - -@Mixin(ChunkCache.class) -public class MixinChunkCache { - @Inject( - method = "getBlockState", - at = @At("HEAD"), - cancellable = true - ) - private void getBlockState(BlockPos pos, CallbackInfoReturnable ci) { - Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone(); - IPlayerContext ctx = baritone.getPlayerContext(); - if (ctx.player() != null && ctx.world() != null && baritone.bsi != null && Baritone.settings().renderCachedChunks.get()) { - ci.setReturnValue(baritone.bsi.get0(pos)); - } - } - - @Inject( - method = "isEmpty", - at = @At("HEAD"), - cancellable = true - ) - private void isEmpty(CallbackInfoReturnable ci) { - Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone(); - IPlayerContext ctx = baritone.getPlayerContext(); - if (ctx.player() != null && ctx.world() != null && baritone.bsi != null && Baritone.settings().renderCachedChunks.get()) { - ci.setReturnValue(false); - } - } -} diff --git a/src/launch/java/baritone/launch/mixins/MixinChunkRenderContainer.java b/src/launch/java/baritone/launch/mixins/MixinChunkRenderContainer.java index 1894caaa6..19cbfc14a 100644 --- a/src/launch/java/baritone/launch/mixins/MixinChunkRenderContainer.java +++ b/src/launch/java/baritone/launch/mixins/MixinChunkRenderContainer.java @@ -31,6 +31,7 @@ import static org.lwjgl.opengl.GL11.*; @Mixin(ChunkRenderContainer.class) public class MixinChunkRenderContainer { + @Inject( method = "preRenderChunk", at = @At("HEAD") diff --git a/src/launch/java/baritone/launch/mixins/MixinChunkRenderWorker.java b/src/launch/java/baritone/launch/mixins/MixinChunkRenderWorker.java index 493d48693..3621b6648 100644 --- a/src/launch/java/baritone/launch/mixins/MixinChunkRenderWorker.java +++ b/src/launch/java/baritone/launch/mixins/MixinChunkRenderWorker.java @@ -24,23 +24,32 @@ import net.minecraft.client.renderer.chunk.ChunkRenderWorker; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(ChunkRenderWorker.class) -public class MixinChunkRenderWorker { - @Inject( - method = "isChunkExisting", - at = @At("HEAD"), - cancellable = true +public abstract class MixinChunkRenderWorker { + + @Shadow protected abstract boolean isChunkExisting(BlockPos pos, World worldIn); + + @Redirect( + method = "processTask", + at = @At( + value = "INVOKE", + target = "net/minecraft/client/renderer/chunk/ChunkRenderWorker.isChunkExisting(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/World;)Z" + ) ) - private void isChunkExisting(BlockPos pos, World world, CallbackInfoReturnable ci) { - Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone(); - IPlayerContext ctx = baritone.getPlayerContext(); - if (ctx.player() != null && ctx.world() != null && baritone.bsi != null && Baritone.settings().renderCachedChunks.get()) { - ci.setReturnValue(baritone.bsi.isLoaded(pos.getX(), pos.getZ())); + private boolean isChunkExisting(ChunkRenderWorker worker, BlockPos pos, World world) { + if (Baritone.settings().renderCachedChunks.get()) { + Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone(); + IPlayerContext ctx = baritone.getPlayerContext(); + if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) { + return baritone.bsi.isLoaded(pos.getX(), pos.getZ()); + } } + + return this.isChunkExisting(pos, world); } } diff --git a/src/launch/java/baritone/launch/mixins/MixinRenderChunk.java b/src/launch/java/baritone/launch/mixins/MixinRenderChunk.java new file mode 100644 index 000000000..47402c6b0 --- /dev/null +++ b/src/launch/java/baritone/launch/mixins/MixinRenderChunk.java @@ -0,0 +1,75 @@ +/* + * 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 . + */ + +package baritone.launch.mixins; + +import baritone.Baritone; +import baritone.api.BaritoneAPI; +import baritone.api.utils.IPlayerContext; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.chunk.RenderChunk; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.ChunkCache; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +/** + * @author Brady + * @since 1/29/2019 + */ +@Mixin(RenderChunk.class) +public class MixinRenderChunk { + + @Redirect( + method = "rebuildChunk", + at = @At( + value = "INVOKE", + target = "net/minecraft/world/ChunkCache.isEmpty()Z" + ) + ) + private boolean isEmpty(ChunkCache chunkCache) { + if (Baritone.settings().renderCachedChunks.get()) { + Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone(); + IPlayerContext ctx = baritone.getPlayerContext(); + if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) { + return false; + } + } + + return chunkCache.isEmpty(); + } + + @Redirect( + method = "rebuildChunk", + at = @At( + value = "INVOKE", + target = "net/minecraft/world/ChunkCache.getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState;" + ) + ) + private IBlockState getBlockState(ChunkCache chunkCache, BlockPos pos) { + if (Baritone.settings().renderCachedChunks.get()) { + Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone(); + IPlayerContext ctx = baritone.getPlayerContext(); + if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) { + return baritone.bsi.get0(pos); + } + } + + return chunkCache.getBlockState(pos); + } +} diff --git a/src/launch/resources/mixins.baritone.json b/src/launch/resources/mixins.baritone.json index 10e3510d6..aa9a724ff 100644 --- a/src/launch/resources/mixins.baritone.json +++ b/src/launch/resources/mixins.baritone.json @@ -10,7 +10,6 @@ "client": [ "MixinAnvilChunkLoader", "MixinBlockPos", - "MixinChunkCache", "MixinChunkProviderClient", "MixinChunkProviderServer", "MixinChunkRenderContainer", @@ -23,6 +22,7 @@ "MixinMinecraft", "MixinNetHandlerPlayClient", "MixinNetworkManager", + "MixinRenderChunk", "MixinWorldClient" ] } \ No newline at end of file