Merge pull request #6836 from IThundxr/mc1.18/fix-deployer-blockitem-onuse

Fix deployers not calling BlockItem#onUse
This commit is contained in:
simibubi 2024-08-25 11:08:05 +02:00 committed by GitHub
commit 5ac7e6fe77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 48 additions and 3 deletions

View File

@ -300,8 +300,8 @@ public class DeployerHandler {
return; return;
if (useItem == DENY) if (useItem == DENY)
return; return;
if (item instanceof BlockItem && !(item instanceof CartAssemblerBlockItem) if (item instanceof CartAssemblerBlockItem
&& !clickedState.canBeReplaced(new BlockPlaceContext(itemusecontext))) && clickedState.canBeReplaced(new BlockPlaceContext(itemusecontext)))
return; return;
// Reposition fire placement for convenience // Reposition fire placement for convenience

View File

@ -0,0 +1,29 @@
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;
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<InteractionResult> cir) {
BlockState state = pContext.getLevel().getBlockState(((UseOnContextAccessor) pContext).create$getHitResult().getBlockPos());
if (state != Blocks.AIR.defaultBlockState() && pContext.getPlayer() instanceof DeployerFakePlayer) {
cir.setReturnValue(InteractionResult.PASS);
}
}
}

View File

@ -0,0 +1,14 @@
package com.simibubi.create.foundation.mixin.accessor;
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();
}

View File

@ -6,6 +6,7 @@
"compatibilityLevel": "JAVA_17", "compatibilityLevel": "JAVA_17",
"refmap": "create.refmap.json", "refmap": "create.refmap.json",
"mixins": [ "mixins": [
"BlockItemMixin",
"ClientboundMapItemDataPacketMixin", "ClientboundMapItemDataPacketMixin",
"ContraptionDriverInteractMixin", "ContraptionDriverInteractMixin",
"CustomItemUseEffectsMixin", "CustomItemUseEffectsMixin",
@ -23,7 +24,8 @@
"accessor.LivingEntityAccessor", "accessor.LivingEntityAccessor",
"accessor.NbtAccounterAccessor", "accessor.NbtAccounterAccessor",
"accessor.ServerLevelAccessor", "accessor.ServerLevelAccessor",
"accessor.SystemReportAccessor" "accessor.SystemReportAccessor",
"accessor.UseOnContextAccessor"
], ],
"client": [ "client": [
"accessor.AgeableListModelAccessor", "accessor.AgeableListModelAccessor",