JavaUpdateTileEntityTranslator improvements

- Remove the use of deprecated functions
- Check for empty NBT (fixes errors on CubeCraft)
This commit is contained in:
DoctorMacc 2020-07-06 16:22:07 -04:00
parent 82c6276794
commit 545dfa38f0

View file

@ -40,12 +40,17 @@ public class JavaUpdateTileEntityTranslator extends PacketTranslator<ServerUpdat
@Override
public void translate(ServerUpdateTileEntityPacket packet, GeyserSession session) {
String id = BlockEntityUtils.getBedrockBlockEntityId(packet.getType().name());
if (packet.getNbt().isEmpty()) { // Fixes errors in CubeCraft sending empty NBT
BlockEntityUtils.updateBlockEntity(session, null, packet.getPosition());
return;
}
BlockEntityTranslator translator = BlockEntityUtils.getBlockEntityTranslator(id);
// If not null then the BlockState is used in BlockEntityTranslator.translateTag()
if (ChunkUtils.CACHED_BLOCK_ENTITIES.get(packet.getPosition()) != null) {
if (ChunkUtils.CACHED_BLOCK_ENTITIES.containsKey(packet.getPosition())) {
int blockState = ChunkUtils.CACHED_BLOCK_ENTITIES.getOrDefault(packet.getPosition(), 0);
BlockEntityUtils.updateBlockEntity(session, translator.getBlockEntityTag(id, packet.getNbt(),
ChunkUtils.CACHED_BLOCK_ENTITIES.get(packet.getPosition())), packet.getPosition());
ChunkUtils.CACHED_BLOCK_ENTITIES.remove(packet.getPosition());
blockState), packet.getPosition());
ChunkUtils.CACHED_BLOCK_ENTITIES.remove(packet.getPosition(), blockState);
} else {
BlockEntityUtils.updateBlockEntity(session, translator.getBlockEntityTag(id, packet.getNbt(), 0), packet.getPosition());
}