Error changing tile entity's BlockState

[18:52:28 ERROR]: Block at 19,937, 103, -17,209 is Block{minecraft:dirt} but has net.minecraft.ser[email protected] Bukkit will attempt to fix this, but there may be additional damage that we cannot recover.

I’m getting this error when trying to set a tile entity (chest in this case) to a non tile entity. This same error happens using Block#setBlockData() as well as BlockState#setBlockData().

I also tried removing all PersistentDataContainer keys from the BlockState, but that doesn’t seem to fix the issue. Here’s my most recent attempt at a fix:

BlockState blockState = block.getState();
if (blockState instanceof TileState) {
    PersistentDataContainer pdc = ((TileState) blockState).getPersistentDataContainer();
    for (NamespacedKey key : pdc.getKeys()) {


My only idea for a fix would be to set the BlockState of the block to a completely new BlockState initialized using the BlockData that I’m using, but I don’t know if that would work or not. My reasoning behind this idea is that the error probably comes from the fact that the CraftBlockData implements TileState (and one of its subinterfaces depending on the tile entity type), so I think a solution might be to create a new BlockState that either implements a different tile entity inteface or doesn’t implement one at all, which theoretically will stop the error.

Bump, any ideas for a fix?