Backport bugfix for block place event to 1.16... again

This commit is contained in:
Max
2023-05-04 09:59:19 +02:00
parent 0c00f0e7c7
commit 1228e4a765

View File

@@ -23,17 +23,23 @@ import me.shedaniel.architectury.event.events.BlockEvent;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.context.BlockPlaceContext;
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;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(BlockItem.class)
public abstract class MixinBlockItem {
@Inject(method = "place", at = @At("HEAD"), cancellable = true)
private void place(BlockPlaceContext context, CallbackInfoReturnable<InteractionResult> cir) {
InteractionResult result = BlockEvent.PLACE.invoker().placeBlock(context.getLevel(), context.getClickedPos(), context.getLevel().getBlockState(context.getClickedPos()), context.getPlayer());
if (result != InteractionResult.PASS) {
@Inject(method = "place",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/item/BlockItem;placeBlock(Lnet/minecraft/world/item/context/BlockPlaceContext;Lnet/minecraft/world/level/block/state/BlockState;)Z"),
locals = LocalCapture.CAPTURE_FAILHARD,
cancellable = true)
private void place(BlockPlaceContext _0, CallbackInfoReturnable<InteractionResult> cir, BlockPlaceContext context, BlockState placedState) {
InteractionResult result = BlockEvent.PLACE.invoker().placeBlock(context.getLevel(), context.getClickedPos(), placedState, context.getPlayer());
if (result == InteractionResult.FAIL) {
cir.setReturnValue(result);
}
}