From bcce83c829b6b5eda012fda54c441fa0c4c2ae0d Mon Sep 17 00:00:00 2001 From: Virtuoel Date: Thu, 12 Sep 2019 05:09:40 +0300 Subject: [PATCH 1/2] Fix NPE in fluid renderer mixin (#361) * Fix NPE in fluid renderer mixin * Ensure state, view, and pos are never null * Bump fabric-rendering-fluids-v1 version --- fabric-rendering-fluids-v1/build.gradle | 2 +- .../render/fluid/MixinFluidRenderer.java | 21 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/fabric-rendering-fluids-v1/build.gradle b/fabric-rendering-fluids-v1/build.gradle index 1046ac5b4..6c2ef5727 100644 --- a/fabric-rendering-fluids-v1/build.gradle +++ b/fabric-rendering-fluids-v1/build.gradle @@ -1,5 +1,5 @@ archivesBaseName = "fabric-rendering-fluids-v1" -version = getSubprojectVersion(project, "0.1.1") +version = getSubprojectVersion(project, "0.1.2") dependencies { compile project(path: ':fabric-api-base', configuration: 'dev') diff --git a/fabric-rendering-fluids-v1/src/main/java/net/fabricmc/fabric/mixin/client/render/fluid/MixinFluidRenderer.java b/fabric-rendering-fluids-v1/src/main/java/net/fabricmc/fabric/mixin/client/render/fluid/MixinFluidRenderer.java index 8b3557fcf..cf5251ba1 100644 --- a/fabric-rendering-fluids-v1/src/main/java/net/fabricmc/fabric/mixin/client/render/fluid/MixinFluidRenderer.java +++ b/fabric-rendering-fluids-v1/src/main/java/net/fabricmc/fabric/mixin/client/render/fluid/MixinFluidRenderer.java @@ -52,20 +52,21 @@ public class MixinFluidRenderer { public void tesselate(ExtendedBlockView view, BlockPos pos, BufferBuilder bufferBuilder, FluidState state, CallbackInfoReturnable info) { FluidRendererHookContainer ctr = fabric_renderHandler.get(); FluidRenderHandler handler = FluidRenderHandlerRegistryImpl.INSTANCE.getOverride(state.getFluid()); - if (handler == null) { - return; - } - - /* ActionResult hResult = handler.tesselate(view, pos, bufferBuilder, state); - if (hResult != ActionResult.PASS) { - info.setReturnValue(hResult == ActionResult.SUCCESS); - return; - } */ ctr.view = view; ctr.pos = pos; ctr.state = state; ctr.handler = handler; + + /* if (handler == null) { + return; + } + + ActionResult hResult = handler.tesselate(view, pos, bufferBuilder, state); + if (hResult != ActionResult.PASS) { + info.setReturnValue(hResult == ActionResult.SUCCESS); + return; + } */ } @Inject(at = @At("RETURN"), method = "tesselate") @@ -81,7 +82,7 @@ public class MixinFluidRenderer { // Has other uses but those have already happened by the time the hook is called. final FluidRendererHookContainer ctr = fabric_renderHandler.get(); - return chk || (ctr != null && !ctr.state.matches(FluidTags.WATER)); + return chk || !ctr.state.matches(FluidTags.WATER); } @ModifyVariable(at = @At(value = "INVOKE", target = "net/minecraft/client/render/block/FluidRenderer.isSameFluid(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;Lnet/minecraft/fluid/FluidState;)Z"), method = "tesselate", ordinal = 0) From 7eee2bafa34bdc234a3c96781faef3cb02fad415 Mon Sep 17 00:00:00 2001 From: liach <7806504+liach@users.noreply.github.com> Date: Fri, 13 Sep 2019 14:01:21 -0500 Subject: [PATCH 2/2] Update UseItemCallback to 19w37a * A fix for #364 Signed-off-by: liach * Version to 0.2.0 --- fabric-events-interaction-v0/build.gradle | 2 +- .../fabric/api/event/player/UseItemCallback.java | 12 +++++++----- .../MixinClientPlayerInteractionManager.java | 10 ++++++---- .../MixinServerPlayerInteractionManager.java | 7 ++++--- .../src/main/resources/fabric.mod.json | 3 ++- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/fabric-events-interaction-v0/build.gradle b/fabric-events-interaction-v0/build.gradle index df81ca51c..2fba66254 100644 --- a/fabric-events-interaction-v0/build.gradle +++ b/fabric-events-interaction-v0/build.gradle @@ -1,5 +1,5 @@ archivesBaseName = "fabric-events-interaction-v0" -version = getSubprojectVersion(project, "0.1.2") +version = getSubprojectVersion(project, "0.2.0") dependencies { compile project(path: ':fabric-api-base', configuration: 'dev') diff --git a/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/api/event/player/UseItemCallback.java b/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/api/event/player/UseItemCallback.java index 38e27d5b5..752eea77c 100644 --- a/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/api/event/player/UseItemCallback.java +++ b/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/api/event/player/UseItemCallback.java @@ -19,8 +19,10 @@ package net.fabricmc.fabric.api.event.player; import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.EventFactory; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; import net.minecraft.world.World; /** @@ -34,17 +36,17 @@ import net.minecraft.world.World; */ public interface UseItemCallback { public static final Event EVENT = EventFactory.createArrayBacked(UseItemCallback.class, - (listeners) -> (player, world, hand) -> { + listeners -> (player, world, hand) -> { for (UseItemCallback event : listeners) { - ActionResult result = event.interact(player, world, hand); - if (result != ActionResult.PASS) { + TypedActionResult result = event.interact(player, world, hand); + if (result.getResult() != ActionResult.PASS) { return result; } } - return ActionResult.PASS; + return TypedActionResult.method_22430(ItemStack.EMPTY); } ); - ActionResult interact(PlayerEntity player, World world, Hand hand); + TypedActionResult interact(PlayerEntity player, World world, Hand hand); } diff --git a/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/mixin/eventsinteraction/MixinClientPlayerInteractionManager.java b/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/mixin/eventsinteraction/MixinClientPlayerInteractionManager.java index 237153f2f..c1832de45 100644 --- a/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/mixin/eventsinteraction/MixinClientPlayerInteractionManager.java +++ b/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/mixin/eventsinteraction/MixinClientPlayerInteractionManager.java @@ -24,11 +24,13 @@ import net.minecraft.client.network.ClientPlayerInteractionManager; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; import net.minecraft.server.network.packet.PlayerInteractBlockC2SPacket; import net.minecraft.server.network.packet.PlayerInteractEntityC2SPacket; import net.minecraft.server.network.packet.PlayerInteractItemC2SPacket; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.math.BlockPos; @@ -87,10 +89,10 @@ public class MixinClientPlayerInteractionManager { } @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/Packet;)V", ordinal = 0), method = "interactItem", cancellable = true) - public void interactItem(PlayerEntity player, World world, Hand hand, CallbackInfoReturnable info) { - ActionResult result = UseItemCallback.EVENT.invoker().interact(player, world, hand); - if (result != ActionResult.PASS) { - if (result == ActionResult.SUCCESS) { + public void interactItem(PlayerEntity player, World world, Hand hand, CallbackInfoReturnable> info) { + TypedActionResult result = UseItemCallback.EVENT.invoker().interact(player, world, hand); + if (result.getResult() != ActionResult.PASS) { + if (result.getResult() == ActionResult.SUCCESS) { this.networkHandler.sendPacket(new PlayerInteractItemC2SPacket(hand)); } info.setReturnValue(result); diff --git a/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/mixin/eventsinteraction/MixinServerPlayerInteractionManager.java b/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/mixin/eventsinteraction/MixinServerPlayerInteractionManager.java index bd82961c9..43948f5fa 100644 --- a/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/mixin/eventsinteraction/MixinServerPlayerInteractionManager.java +++ b/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/mixin/eventsinteraction/MixinServerPlayerInteractionManager.java @@ -28,6 +28,7 @@ import net.minecraft.server.network.packet.PlayerActionC2SPacket; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -68,9 +69,9 @@ public class MixinServerPlayerInteractionManager { @Inject(at = @At("HEAD"), method = "interactItem", cancellable = true) public void interactItem(PlayerEntity player, World world, ItemStack stack, Hand hand, CallbackInfoReturnable info) { - ActionResult result = UseItemCallback.EVENT.invoker().interact(player, world, hand); - if (result != ActionResult.PASS) { - info.setReturnValue(result); + TypedActionResult result = UseItemCallback.EVENT.invoker().interact(player, world, hand); + if (result.getResult() != ActionResult.PASS) { + info.setReturnValue(result.getResult()); info.cancel(); return; } diff --git a/fabric-events-interaction-v0/src/main/resources/fabric.mod.json b/fabric-events-interaction-v0/src/main/resources/fabric.mod.json index 18f860d4b..a87909b49 100644 --- a/fabric-events-interaction-v0/src/main/resources/fabric.mod.json +++ b/fabric-events-interaction-v0/src/main/resources/fabric.mod.json @@ -17,7 +17,8 @@ ], "depends": { "fabricloader": ">=0.4.0", - "fabric-api-base": "*" + "fabric-api-base": "*", + "minecraft": ">=1.15-alpha.19.37.a" }, "entrypoints": { "main": [