mojira.dev
MC-117574

Using /setblock or /fill to re-place a block entity keeps old NBT (if no NBT specified) but clears inventories, even when the command fails

The bug

When using /setblock or /fill to replace a block entity, this keeps the old NBT (if no NBT is specified), but clears the inventories, even if the command fails.

Additionally, the command will fail if the specified block state matches the existing one, even if there is new NBT to apply. The result is only inventories clearing.

How to reproduce

  • Example 1:

    /setblock ~1 ~ ~ dropper[facing=up]{CustomName:"\"first\"",Items:[{id:stone,Count:1b,Slot:0b}]}

    This places a dropper as expected. Now run the following command:

    /setblock ~1 ~ ~ dropper[facing=up]{CustomName:"\"updated\"",Items:[{id:stone,Count:1b,Slot:0b}]}

    Expected behavior: command succeeds (because NBT differs), dropper updates name.
    Actual behavior: command fails (because the blockstates are the same), dropper does not update name, inventory clear.
    Note: Leaving off the NBT in the last command has the same effect.

  • Example 2:

    /setblock ~1 ~ ~ command_block[facing=up]{Command:"first"}

    This places a command block as expected. Now run the following command:

    /setblock ~1 ~ ~ command_block[facing=down]

    Expected behavior: command block is empty
    Actual behavior: command block contains the command "first".
    Note: including NBT in the last command successfully places a new block as expected.

Linked issues

MC-118677 Return "No block filled" when try to empty chest with /fill command Resolved MC-119249 setblock replace not working for mob_spawners Resolved MC-119806 Skulls bug Resolved MC-119826 Cannot setblock a sign on the position of another sign Resolved MC-120438 Signs don't replace signs Resolved

Comments 33

The bug seems to completely erase the nbt data of the block, to reprodice simply put this command in a command block and run it twice.

setblock ~ ~1 ~ dropper facing=up replace {Items:[{id:"minecraft:stone",Count:1b}]}

The first time the command is run there will be a stone block in the dropper and the second time the dropper will be empty.

Hey @Bertie2011, we did some testing and I rewrote your report to be more detailed. Hope you don't mind!

@tryashtar
No, I don't mind. I didn't have much time to test things out, thanks for expanding my post =)

Could be related to MC-50166 since replacing all blocks with air / barrier blocks first was likely done to remove tile entities.

Confirmed in Minecraft 1.12 Pre Release 4

23 more comments
Jack McKalling

It seems like this issue doesn't necessarily have anything to do with inventories. What happens is that the target block just gets "cleared" of data, and simply not (re)populated with the specified NBT.
As if replacing a block with differing NBT is interpreted as invalid data for the block and just forced erased upon replace.

I've had the same problem with lecterns, and no matter how much I replaced the block with air and then put in the new lecternwithnbt, the new lectern has the old NBTs. (although in the meantime I've put in a block of air to 'clear').
And 1.20 last pre realase.

Affects 1.21.3

Affects 24w44a

The first example is fixed in 25w02a, and the second example is now intended, per these changes in the changelog:

  • If the block entity data is not specified, and the existing block has data, the block entity data will be preserved

  • If the block entity data is specified, the block entity data will be set to the specified value

  • To clear the block entity data explicitly, you must now specify the block entity data as {}

  • The operation is now successful if either the block state changed or the block entity data changed

Bertie

AlexMCool

(Unassigned)

Confirmed

Platform

Normal

Block states, Commands

/fill, /setblock, block, block-data, command, nbt, nbt-tags, replace

Minecraft 1.12 Pre-Release 3, Minecraft 1.12 Pre-Release 4, Minecraft 1.12 Pre-Release 5, Minecraft 1.12 Pre-Release 6, Minecraft 1.12 Pre-Release 7, ..., 1.20.4, 24w13a, 24w44a, 1.21.3, 1.21.4

25w02a

Retrieved