From 6a13d6a7b1a4c023d1c47d51e27befa8235a30e9 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Sat, 17 Aug 2024 20:31:37 -0400 Subject: [PATCH 1/3] Fix deployers not calling BlockItem#onUse --- .../kinetics/deployer/DeployerHandler.java | 2 +- .../foundation/mixin/BlockItemMixin.java | 27 +++++++++++++++++++ .../mixin/UseOnContextAccessor.java | 14 ++++++++++ src/main/resources/create.mixins.json | 2 ++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/simibubi/create/foundation/mixin/BlockItemMixin.java create mode 100644 src/main/java/com/simibubi/create/foundation/mixin/UseOnContextAccessor.java diff --git a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerHandler.java b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerHandler.java index c0319a8f3..254eb9884 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerHandler.java +++ b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerHandler.java @@ -300,7 +300,7 @@ public class DeployerHandler { return; if (useItem == DENY) return; - if (item instanceof BlockItem && !(item instanceof CartAssemblerBlockItem) + if (item instanceof CartAssemblerBlockItem && !clickedState.canBeReplaced(new BlockPlaceContext(itemusecontext))) return; diff --git a/src/main/java/com/simibubi/create/foundation/mixin/BlockItemMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/BlockItemMixin.java new file mode 100644 index 000000000..3e705b631 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/BlockItemMixin.java @@ -0,0 +1,27 @@ +package com.simibubi.create.foundation.mixin; + +import com.simibubi.create.content.kinetics.deployer.DeployerFakePlayer; + +import net.minecraft.world.InteractionResult; +import net.minecraft.world.item.BlockItem; + +import net.minecraft.world.item.context.BlockPlaceContext; + +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; + +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(BlockItem.class) +public class BlockItemMixin { + @Inject(method = "place", at = @At("HEAD"), cancellable = true) + private void create$fixDeployerPlacement(BlockPlaceContext pContext, CallbackInfoReturnable cir) { + BlockState state = pContext.getLevel().getBlockState(((UseOnContextAccessor) pContext).create$getHitResult().getBlockPos()); + if (state != Blocks.AIR.defaultBlockState() && pContext.getPlayer() instanceof DeployerFakePlayer) { + cir.setReturnValue(InteractionResult.PASS); + } + } +} diff --git a/src/main/java/com/simibubi/create/foundation/mixin/UseOnContextAccessor.java b/src/main/java/com/simibubi/create/foundation/mixin/UseOnContextAccessor.java new file mode 100644 index 000000000..245f973f8 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/UseOnContextAccessor.java @@ -0,0 +1,14 @@ +package com.simibubi.create.foundation.mixin; + +import net.minecraft.world.item.context.UseOnContext; + +import net.minecraft.world.phys.BlockHitResult; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(UseOnContext.class) +public interface UseOnContextAccessor { + @Invoker("getHitResult") + BlockHitResult create$getHitResult(); +} diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index a434994ce..7139181a9 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -6,6 +6,7 @@ "compatibilityLevel": "JAVA_17", "refmap": "create.refmap.json", "mixins": [ + "BlockItemMixin", "ClientboundMapItemDataPacketMixin", "ContraptionDriverInteractMixin", "CustomItemUseEffectsMixin", @@ -15,6 +16,7 @@ "MainMixin", "MapItemSavedDataMixin", "TestCommandMixin", + "UseOnContextAccessor", "WaterWheelFluidSpreadMixin", "accessor.AbstractProjectileDispenseBehaviorAccessor", "accessor.DispenserBlockAccessor", From d2445066569dc06f417c1e8ea467ddaa18d69c6e Mon Sep 17 00:00:00 2001 From: IThundxr Date: Sat, 17 Aug 2024 20:37:06 -0400 Subject: [PATCH 2/3] fix cart assembler --- .../create/content/kinetics/deployer/DeployerHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerHandler.java b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerHandler.java index c0319a8f3..a6189b298 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerHandler.java +++ b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerHandler.java @@ -300,8 +300,8 @@ public class DeployerHandler { return; if (useItem == DENY) return; - if (item instanceof BlockItem && !(item instanceof CartAssemblerBlockItem) - && !clickedState.canBeReplaced(new BlockPlaceContext(itemusecontext))) + if (item instanceof CartAssemblerBlockItem + && clickedState.canBeReplaced(new BlockPlaceContext(itemusecontext))) return; // Reposition fire placement for convenience From 10e533fecc461fd5a5bcaba0f4429f8e156ee87e Mon Sep 17 00:00:00 2001 From: IThundxr Date: Sun, 18 Aug 2024 17:49:13 -0400 Subject: [PATCH 3/3] move accessor to correct folder --- .../com/simibubi/create/foundation/mixin/BlockItemMixin.java | 2 ++ .../foundation/mixin/{ => accessor}/UseOnContextAccessor.java | 2 +- src/main/resources/create.mixins.json | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) rename src/main/java/com/simibubi/create/foundation/mixin/{ => accessor}/UseOnContextAccessor.java (85%) diff --git a/src/main/java/com/simibubi/create/foundation/mixin/BlockItemMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/BlockItemMixin.java index 3e705b631..a9c6d514b 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/BlockItemMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/BlockItemMixin.java @@ -2,6 +2,8 @@ package com.simibubi.create.foundation.mixin; import com.simibubi.create.content.kinetics.deployer.DeployerFakePlayer; +import com.simibubi.create.foundation.mixin.accessor.UseOnContextAccessor; + import net.minecraft.world.InteractionResult; import net.minecraft.world.item.BlockItem; diff --git a/src/main/java/com/simibubi/create/foundation/mixin/UseOnContextAccessor.java b/src/main/java/com/simibubi/create/foundation/mixin/accessor/UseOnContextAccessor.java similarity index 85% rename from src/main/java/com/simibubi/create/foundation/mixin/UseOnContextAccessor.java rename to src/main/java/com/simibubi/create/foundation/mixin/accessor/UseOnContextAccessor.java index 245f973f8..87f2929e0 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/UseOnContextAccessor.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/accessor/UseOnContextAccessor.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.mixin; +package com.simibubi.create.foundation.mixin.accessor; import net.minecraft.world.item.context.UseOnContext; diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index 7139181a9..9187472d9 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -16,7 +16,6 @@ "MainMixin", "MapItemSavedDataMixin", "TestCommandMixin", - "UseOnContextAccessor", "WaterWheelFluidSpreadMixin", "accessor.AbstractProjectileDispenseBehaviorAccessor", "accessor.DispenserBlockAccessor", @@ -25,7 +24,8 @@ "accessor.LivingEntityAccessor", "accessor.NbtAccounterAccessor", "accessor.ServerLevelAccessor", - "accessor.SystemReportAccessor" + "accessor.SystemReportAccessor", + "accessor.UseOnContextAccessor" ], "client": [ "accessor.AgeableListModelAccessor",