Jump to content

Changes to IForgeBlock.rotate


ShetiPhian

Recommended Posts

While updating my blocks I've found some issues with rotate, so I'm sharing my thoughts and proving a suggested fix.

 

Starting with the parameters.

The addition of 'Rotation' is quite helpful as now tools can indicate direction, but the removal of EnumFacing(Direction) hurts the usability as you can no longer rotate based on the face clicked (eg. axis rotation)

Therefore I'm suggesting re-adding Direction, and while we're at it there is no harm in adding Entity as well

 

Now for the bigger issue, the return type changing from boolean to BlockState. This should be reverted.

Prior to 1.13 the boolean return was simple, true if the block rotated and false if not. Therefore blocks handled their own rotation and tools handled their durability based on the boolean.

1.13 and beyond returns a BlockState, and looking at the vanilla blocks indicates the tool is now responsible for rotating the block to the value returned.

This works fine for single blocks that only rotate, but causes issues with blocks that need to update connected blocks. (even the vanilla beds don't rotate correctly)

If the block updates it's connected blocks, then the tool doesn't update the originals state, the multi block is broken. You could just use the neighbor changed method to update connected blocks, but that requires additional checks etc, and fails if the tool didn't have the state change flag set to notify.

 

Here is the proposed reworked method:

default boolean rotate(BlockState state, IWorld world, BlockPos pos, Rotation rotation, Direction direction, Entity entity)
{
    Block block = state.getBlock();
    if (!(block instanceof BedBlock) && !(block instanceof PistonHeadBlock))
    {
        BlockState result = state.rotate(rotation);
        if (result != world.getBlockState(pos))
        {
            return world.setBlockState(pos, state, 3);
        }
    }
    return false;
}

 

If others agree, anyone is free to take the code and create a pull request.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.