mojira.dev
MC-86978

Sideways placeable blocks placed on the side of replaceable blocks are positioned sideways, rather than straight up

The bug

Decorative heads, end rods, and shulker boxes sometimes don't place properly on grass and ferns, or the side of snow (the thin kind, not block, and this isn't shown in the video).

How to reproduce

Video demonstrating the issue.

Code analysis

Code analysis by @unknown can be found in this comment.

List of affected blocks

  • shulker box

  • end rod

  • lightning rod

  • grindstone

  • heads

  • (stripped) logs/wood/hyphae/stems

  • (polished) basalt

  • bone block

  • hay block

  • chain

  • purpur pillar

  • quartz pillar

  • amethyst cluster

  • amethyst bud

  • deepslate

Linked issues

Attachments

Comments 25

Swekob

Confirmed for 15w46a

marcono1234

Confirmed for

  • 1.10.2

marcono1234

Please link to this comment in the description

The following is based on a decompiled version of Minecraft 1.10 using MCP 9.30.

The reason for this is that the method net.minecraft.item.ItemSkull.onItemUse(ItemStack, EntityPlayer, World, BlockPos, EnumHand, EnumFacing, float, float, float) still uses the direction the placer is clicking on a block even if the block is replaced.

Suggested fix

/**
 * Called when a Block is right-clicked with this Item
 */
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    if (facing == EnumFacing.DOWN)
    {
        return EnumActionResult.FAIL;
    }
    else
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();
        boolean flag = block.isReplaceable(worldIn, pos);

        if (!flag)
        {
            if (!worldIn.getBlockState(pos).getMaterial().isSolid())
            {
                return EnumActionResult.FAIL;
            }

            pos = pos.offset(facing);
        }
        // Added this
        else
        {
            if (!worldIn.getBlockState(pos.down()).getMaterial().isSolid())
            {
                return EnumActionResult.FAIL;
            }
            else {
                facing = EnumFacing.UP;
            }
        }

        //...
    }
}

Same situations also for the ItemBlock class.

Suggested fix

/**
 * Called when a Block is right-clicked with this Item
 */
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    IBlockState iblockstate = worldIn.getBlockState(pos);
    Block block = iblockstate.getBlock();

    if (!block.isReplaceable(worldIn, pos))
    {
        pos = pos.offset(facing);
    }
    // Added this
    else {
        facing = EnumFacing.UP;
    }

    //...
}

Note: There might be more directonal blocks of which the item places the block if the method onItemUse is called instead of the general ItemBlock class.

muzikbike

Affects 18w20c

wobst.michael

@unknown, ticket is yours now.

15 more comments
Avoma

Can confirm in 1.17.1.

Avoma

Can confirm in 1.18.1.

Avoma

Can confirm in 1.18.2.

Avoma

Can confirm in 1.19.

Avoma

Can confirm in 1.19.2.

Matthew L

muzikbike

(Unassigned)

Confirmed

Platform

Low

Items

general-breaking-zone, placement, placement-and-support

Minecraft 15w34d, Minecraft 15w44b, Minecraft 15w46a, Minecraft 1.10.2, Minecraft 16w42a, ..., 1.19.2, 1.19.3, 1.20.1, 1.20.3 Release Candidate 1, 1.20.4

Retrieved