litematica icon indicating copy to clipboard operation
litematica copied to clipboard

Block entity data is not pasted correctly

Open zly2006 opened this issue 1 year ago • 7 comments

To reproduce:

  1. Make a schema in single player mode, with 16 chests full of stones expected
  2. paste it to a server.

Observed behavior

In Place & Data Modify Mode

0-not-pasted After pressing the operation key, we found 5 of the 16 chests has no block entity data. 1-empty 3-all-empty This may be caused by some error during setblock command. error I used the following code to see what is wrong but there is not much information.

@Mixin(SetBlockCommand.class)
public class MixinSetBlockCommand {
    @Inject(method = "execute", at = @At(value = "INVOKE", target = "Lcom/mojang/brigadier/exceptions/SimpleCommandExceptionType;create()Lcom/mojang/brigadier/exceptions/CommandSyntaxException;"))
    private static void onError(ServerCommandSource source, BlockPos pos, BlockStateArgument block, SetBlockCommand.Mode mode, Predicate<CachedBlockPosition> condition, CallbackInfoReturnable<Integer> cir) {
        System.out.println("SetBlockCommand failed, pos=" + pos + ", block=" + block.getBlockState() + ", mode=" + mode);
        System.out.println("Current block state: " + source.getWorld().getBlockState(pos));
        BlockEntity be = source.getWorld().getBlockEntity(pos);
        if (be != null) {
            System.out.println("Current block entity: " + be.toInitialChunkDataTag());
        }
    }
}

Logs here:

[00:24:58] [Server thread/INFO] (Minecraft) [Steve47876: Changed the block at 4, 72, 69]
[00:24:58] [Server thread/INFO] (Minecraft) [Steve47876: Changed the block at 6, 68, 77]
[00:24:58] [Server thread/INFO] (Minecraft) [STDOUT]: SetBlockCommand failed, pos=BlockPos{x=-1, y=72, z=69}, block=Block{minecraft:air}, mode=REPLACE
[00:24:58] [Server thread/INFO] (Minecraft) [STDOUT]: Current block state: Block{minecraft:air}
[00:24:58] [Server thread/INFO] (Minecraft) [Steve47876: Changed the block at 6, 68, 78]
[00:24:58] [Server thread/INFO] (Minecraft) [STDOUT]: SetBlockCommand failed, pos=BlockPos{x=6, y=72, z=69}, block=Block{minecraft:air}, mode=REPLACE
[00:24:58] [Server thread/INFO] (Minecraft) [STDOUT]: Current block state: Block{minecraft:air}
[00:24:58] [Server thread/INFO] (Minecraft) [Steve47876: Changed the block at 6, 68, 79]
[00:24:58] [Server thread/INFO] (Minecraft) [STDOUT]: SetBlockCommand failed, pos=BlockPos{x=-2, y=72, z=70}, block=Block{minecraft:air}, mode=REPLACE
[00:24:58] [Server thread/INFO] (Minecraft) [STDOUT]: Current block state: Block{minecraft:air}
[00:24:58] [Server thread/INFO] (Minecraft) [Steve47876: Changed the block at 7, 68, 77]

In Place & Clone Mode

In this mode, the behavior if more strange: even the block state cannot be pasted correctly. however the block entity data is correct, if the block is successfully placed. clone

Some error during setblock command is also reported by my code, log here:

[00:35:17] [Server thread/INFO] (Minecraft) [STDOUT]: SetBlockCommand failed, pos=BlockPos{x=-6, y=75, z=67}, block=Block{minecraft:air}, mode=REPLACE
[00:35:17] [Server thread/INFO] (Minecraft) [STDOUT]: Current block state: Block{minecraft:air}
[00:35:17] [Server thread/INFO] (Minecraft) [STDOUT]: SetBlockCommand failed, pos=BlockPos{x=2, y=75, z=67}, block=Block{minecraft:air}, mode=REPLACE
[00:35:17] [Server thread/INFO] (Minecraft) [STDOUT]: Current block state: Block{minecraft:air}

Also thanks to @tangsu99 for discovering this bug.

zly2006 avatar May 22 '23 16:05 zly2006

What is your commandLimitPerTick set to? You may be running out of the temporary block positions around the player for the NBT smuggling operation? I think the setblock with air would point to that, as it gets rid of those temporary blocks with a setblock air command, and if there was no block placed. That might happen if the player moved and intersected the temp position, or maybe if there were no valid temp positions? Although I don't think it would try to get rid of it if it failed to find a valid position in the first place.

And yeah the Place & Data Modify is the only option that actually works properly... when it works properly... :p The clone option can't get the correct block state if there are any neighbor connections etc. And the teleport option (if it was still there?) just doesn't work at all.

maruohon avatar May 22 '23 17:05 maruohon

The default command limit is often way too high even without NBT restore. With NBT restore I'd recommend dropping it to maybe 4 commands per tick or even lower, otherwise you will likely run out of the temp positions around the player.

maruohon avatar May 22 '23 17:05 maruohon