diff --git a/src/main/java/com/ldtteam/structurize/util/BlockUtils.java b/src/main/java/com/ldtteam/structurize/util/BlockUtils.java index 3ac50251b..7c66e398d 100644 --- a/src/main/java/com/ldtteam/structurize/util/BlockUtils.java +++ b/src/main/java/com/ldtteam/structurize/util/BlockUtils.java @@ -573,35 +573,17 @@ public static void handleCorrectBlockPlacement( { world.removeBlock(here, false); } - else if (item instanceof BlockItem) - { - final Block targetBlock = ((BlockItem) item).getBlock(); - BlockState newState = copyFirstCommonBlockStateProperties(targetBlock.defaultBlockState(), blockState); - - if (newState == null) - { - fakePlayer.setItemInHand(InteractionHand.MAIN_HAND, stackToPlace); - if (stackToPlace.is(ItemTags.BEDS) && blockState.hasProperty(HorizontalDirectionalBlock.FACING)) - { - fakePlayer.setYRot(blockState.getValue(HorizontalDirectionalBlock.FACING).get2DDataValue() * 90); - } - - newState = targetBlock.getStateForPlacement(new BlockPlaceContext(new UseOnContext(fakePlayer, - InteractionHand.MAIN_HAND, - new BlockHitResult(new Vec3(0, 0, 0), - itemStack.getItem() instanceof BedItem ? Direction.UP : Direction.NORTH, - here, - true)))); - - if (newState == null) - { - return; - } - } - - // place - world.setBlock(here, Blocks.COBBLESTONE.defaultBlockState(), Block.UPDATE_CLIENTS); - world.setBlock(here, newState, Constants.UPDATE_FLAG); + else if (item instanceof BlockItem blockItem) + { + final Block targetBlock = blockItem.getBlock(); + fakePlayer.setItemInHand(InteractionHand.MAIN_HAND, stackToPlace); + final BlockPlaceContext ctx = new BlockPlaceContext(new UseOnContext(fakePlayer, InteractionHand.MAIN_HAND, + new BlockHitResult(new Vec3(0, 0, 0), Direction.NORTH, here, true))); + final BlockState placementState = targetBlock.getStateForPlacement(ctx); + BlockState newState = copyFirstCommonBlockStateProperties(placementState != null ? placementState : targetBlock.defaultBlockState(), blockState); + world.setBlock(here, newState, Block.UPDATE_ALL_IMMEDIATE); + newState = blockItem.updateBlockStateFromTag(here, world, stackToPlace, newState); + blockItem.updateCustomBlockEntityTag(here, world, fakePlayer, stackToPlace, newState); targetBlock.setPlacedBy(world, here, newState, fakePlayer, stackToPlace); } else if (item instanceof BucketItem) diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 25217fca0..03414b6cb 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -25,3 +25,7 @@ public net.minecraft.world.level.levelgen.SurfaceRules$SurfaceRule public net.minecraft.client.KeyMapping f_90818_ # clickCount public net.minecraft.world.level.block.state.BlockBehaviour f_60443_ # hasCollision + +# BlockItem placement logic +public net.minecraft.world.item.BlockItem m_40602_(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/level/block/state/BlockState; #updateBlockStateFromTag +public net.minecraft.world.item.BlockItem m_7274_(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/level/block/state/BlockState;)Z # updateCustomBlockEntityTag