Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 11 additions & 29 deletions src/main/java/com/ldtteam/structurize/util/BlockUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't go over this placement context because this will mess with blocks like stairs, etc as they use hit directions etc which will result in strange things.
Which of these things here specifically do the necessary things for the panels to work?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is I need getStateForPlacement, which is what requires the placement context

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do a test with stairs but important is that this is only used by scan tool replaces it looks like

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the copy properties method that goes after the placement state should copy the direction of a stair over

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getStateForPlacement probably translates some meta data into the blockstate property we need. We should be able to get this from the internal call that method uses

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just in case, according to documentation (that is, the chat message in game), if you replace a block with another block with similar block states, it should inherit the block states
If the new block has block states that are not present on the old block, the default block state property is used (and the chat message is printed)
Which means, in particular for stairs, if you are replacing one stair with another, it should have the same shape in the same direction, and if you are replacing a non-stair non-shingle with a stair, it should always face in the default direction (north?), independent from how you are standing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getStateForPlacement probably translates some meta data into the blockstate property we need. We should be able to get this from the internal call that method uses

There's nothing else for this, check PanelBlock in DO

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified and stairs continue to work normal. Because of:

BlockState newState = copyFirstCommonBlockStateProperties(placementState != null ? placementState : targetBlock.defaultBlockState(), blockState);

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)
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading