From f2b747cc4513726d4c4b4850546f5aec07c44a11 Mon Sep 17 00:00:00 2001 From: Cadiboo <37298044+Cadiboo@users.noreply.github.com> Date: Wed, 10 Apr 2019 20:31:52 +1000 Subject: [PATCH] :D --- ...ebuildChunkCanBlockRenderInLayerEvent.java | 3 + ...hunkCanBlockRenderTypeBeRenderedEvent.java | 3 + ...ebuildChunkCanFluidRenderInLayerEvent.java | 3 + .../event/RebuildChunkCheckWorldEvent.java | 3 + .../event/RebuildChunkEvent.java | 2 + .../event/RebuildChunkIsFluidEmptyEvent.java | 2 + .../event/RebuildChunkPostIterationEvent.java | 2 + .../event/RebuildChunkPreEvent.java | 3 + .../event/RebuildChunkPreIterationEvent.java | 3 + .../event/RebuildChunkPreRenderEvent.java | 3 + .../event/RebuildChunkRenderBlockEvent.java | 3 + .../event/RebuildChunkRenderFluidEvent.java | 3 + .../hooks/Hooks.java | 25 +-- .../CorrectBlockRenderLayerTester.java | 41 +++++ .../EventCancellingTester.java | 154 +++++++++++++++++ .../EventDenyingTester.java | 161 ++++++++++++++++++ ...entTester.java => EventNonNullTester.java} | 16 +- 17 files changed, 414 insertions(+), 16 deletions(-) create mode 100644 src/test/java/io/github/cadiboo/renderchunkrebuildchunkhooks/CorrectBlockRenderLayerTester.java create mode 100644 src/test/java/io/github/cadiboo/renderchunkrebuildchunkhooks/EventCancellingTester.java create mode 100644 src/test/java/io/github/cadiboo/renderchunkrebuildchunkhooks/EventDenyingTester.java rename src/test/java/io/github/cadiboo/renderchunkrebuildchunkhooks/{EventTester.java => EventNonNullTester.java} (95%) diff --git a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkCanBlockRenderInLayerEvent.java b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkCanBlockRenderInLayerEvent.java index 9865fe4..aa2ecec 100644 --- a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkCanBlockRenderInLayerEvent.java +++ b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkCanBlockRenderInLayerEvent.java @@ -14,6 +14,8 @@ import net.minecraft.world.IWorldReader; import net.minecraft.world.World; import net.minecraftforge.eventbus.api.Cancelable; +import net.minecraftforge.eventbus.api.Event; +import net.minecraftforge.eventbus.api.Event.HasResult; import javax.annotation.Nonnull; import java.util.HashSet; @@ -23,6 +25,7 @@ * @author Cadiboo */ @Cancelable +@HasResult public class RebuildChunkCanBlockRenderInLayerEvent extends RebuildChunkEvent { @Nonnull diff --git a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkCanBlockRenderTypeBeRenderedEvent.java b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkCanBlockRenderTypeBeRenderedEvent.java index 1d38a4e..46f8f47 100644 --- a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkCanBlockRenderTypeBeRenderedEvent.java +++ b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkCanBlockRenderTypeBeRenderedEvent.java @@ -13,6 +13,8 @@ import net.minecraft.world.IWorldReader; import net.minecraft.world.World; import net.minecraftforge.eventbus.api.Cancelable; +import net.minecraftforge.eventbus.api.Event; +import net.minecraftforge.eventbus.api.Event.HasResult; import javax.annotation.Nonnull; import java.util.HashSet; @@ -22,6 +24,7 @@ * @author Cadiboo */ @Cancelable +@HasResult public class RebuildChunkCanBlockRenderTypeBeRenderedEvent extends RebuildChunkEvent { @Nonnull diff --git a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkCanFluidRenderInLayerEvent.java b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkCanFluidRenderInLayerEvent.java index 70567d3..70f1914 100644 --- a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkCanFluidRenderInLayerEvent.java +++ b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkCanFluidRenderInLayerEvent.java @@ -14,6 +14,8 @@ import net.minecraft.world.IWorldReader; import net.minecraft.world.World; import net.minecraftforge.eventbus.api.Cancelable; +import net.minecraftforge.eventbus.api.Event; +import net.minecraftforge.eventbus.api.Event.HasResult; import javax.annotation.Nonnull; import java.util.HashSet; @@ -23,6 +25,7 @@ * @author Cadiboo */ @Cancelable +@HasResult public class RebuildChunkCanFluidRenderInLayerEvent extends RebuildChunkEvent { @Nonnull diff --git a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkCheckWorldEvent.java b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkCheckWorldEvent.java index 4e63929..31749df 100644 --- a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkCheckWorldEvent.java +++ b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkCheckWorldEvent.java @@ -7,6 +7,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.eventbus.api.Cancelable; +import net.minecraftforge.eventbus.api.Event; +import net.minecraftforge.eventbus.api.Event.HasResult; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -15,6 +17,7 @@ * @author Cadiboo */ @Cancelable +@HasResult public class RebuildChunkCheckWorldEvent extends RebuildChunkEvent { @Nonnull diff --git a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkEvent.java b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkEvent.java index 3ae9032..c75dc45 100644 --- a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkEvent.java +++ b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkEvent.java @@ -5,6 +5,7 @@ import net.minecraft.client.renderer.chunk.RenderChunk; import net.minecraft.util.BlockRenderLayer; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.eventbus.api.Cancelable; import net.minecraftforge.eventbus.api.Event; import javax.annotation.Nonnull; @@ -14,6 +15,7 @@ * Called when a {@link RenderChunk#rebuildChunk} is called. * This event is fired on the {@link MinecraftForge#EVENT_BUS} */ +@Cancelable public class RebuildChunkEvent extends Event { @Nonnull diff --git a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkIsFluidEmptyEvent.java b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkIsFluidEmptyEvent.java index bef9d91..9156b40 100644 --- a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkIsFluidEmptyEvent.java +++ b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkIsFluidEmptyEvent.java @@ -13,6 +13,7 @@ import net.minecraft.world.IWorldReader; import net.minecraft.world.World; import net.minecraftforge.eventbus.api.Cancelable; +import net.minecraftforge.eventbus.api.Event.HasResult; import javax.annotation.Nonnull; import java.util.HashSet; @@ -22,6 +23,7 @@ * @author Cadiboo */ @Cancelable +@HasResult public class RebuildChunkIsFluidEmptyEvent extends RebuildChunkEvent { @Nonnull diff --git a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkPostIterationEvent.java b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkPostIterationEvent.java index 6d46c51..ee6d97c 100644 --- a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkPostIterationEvent.java +++ b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkPostIterationEvent.java @@ -10,6 +10,8 @@ import net.minecraft.world.IWorldReader; import net.minecraft.world.World; import net.minecraftforge.eventbus.api.Cancelable; +import net.minecraftforge.eventbus.api.Event; +import net.minecraftforge.eventbus.api.Event.HasResult; import javax.annotation.Nonnull; import java.util.HashSet; diff --git a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkPreEvent.java b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkPreEvent.java index 1470447..c3f33e3 100644 --- a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkPreEvent.java +++ b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkPreEvent.java @@ -3,6 +3,8 @@ import net.minecraft.client.renderer.chunk.ChunkRenderTask; import net.minecraft.client.renderer.chunk.RenderChunk; import net.minecraftforge.eventbus.api.Cancelable; +import net.minecraftforge.eventbus.api.Event; +import net.minecraftforge.eventbus.api.Event.HasResult; import javax.annotation.Nonnull; @@ -10,6 +12,7 @@ * @author Cadiboo */ @Cancelable +@HasResult public class RebuildChunkPreEvent extends RebuildChunkEvent { public RebuildChunkPreEvent( diff --git a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkPreIterationEvent.java b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkPreIterationEvent.java index 07ff1a1..874f0ea 100644 --- a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkPreIterationEvent.java +++ b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkPreIterationEvent.java @@ -10,6 +10,8 @@ import net.minecraft.world.IWorldReader; import net.minecraft.world.World; import net.minecraftforge.eventbus.api.Cancelable; +import net.minecraftforge.eventbus.api.Event; +import net.minecraftforge.eventbus.api.Event.HasResult; import javax.annotation.Nonnull; import java.util.HashSet; @@ -19,6 +21,7 @@ * @author Cadiboo */ @Cancelable +@HasResult public class RebuildChunkPreIterationEvent extends RebuildChunkEvent { @Nonnull diff --git a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkPreRenderEvent.java b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkPreRenderEvent.java index 136be80..759e7c3 100644 --- a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkPreRenderEvent.java +++ b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkPreRenderEvent.java @@ -9,6 +9,8 @@ import net.minecraft.world.IWorldReader; import net.minecraft.world.World; import net.minecraftforge.eventbus.api.Cancelable; +import net.minecraftforge.eventbus.api.Event; +import net.minecraftforge.eventbus.api.Event.HasResult; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -18,6 +20,7 @@ * @author Cadiboo */ @Cancelable +@HasResult public class RebuildChunkPreRenderEvent extends RebuildChunkEvent { @Nonnull diff --git a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkRenderBlockEvent.java b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkRenderBlockEvent.java index 8705a87..c91bb3b 100644 --- a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkRenderBlockEvent.java +++ b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkRenderBlockEvent.java @@ -15,6 +15,8 @@ import net.minecraft.world.IWorldReader; import net.minecraft.world.World; import net.minecraftforge.eventbus.api.Cancelable; +import net.minecraftforge.eventbus.api.Event; +import net.minecraftforge.eventbus.api.Event.HasResult; import javax.annotation.Nonnull; import java.util.HashSet; @@ -24,6 +26,7 @@ * @author Cadiboo */ @Cancelable +@HasResult public class RebuildChunkRenderBlockEvent extends RebuildChunkEvent { @Nonnull diff --git a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkRenderFluidEvent.java b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkRenderFluidEvent.java index 69102d3..1e9baa2 100644 --- a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkRenderFluidEvent.java +++ b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/event/RebuildChunkRenderFluidEvent.java @@ -15,6 +15,8 @@ import net.minecraft.world.IWorldReader; import net.minecraft.world.World; import net.minecraftforge.eventbus.api.Cancelable; +import net.minecraftforge.eventbus.api.Event; +import net.minecraftforge.eventbus.api.Event.HasResult; import javax.annotation.Nonnull; import java.util.HashSet; @@ -24,6 +26,7 @@ * @author Cadiboo */ @Cancelable +@HasResult public class RebuildChunkRenderFluidEvent extends RebuildChunkEvent { @Nonnull diff --git a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/hooks/Hooks.java b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/hooks/Hooks.java index 500172e..dfc043b 100644 --- a/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/hooks/Hooks.java +++ b/src/main/java/io/github/cadiboo/renderchunkrebuildchunkhooks/hooks/Hooks.java @@ -48,6 +48,7 @@ import static io.github.cadiboo.renderchunkrebuildchunkhooks.hooks.HookConfig.postRebuildChunkPreRenderEvent; import static io.github.cadiboo.renderchunkrebuildchunkhooks.hooks.HookConfig.postRebuildChunkRenderBlockEvent; import static io.github.cadiboo.renderchunkrebuildchunkhooks.hooks.HookConfig.postRebuildChunkRenderFluidEvent; +import static net.minecraftforge.eventbus.api.Event.Result.DENY; /** * @author Cadiboo @@ -64,7 +65,7 @@ public static boolean pre(final RenderChunk renderChunk, final float x, final fl if (postRebuildChunkPreEvent) { final RebuildChunkPreEvent event = new RebuildChunkPreEvent(renderChunk, x, y, z, generator); MinecraftForge.EVENT_BUS.post(event); - return event.isCanceled(); + return event.getResult() != DENY; } else { return false; } @@ -75,7 +76,7 @@ public static boolean checkWorld(final RenderChunk renderChunk, final float x, f if (postRebuildChunkCheckWorldEvent) { final RebuildChunkCheckWorldEvent event = new RebuildChunkCheckWorldEvent(renderChunk, x, y, z, generator, compiledchunk, blockpos, blockpos1, world, worldRef); MinecraftForge.EVENT_BUS.post(event); - return event.isCanceled(); + return event.getResult() != DENY; } else { return false; } @@ -86,7 +87,7 @@ public static boolean preRender(final RenderChunk renderChunk, final float x, fi if (postRebuildChunkPreRenderEvent) { final RebuildChunkPreRenderEvent event = new RebuildChunkPreRenderEvent(renderChunk, x, y, z, generator, compiledchunk, blockpos, blockpos1, world, lvt_10_1_, lvt_11_1_, lvt_12_1_); MinecraftForge.EVENT_BUS.post(event); - return event.isCanceled(); + return event.getResult() != DENY; } else { return false; } @@ -97,7 +98,7 @@ public static boolean preIteration(final RenderChunk renderChunk, final float x, if (postRebuildChunkPreIterationEvent) { final RebuildChunkPreIterationEvent event = new RebuildChunkPreIterationEvent(renderChunk, x, y, z, generator, compiledchunk, blockpos, blockpos1, world, lvt_10_1_, lvt_11_1_, lvt_12_1_, aboolean, random, blockrendererdispatcher); MinecraftForge.EVENT_BUS.post(event); - return event.isCanceled(); + return event.getResult() != DENY; } else { return false; } @@ -113,19 +114,19 @@ public static boolean canFluidRender(final RenderChunk renderChunk, final float final RebuildChunkCanFluidRenderInLayerEvent canFluidRenderInLayerEvent = PooledHandler.setupRebuildChunkCanFluidRenderInLayerEvent(renderChunk, x, y, z, generator, compiledchunk, blockpos, blockpos1, world, lvt_10_1_, lvt_11_1_, lvt_12_1_, aboolean, random, blockrendererdispatcher, iblockstate, block, ifluidstate, blockrenderlayer1); MinecraftForge.EVENT_BUS.post(canFluidRenderInLayerEvent); PooledHandler.tearDown(canFluidRenderInLayerEvent); - return !isFluidEmptyEvent.isCanceled() && !canFluidRenderInLayerEvent.isCanceled(); + return isFluidEmptyEvent.getResult() != DENY && canFluidRenderInLayerEvent.getResult() != DENY; } else { final RebuildChunkIsFluidEmptyEvent isFluidEmptyEvent = PooledHandler.setupRebuildChunkIsFluidEmptyEvent(renderChunk, x, y, z, generator, compiledchunk, blockpos, blockpos1, world, lvt_10_1_, lvt_11_1_, lvt_12_1_, aboolean, random, blockrendererdispatcher, iblockstate, block, ifluidstate); MinecraftForge.EVENT_BUS.post(isFluidEmptyEvent); PooledHandler.tearDown(isFluidEmptyEvent); - return !isFluidEmptyEvent.isCanceled() && ifluidstate.canRenderInLayer(blockrenderlayer1); + return isFluidEmptyEvent.getResult() != DENY && ifluidstate.canRenderInLayer(blockrenderlayer1); } } else { if (postRebuildChunkCanFluidRenderInLayerEvent) { final RebuildChunkCanFluidRenderInLayerEvent canFluidRenderInLayerEvent = PooledHandler.setupRebuildChunkCanFluidRenderInLayerEvent(renderChunk, x, y, z, generator, compiledchunk, blockpos, blockpos1, world, lvt_10_1_, lvt_11_1_, lvt_12_1_, aboolean, random, blockrendererdispatcher, iblockstate, block, ifluidstate, blockrenderlayer1); MinecraftForge.EVENT_BUS.post(canFluidRenderInLayerEvent); PooledHandler.tearDown(canFluidRenderInLayerEvent); - return !ifluidstate.isEmpty() && !canFluidRenderInLayerEvent.isCanceled(); + return !ifluidstate.isEmpty() && canFluidRenderInLayerEvent.getResult() != DENY; } else { return !ifluidstate.isEmpty() && ifluidstate.canRenderInLayer(blockrenderlayer1); } @@ -138,7 +139,7 @@ public static boolean preRenderFluid(final RenderChunk renderChunk, final float final RebuildChunkRenderFluidEvent event = PooledHandler.setupRebuildChunkRenderFluidEvent(renderChunk, x, y, z, generator, compiledchunk, blockpos, blockpos1, world, lvt_10_1_, lvt_11_1_, lvt_12_1_, aboolean, random, blockrendererdispatcher, iblockstate, block, ifluidstate, blockrenderlayer1, j, bufferbuilder); MinecraftForge.EVENT_BUS.post(event); PooledHandler.tearDown(event); - return event.isCanceled(); + return event.getResult() != DENY; } else { return false; } @@ -154,19 +155,19 @@ public static boolean canBlockRender(final RenderChunk renderChunk, final float final RebuildChunkCanBlockRenderInLayerEvent canBlockRenderInLayerEvent = PooledHandler.setupRebuildChunkCanBlockRenderInLayerEvent(renderChunk, x, y, z, generator, compiledchunk, blockpos, blockpos1, world, lvt_10_1_, lvt_11_1_, lvt_12_1_, aboolean, random, blockrendererdispatcher, iblockstate, block, ifluidstate, blockrenderlayer1); MinecraftForge.EVENT_BUS.post(canBlockRenderInLayerEvent); PooledHandler.tearDown(canBlockRenderInLayerEvent); - return !canBlockRenderTypeBeRenderedEvent.isCanceled() && !canBlockRenderInLayerEvent.isCanceled(); + return canBlockRenderTypeBeRenderedEvent.getResult() != DENY && canBlockRenderInLayerEvent.getResult() != DENY; } else { final RebuildChunkCanBlockRenderTypeBeRenderedEvent canBlockRenderTypeBeRenderedEvent = PooledHandler.setupRebuildChunkCanBlockRenderTypeBeRenderedEvent(renderChunk, x, y, z, generator, compiledchunk, blockpos, blockpos1, world, lvt_10_1_, lvt_11_1_, lvt_12_1_, aboolean, random, blockrendererdispatcher, iblockstate, block, ifluidstate); MinecraftForge.EVENT_BUS.post(canBlockRenderTypeBeRenderedEvent); PooledHandler.tearDown(canBlockRenderTypeBeRenderedEvent); - return !canBlockRenderTypeBeRenderedEvent.isCanceled() && iblockstate.canRenderInLayer(blockrenderlayer1); + return canBlockRenderTypeBeRenderedEvent.getResult() != DENY && iblockstate.canRenderInLayer(blockrenderlayer1); } } else { if (postRebuildChunkCanBlockRenderInLayerEvent) { final RebuildChunkCanBlockRenderInLayerEvent canBlockRenderInLayerEvent = PooledHandler.setupRebuildChunkCanBlockRenderInLayerEvent(renderChunk, x, y, z, generator, compiledchunk, blockpos, blockpos1, world, lvt_10_1_, lvt_11_1_, lvt_12_1_, aboolean, random, blockrendererdispatcher, iblockstate, block, ifluidstate, blockrenderlayer1); MinecraftForge.EVENT_BUS.post(canBlockRenderInLayerEvent); PooledHandler.tearDown(canBlockRenderInLayerEvent); - return iblockstate.getRenderType() != EnumBlockRenderType.INVISIBLE && !canBlockRenderInLayerEvent.isCanceled(); + return iblockstate.getRenderType() != EnumBlockRenderType.INVISIBLE && canBlockRenderInLayerEvent.getResult() != DENY; } else { return iblockstate.getRenderType() != EnumBlockRenderType.INVISIBLE && iblockstate.canRenderInLayer(blockrenderlayer1); } @@ -179,7 +180,7 @@ public static boolean preRenderBlock(final RenderChunk renderChunk, final float final RebuildChunkRenderBlockEvent event = PooledHandler.setupRebuildChunkRenderBlockEvent(renderChunk, x, y, z, generator, compiledchunk, blockpos, blockpos1, world, lvt_10_1_, lvt_11_1_, lvt_12_1_, aboolean, random, blockrendererdispatcher, iblockstate, block, ifluidstate, blockrenderlayer1, k, bufferbuilder1); MinecraftForge.EVENT_BUS.post(event); PooledHandler.tearDown(event); - return event.isCanceled(); + return event.getResult() != DENY; } else { return false; } diff --git a/src/test/java/io/github/cadiboo/renderchunkrebuildchunkhooks/CorrectBlockRenderLayerTester.java b/src/test/java/io/github/cadiboo/renderchunkrebuildchunkhooks/CorrectBlockRenderLayerTester.java new file mode 100644 index 0000000..a4fb6fe --- /dev/null +++ b/src/test/java/io/github/cadiboo/renderchunkrebuildchunkhooks/CorrectBlockRenderLayerTester.java @@ -0,0 +1,41 @@ +package io.github.cadiboo.renderchunkrebuildchunkhooks; + +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkCanBlockRenderInLayerEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.hooks.HookConfig; +import net.minecraft.client.Minecraft; +import net.minecraft.util.BlockRenderLayer; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; + +import static io.github.cadiboo.renderchunkrebuildchunkhooks.util.Refs.MOD_ID; +import static net.minecraft.util.BlockRenderLayer.CUTOUT; +import static net.minecraft.util.BlockRenderLayer.CUTOUT_MIPPED; +import static net.minecraftforge.eventbus.api.Event.Result.ALLOW; + +@EventBusSubscriber(modid = MOD_ID, value = Dist.CLIENT) +public final class CorrectBlockRenderLayerTester { + + private static boolean enabled = true; + static { + if (enabled) { + HookConfig.enableRebuildChunkCanBlockRenderInLayerEvent(); + } + } + + @SubscribeEvent + public static void onRebuildChunkCanBlockRenderInLayerEvent(final RebuildChunkCanBlockRenderInLayerEvent event) { + if (!enabled) { + return; + } + + if (event.getBlockRenderLayer() == getTargetLayer()) { + event.setResult(ALLOW); + } + } + + private static BlockRenderLayer getTargetLayer() { + return Minecraft.getInstance().gameSettings.mipmapLevels > 0 ? CUTOUT : CUTOUT_MIPPED; + } + +} diff --git a/src/test/java/io/github/cadiboo/renderchunkrebuildchunkhooks/EventCancellingTester.java b/src/test/java/io/github/cadiboo/renderchunkrebuildchunkhooks/EventCancellingTester.java new file mode 100644 index 0000000..02309e6 --- /dev/null +++ b/src/test/java/io/github/cadiboo/renderchunkrebuildchunkhooks/EventCancellingTester.java @@ -0,0 +1,154 @@ +package io.github.cadiboo.renderchunkrebuildchunkhooks; + +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkCanBlockRenderInLayerEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkCanBlockRenderTypeBeRenderedEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkCanFluidRenderInLayerEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkCheckWorldEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkIsFluidEmptyEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkPostEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkPostIterationEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkPostRenderEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkPreEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkPreIterationEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkPreRenderEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkRenderBlockEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkRenderFluidEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.hooks.HookConfig; +import net.minecraft.client.renderer.chunk.ChunkRenderTask; +import net.minecraft.client.renderer.chunk.CompiledChunk; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; + +import java.util.concurrent.locks.ReentrantLock; + +import static io.github.cadiboo.renderchunkrebuildchunkhooks.util.Refs.MOD_ID; + +@EventBusSubscriber(modid = MOD_ID, value = Dist.CLIENT) +public final class EventCancellingTester { + + private static boolean enabled = true; + static { + if (enabled) { + HookConfig.enableAll(); + } + } + + @SubscribeEvent + public static void onRebuildChunkPreEvent(final RebuildChunkPreEvent event) { + if (!enabled) { + return; + } + + event.setCanceled(true); + } + + @SubscribeEvent + public static void onRebuildChunkCheckWorldEvent(final RebuildChunkCheckWorldEvent event) { + if (!enabled) { + return; + } + + event.setCanceled(true); + } + + @SubscribeEvent + public static void onRebuildChunkPreRenderEvent(final RebuildChunkPreRenderEvent event) { + if (!enabled) { + return; + } + + event.setCanceled(true); + } + + @SubscribeEvent + public static void onRebuildChunkPreIterationEvent(final RebuildChunkPreIterationEvent event) { + if (!enabled) { + return; + } + + event.setCanceled(true); + } + + @SubscribeEvent + public static void onRebuildChunkIsFluidEmptyEvent(final RebuildChunkIsFluidEmptyEvent event) { + if (!enabled) { + return; + } + + event.setCanceled(true); + } + + @SubscribeEvent + public static void onRebuildChunkCanFluidRenderInLayerEvent(final RebuildChunkCanFluidRenderInLayerEvent event) { + if (!enabled) { + return; + } + + event.setCanceled(true); + } + + @SubscribeEvent + public static void onRebuildChunkRenderFluidEvent(final RebuildChunkRenderFluidEvent event) { + if (!enabled) { + return; + } + + event.setCanceled(true); + } + + @SubscribeEvent + public static void onRebuildChunkCanBlockRenderTypeBeRenderedEvent(final RebuildChunkCanBlockRenderTypeBeRenderedEvent event) { + if (!enabled) { + return; + } + + event.setCanceled(true); + } + + @SubscribeEvent + public static void onRebuildChunkCanBlockRenderInLayerEvent(final RebuildChunkCanBlockRenderInLayerEvent event) { + if (!enabled) { + return; + } + + event.setCanceled(true); + } + + @SubscribeEvent + public static void onRebuildChunkRenderBlockEvent(final RebuildChunkRenderBlockEvent event) { + if (!enabled) { + return; + } + + event.setCanceled(true); + } + + @SubscribeEvent + public static void onRebuildChunkPostIterationEvent(final RebuildChunkPostIterationEvent event) { + if (!enabled) { + return; + } + + event.setCanceled(true); + } + + @SubscribeEvent + public static void onRebuildChunkPostRenderEvent(final RebuildChunkPostRenderEvent event) { + if (!enabled) { + return; + } + + event.setCanceled(true); + } + + @SubscribeEvent + public static void onRebuildChunkPostEvent(final RebuildChunkPostEvent event) { + if (!enabled) { + return; + } + + event.setCanceled(true); + } + +} diff --git a/src/test/java/io/github/cadiboo/renderchunkrebuildchunkhooks/EventDenyingTester.java b/src/test/java/io/github/cadiboo/renderchunkrebuildchunkhooks/EventDenyingTester.java new file mode 100644 index 0000000..6663695 --- /dev/null +++ b/src/test/java/io/github/cadiboo/renderchunkrebuildchunkhooks/EventDenyingTester.java @@ -0,0 +1,161 @@ +package io.github.cadiboo.renderchunkrebuildchunkhooks; + +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkCanBlockRenderInLayerEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkCanBlockRenderTypeBeRenderedEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkCanFluidRenderInLayerEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkCheckWorldEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkIsFluidEmptyEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkPostEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkPostIterationEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkPostRenderEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkPreEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkPreIterationEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkPreRenderEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkRenderBlockEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.event.RebuildChunkRenderFluidEvent; +import io.github.cadiboo.renderchunkrebuildchunkhooks.hooks.HookConfig; +import net.minecraft.client.renderer.chunk.ChunkRenderTask; +import net.minecraft.client.renderer.chunk.CompiledChunk; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; + +import java.util.concurrent.locks.ReentrantLock; + +import static io.github.cadiboo.renderchunkrebuildchunkhooks.util.Refs.MOD_ID; +import static net.minecraftforge.eventbus.api.Event.Result.DENY; + +@EventBusSubscriber(modid = MOD_ID, value = Dist.CLIENT) +public final class EventDenyingTester { + + private static boolean enabled = true; + static { + if (enabled) { + HookConfig.enableAll(); + } + } + + @SubscribeEvent + public static void onRebuildChunkPreEvent(final RebuildChunkPreEvent event) { +// if (!enabled) { +// return; +// } +// +// event.setResult(DENY); +// +// final ChunkRenderTask generator = event.getGenerator(); +// final ReentrantLock lock = generator.getLock(); +// lock.lock(); +// try { +// generator.setCompiledChunk(new CompiledChunk()); +// } finally { +// lock.unlock(); +// } + } + + @SubscribeEvent + public static void onRebuildChunkCheckWorldEvent(final RebuildChunkCheckWorldEvent event) { + if (!enabled) { + return; + } + + event.setResult(DENY); + } + + @SubscribeEvent + public static void onRebuildChunkPreRenderEvent(final RebuildChunkPreRenderEvent event) { + if (!enabled) { + return; + } + + event.setResult(DENY); + } + + @SubscribeEvent + public static void onRebuildChunkPreIterationEvent(final RebuildChunkPreIterationEvent event) { + if (!enabled) { + return; + } + + event.setResult(DENY); + } + + @SubscribeEvent + public static void onRebuildChunkIsFluidEmptyEvent(final RebuildChunkIsFluidEmptyEvent event) { + if (!enabled) { + return; + } + + event.setResult(DENY); + } + + @SubscribeEvent + public static void onRebuildChunkCanFluidRenderInLayerEvent(final RebuildChunkCanFluidRenderInLayerEvent event) { + if (!enabled) { + return; + } + + event.setResult(DENY); + } + + @SubscribeEvent + public static void onRebuildChunkRenderFluidEvent(final RebuildChunkRenderFluidEvent event) { + if (!enabled) { + return; + } + + event.setResult(DENY); + } + + @SubscribeEvent + public static void onRebuildChunkCanBlockRenderTypeBeRenderedEvent(final RebuildChunkCanBlockRenderTypeBeRenderedEvent event) { + if (!enabled) { + return; + } + + event.setResult(DENY); + } + + @SubscribeEvent + public static void onRebuildChunkCanBlockRenderInLayerEvent(final RebuildChunkCanBlockRenderInLayerEvent event) { + if (!enabled) { + return; + } + + event.setResult(DENY); + } + + @SubscribeEvent + public static void onRebuildChunkRenderBlockEvent(final RebuildChunkRenderBlockEvent event) { + if (!enabled) { + return; + } + + event.setResult(DENY); + } + + @SubscribeEvent + public static void onRebuildChunkPostIterationEvent(final RebuildChunkPostIterationEvent event) { + if (!enabled) { + return; + } + + } + + @SubscribeEvent + public static void onRebuildChunkPostRenderEvent(final RebuildChunkPostRenderEvent event) { + if (!enabled) { + return; + } + + } + + @SubscribeEvent + public static void onRebuildChunkPostEvent(final RebuildChunkPostEvent event) { + if (!enabled) { + return; + } + + } + +} diff --git a/src/test/java/io/github/cadiboo/renderchunkrebuildchunkhooks/EventTester.java b/src/test/java/io/github/cadiboo/renderchunkrebuildchunkhooks/EventNonNullTester.java similarity index 95% rename from src/test/java/io/github/cadiboo/renderchunkrebuildchunkhooks/EventTester.java rename to src/test/java/io/github/cadiboo/renderchunkrebuildchunkhooks/EventNonNullTester.java index fbd8c67..10eed31 100644 --- a/src/test/java/io/github/cadiboo/renderchunkrebuildchunkhooks/EventTester.java +++ b/src/test/java/io/github/cadiboo/renderchunkrebuildchunkhooks/EventNonNullTester.java @@ -22,11 +22,13 @@ import static io.github.cadiboo.renderchunkrebuildchunkhooks.util.Refs.MOD_ID; @EventBusSubscriber(modid = MOD_ID, value = Dist.CLIENT) -public final class EventTester { +public final class EventNonNullTester { private static boolean enabled = true; static { - HookConfig.enableAll(); + if (enabled) { + HookConfig.enableAll(); + } } @SubscribeEvent @@ -88,6 +90,7 @@ public static void onRebuildChunkPreIterationEvent(final RebuildChunkPreIteratio Preconditions.checkNotNull(event.getEndPosition(), "blockpos1"); Preconditions.checkNotNull(event.getWorld(), "world"); Preconditions.checkNotNull(event.getRenderChunkCache(), "lvt_10_1_"); + Preconditions.checkNotNull(event.getIWorldReader(), "lvt_10_1_"); Preconditions.checkNotNull(event.getVisGraph(), "lvt_11_1_"); Preconditions.checkNotNull(event.getTileEntitiesWithGlobalRenderers(), "lvt_12_1_"); Preconditions.checkNotNull(event.getUsedBlockRenderLayers(), "aboolean"); @@ -109,6 +112,7 @@ public static void onRebuildChunkIsFluidEmptyEvent(final RebuildChunkIsFluidEmpt Preconditions.checkNotNull(event.getEndPosition(), "blockpos1"); Preconditions.checkNotNull(event.getWorld(), "world"); Preconditions.checkNotNull(event.getRenderChunkCache(), "lvt_10_1_"); + Preconditions.checkNotNull(event.getIWorldReader(), "lvt_10_1_"); Preconditions.checkNotNull(event.getVisGraph(), "lvt_11_1_"); Preconditions.checkNotNull(event.getTileEntitiesWithGlobalRenderers(), "lvt_12_1_"); Preconditions.checkNotNull(event.getUsedBlockRenderLayers(), "aboolean"); @@ -117,8 +121,6 @@ public static void onRebuildChunkIsFluidEmptyEvent(final RebuildChunkIsFluidEmpt Preconditions.checkNotNull(event.getIBlockState(), "iblockstate"); Preconditions.checkNotNull(event.getBlock(), "block"); Preconditions.checkNotNull(event.getIFluidState(), "ifluidstate"); - - event.setCanceled(true); } @SubscribeEvent @@ -135,6 +137,7 @@ public static void onRebuildChunkCanFluidRenderInLayerEvent(final RebuildChunkCa Preconditions.checkNotNull(event.getEndPosition(), "blockpos1"); Preconditions.checkNotNull(event.getWorld(), "world"); Preconditions.checkNotNull(event.getRenderChunkCache(), "lvt_10_1_"); + Preconditions.checkNotNull(event.getIWorldReader(), "lvt_10_1_"); Preconditions.checkNotNull(event.getVisGraph(), "lvt_11_1_"); Preconditions.checkNotNull(event.getTileEntitiesWithGlobalRenderers(), "lvt_12_1_"); Preconditions.checkNotNull(event.getUsedBlockRenderLayers(), "aboolean"); @@ -160,6 +163,7 @@ public static void onRebuildChunkRenderFluidEvent(final RebuildChunkRenderFluidE Preconditions.checkNotNull(event.getEndPosition(), "blockpos1"); Preconditions.checkNotNull(event.getWorld(), "world"); Preconditions.checkNotNull(event.getRenderChunkCache(), "lvt_10_1_"); + Preconditions.checkNotNull(event.getIWorldReader(), "lvt_10_1_"); Preconditions.checkNotNull(event.getVisGraph(), "lvt_11_1_"); Preconditions.checkNotNull(event.getTileEntitiesWithGlobalRenderers(), "lvt_12_1_"); Preconditions.checkNotNull(event.getUsedBlockRenderLayers(), "aboolean"); @@ -187,6 +191,7 @@ public static void onRebuildChunkCanBlockRenderTypeBeRenderedEvent(final Rebuild Preconditions.checkNotNull(event.getEndPosition(), "blockpos1"); Preconditions.checkNotNull(event.getWorld(), "world"); Preconditions.checkNotNull(event.getRenderChunkCache(), "lvt_10_1_"); + Preconditions.checkNotNull(event.getIWorldReader(), "lvt_10_1_"); Preconditions.checkNotNull(event.getVisGraph(), "lvt_11_1_"); Preconditions.checkNotNull(event.getTileEntitiesWithGlobalRenderers(), "lvt_12_1_"); Preconditions.checkNotNull(event.getUsedBlockRenderLayers(), "aboolean"); @@ -211,6 +216,7 @@ public static void onRebuildChunkCanBlockRenderInLayerEvent(final RebuildChunkCa Preconditions.checkNotNull(event.getEndPosition(), "blockpos1"); Preconditions.checkNotNull(event.getWorld(), "world"); Preconditions.checkNotNull(event.getRenderChunkCache(), "lvt_10_1_"); + Preconditions.checkNotNull(event.getIWorldReader(), "lvt_10_1_"); Preconditions.checkNotNull(event.getVisGraph(), "lvt_11_1_"); Preconditions.checkNotNull(event.getTileEntitiesWithGlobalRenderers(), "lvt_12_1_"); Preconditions.checkNotNull(event.getUsedBlockRenderLayers(), "aboolean"); @@ -236,6 +242,7 @@ public static void onRebuildChunkRenderBlockEvent(final RebuildChunkRenderBlockE Preconditions.checkNotNull(event.getEndPosition(), "blockpos1"); Preconditions.checkNotNull(event.getWorld(), "world"); Preconditions.checkNotNull(event.getRenderChunkCache(), "lvt_10_1_"); + Preconditions.checkNotNull(event.getIWorldReader(), "lvt_10_1_"); Preconditions.checkNotNull(event.getVisGraph(), "lvt_11_1_"); Preconditions.checkNotNull(event.getTileEntitiesWithGlobalRenderers(), "lvt_12_1_"); Preconditions.checkNotNull(event.getUsedBlockRenderLayers(), "aboolean"); @@ -263,6 +270,7 @@ public static void onRebuildChunkPostIterationEvent(final RebuildChunkPostIterat Preconditions.checkNotNull(event.getEndPosition(), "blockpos1"); Preconditions.checkNotNull(event.getWorld(), "world"); Preconditions.checkNotNull(event.getRenderChunkCache(), "lvt_10_1_"); + Preconditions.checkNotNull(event.getIWorldReader(), "lvt_10_1_"); Preconditions.checkNotNull(event.getVisGraph(), "lvt_11_1_"); Preconditions.checkNotNull(event.getTileEntitiesWithGlobalRenderers(), "lvt_12_1_"); Preconditions.checkNotNull(event.getUsedBlockRenderLayers(), "aboolean");