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.

Related issues

Comments

migrated

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.

tryashtar

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

migrated

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

marcono1234

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

migrated

Confirmed in Minecraft 1.12 Pre Release 4

migrated

Confirmed in Minecraft 1.12 Pre Release 5

insane96mcp

Can confirm for 1.12 Pre-7

migrated

Confirmed for 1.12!
I hoped that the delay would mean a fix before the release. 😞

EDIT:
Possible temporary fix for map makers: Use the destroy argument instead of the replace argument and make sure to do: /gamerule doTileDrops false. This prevents the block to appear as item after destruction.

migrated

The same issue with me, too!

tryashtar

Was not fixed with the new command system. Updated the syntax of the commands to 1.13's format.

blablubbabc

Confirmed for snapshot 17w50a. Hope this finds its way into 1.13, with all those nbt-related command changes.

lord.quadrato

Confirmed for 1.13-pre2

AlexMCool

Affects 1.13-pre4

AlexMCool

Affects 1.13-pre5

AlexMCool

Affects 1.13-pre6

AlexMCool

Affects 1.13-pre7

AlexMCool

And 1.13-pre8

AlexMCool

And 1.13-pre9

AlexMCool

And 1.13

AlexMCool

And 18w30a

AlexMCool

And 18w30b

AlexMCool

And 18w31a

migrated

Confirmed for 18w46a.

ZeNico13

Still in 19w08a

migrated

Please do not mark unreleased versions as affected.
You don't have access to them yet.

ZeNico13

Still in 1.14.1 Release

migrated

Present in 19w44a

migrated

Still seeing this in 1.16.3

Trying to use fill command to replace end_gateway blocks with different nbt results in No blocks filled message. 

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.

MrBurdy

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.

migrated

Affects 1.21.3

migrated

Affects 24w44a

tryashtar

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

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