From e0f6c8a1700fa0df130cc884f84e5ac91eace754 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 25 Jan 2020 23:51:29 -0600 Subject: [PATCH] Fix chests and potentially other block entities --- .../network/translators/TranslatorsInit.java | 8 ++++---- .../entity/BannerBlockEntityTranslator.java | 12 ++++-------- .../block/entity/BlockEntityTranslator.java | 16 +++++++--------- .../entity/CampfireBlockEntityTranslator.java | 12 ++++-------- .../entity/ContainerBlockEntityTranslator.java | 12 ++++-------- .../block/entity/EmptyBlockEntityTranslator.java | 12 ++++-------- .../block/entity/SignBlockEntityTranslator.java | 12 ++++-------- .../connector/utils/BlockEntityUtils.java | 4 +++- .../org/geysermc/connector/utils/ChunkUtils.java | 2 +- 9 files changed, 35 insertions(+), 55 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java b/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java index 6d5a1efaa..21b57b25b 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java @@ -176,10 +176,10 @@ public class TranslatorsInit { } private static void registerBlockEntityTranslators() { - blockEntityTranslators.put("Empty", new EmptyBlockEntityTranslator("empty", "Empty")); - blockEntityTranslators.put("Sign", new SignBlockEntityTranslator("minecraft:sign", "Sign")); - blockEntityTranslators.put("Campfire", new CampfireBlockEntityTranslator("minecraft:campfire", "Campfire")); - blockEntityTranslators.put("Banner", new BannerBlockEntityTranslator("minecraft:banner", "Banner")); + blockEntityTranslators.put("Empty", new EmptyBlockEntityTranslator()); + blockEntityTranslators.put("Sign", new SignBlockEntityTranslator()); + blockEntityTranslators.put("Campfire", new CampfireBlockEntityTranslator()); + blockEntityTranslators.put("Banner", new BannerBlockEntityTranslator()); } private static void registerInventoryTranslators() { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/BannerBlockEntityTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/BannerBlockEntityTranslator.java index 22c688432..a5ed59947 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/BannerBlockEntityTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/BannerBlockEntityTranslator.java @@ -36,10 +36,6 @@ import java.util.List; public class BannerBlockEntityTranslator extends BlockEntityTranslator { - public BannerBlockEntityTranslator(String javaId, String bedrockId) { - super(javaId, bedrockId); - } - @Override public List> translateTag(CompoundTag tag) { List> tags = new ArrayList<>(); @@ -59,15 +55,15 @@ public class BannerBlockEntityTranslator extends BlockEntityTranslator { } @Override - public CompoundTag getDefaultJavaTag(int x, int y, int z) { - CompoundTag tag = getConstantJavaTag(x, y, z); + public CompoundTag getDefaultJavaTag(String javaId, int x, int y, int z) { + CompoundTag tag = getConstantJavaTag(javaId, x, y, z); tag.put(new ListTag("Patterns")); return tag; } @Override - public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(int x, int y, int z) { - CompoundTagBuilder tagBuilder = getConstantBedrockTag(x, y, z).toBuilder(); + public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) { + CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder(); tagBuilder.listTag("Patterns", com.nukkitx.nbt.tag.CompoundTag.class, new ArrayList<>()); return tagBuilder.buildRootTag(); } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/BlockEntityTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/BlockEntityTranslator.java index e5e3a50d9..71b83d59c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/BlockEntityTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/BlockEntityTranslator.java @@ -32,32 +32,30 @@ import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.tag.Tag; import lombok.AllArgsConstructor; +import org.geysermc.connector.utils.BlockEntityUtils; import java.util.List; -@AllArgsConstructor public abstract class BlockEntityTranslator { - protected String javaId; - protected String bedrockId; - public abstract List> translateTag(CompoundTag tag); - public abstract CompoundTag getDefaultJavaTag(int x, int y, int z); + public abstract CompoundTag getDefaultJavaTag(String javaId, int x, int y, int z); - public abstract com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(int x, int y, int z); + public abstract com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z); public com.nukkitx.nbt.tag.CompoundTag getBlockEntityTag(CompoundTag tag) { int x = Integer.parseInt(String.valueOf(tag.getValue().get("x").getValue())); int y = Integer.parseInt(String.valueOf(tag.getValue().get("y").getValue())); int z = Integer.parseInt(String.valueOf(tag.getValue().get("z").getValue())); - CompoundTagBuilder tagBuilder = getConstantBedrockTag(x, y, z).toBuilder(); + CompoundTagBuilder tagBuilder = getConstantBedrockTag(BlockEntityUtils.getBedrockBlockEntityId( + String.valueOf(tag.get("id").getValue())), x, y, z).toBuilder(); translateTag(tag).forEach(tagBuilder::tag); return tagBuilder.buildRootTag(); } - protected CompoundTag getConstantJavaTag(int x, int y, int z) { + protected CompoundTag getConstantJavaTag(String javaId, int x, int y, int z) { CompoundTag tag = new CompoundTag(""); tag.put(new IntTag("x", x)); tag.put(new IntTag("y", y)); @@ -66,7 +64,7 @@ public abstract class BlockEntityTranslator { return tag; } - protected com.nukkitx.nbt.tag.CompoundTag getConstantBedrockTag(int x, int y, int z) { + protected com.nukkitx.nbt.tag.CompoundTag getConstantBedrockTag(String bedrockId, int x, int y, int z) { CompoundTagBuilder tagBuilder = CompoundTagBuilder.builder() .intTag("x", x) .intTag("y", y) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/CampfireBlockEntityTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/CampfireBlockEntityTranslator.java index ee1c12753..b40626dcf 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/CampfireBlockEntityTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/CampfireBlockEntityTranslator.java @@ -39,10 +39,6 @@ import java.util.List; public class CampfireBlockEntityTranslator extends BlockEntityTranslator { - public CampfireBlockEntityTranslator(String javaId, String bedrockId) { - super(javaId, bedrockId); - } - @Override public List> translateTag(CompoundTag tag) { List> tags = new ArrayList<>(); @@ -56,15 +52,15 @@ public class CampfireBlockEntityTranslator extends BlockEntityTranslator { } @Override - public CompoundTag getDefaultJavaTag(int x, int y, int z) { - CompoundTag tag = getConstantJavaTag(x, y, z); + public CompoundTag getDefaultJavaTag(String javaId, int x, int y, int z) { + CompoundTag tag = getConstantJavaTag(javaId, x, y, z); tag.put(new ListTag("Items")); return tag; } @Override - public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(int x, int y, int z) { - CompoundTagBuilder tagBuilder = getConstantBedrockTag(x, y, z).toBuilder(); + public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) { + CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder(); tagBuilder.tag(new com.nukkitx.nbt.tag.CompoundTag("Item1", new HashMap<>())); tagBuilder.tag(new com.nukkitx.nbt.tag.CompoundTag("Item2", new HashMap<>())); tagBuilder.tag(new com.nukkitx.nbt.tag.CompoundTag("Item3", new HashMap<>())); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/ContainerBlockEntityTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/ContainerBlockEntityTranslator.java index 78566d608..123290dbe 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/ContainerBlockEntityTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/ContainerBlockEntityTranslator.java @@ -38,10 +38,6 @@ import java.util.List; public class ContainerBlockEntityTranslator extends BlockEntityTranslator { - public ContainerBlockEntityTranslator(String javaId, String bedrockId) { - super(javaId, bedrockId); - } - @Override public List> translateTag(CompoundTag tag) { List> tags = new ArrayList<>(); @@ -58,15 +54,15 @@ public class ContainerBlockEntityTranslator extends BlockEntityTranslator { } @Override - public CompoundTag getDefaultJavaTag(int x, int y, int z) { - CompoundTag tag = getConstantJavaTag(x, y, z); + public CompoundTag getDefaultJavaTag(String javaId, int x, int y, int z) { + CompoundTag tag = getConstantJavaTag(javaId, x, y, z); tag.put(new ListTag("Items")); return tag; } @Override - public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(int x, int y, int z) { - CompoundTagBuilder tagBuilder = getConstantBedrockTag(x, y, z).toBuilder(); + public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) { + CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder(); tagBuilder.listTag("Items", com.nukkitx.nbt.tag.CompoundTag.class, new ArrayList<>()); return tagBuilder.buildRootTag(); } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/EmptyBlockEntityTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/EmptyBlockEntityTranslator.java index 700b50dbc..16bc4d7a1 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/EmptyBlockEntityTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/EmptyBlockEntityTranslator.java @@ -33,22 +33,18 @@ import java.util.List; public class EmptyBlockEntityTranslator extends BlockEntityTranslator { - public EmptyBlockEntityTranslator(String javaId, String bedrockId) { - super(javaId, bedrockId); - } - @Override public List> translateTag(CompoundTag tag) { return new ArrayList<>(); } @Override - public CompoundTag getDefaultJavaTag(int x, int y, int z) { - return getConstantJavaTag(x, y, z); + public CompoundTag getDefaultJavaTag(String javaId, int x, int y, int z) { + return getConstantJavaTag(javaId, x, y, z); } @Override - public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(int x, int y, int z) { - return getConstantBedrockTag(x, y, z); + public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) { + return getConstantBedrockTag(bedrockId, x, y, z); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/SignBlockEntityTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/SignBlockEntityTranslator.java index 7029143bb..3d9a4a7af 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/SignBlockEntityTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/block/entity/SignBlockEntityTranslator.java @@ -38,10 +38,6 @@ import java.util.List; public class SignBlockEntityTranslator extends BlockEntityTranslator { - public SignBlockEntityTranslator(String javaId, String bedrockId) { - super(javaId, bedrockId); - } - @Override public List> translateTag(CompoundTag tag) { List> tags = new ArrayList<>(); @@ -61,8 +57,8 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator { } @Override - public CompoundTag getDefaultJavaTag(int x, int y, int z) { - CompoundTag tag = getConstantJavaTag(x, y, z); + public CompoundTag getDefaultJavaTag(String javaId, int x, int y, int z) { + CompoundTag tag = getConstantJavaTag(javaId, x, y, z); tag.put(new com.github.steveice10.opennbt.tag.builtin.StringTag("Text1", "{\"text\":\"\"}")); tag.put(new com.github.steveice10.opennbt.tag.builtin.StringTag("Text2", "{\"text\":\"\"}")); tag.put(new com.github.steveice10.opennbt.tag.builtin.StringTag("Text3", "{\"text\":\"\"}")); @@ -71,8 +67,8 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator { } @Override - public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(int x, int y, int z) { - CompoundTagBuilder tagBuilder = getConstantBedrockTag(x, y, z).toBuilder(); + public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) { + CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder(); tagBuilder.stringTag("Text", ""); return tagBuilder.buildRootTag(); } diff --git a/connector/src/main/java/org/geysermc/connector/utils/BlockEntityUtils.java b/connector/src/main/java/org/geysermc/connector/utils/BlockEntityUtils.java index f610f2717..58eadb1b2 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/BlockEntityUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/BlockEntityUtils.java @@ -10,6 +10,8 @@ import org.geysermc.connector.network.translators.block.entity.BlockEntityTransl public class BlockEntityUtils { + private static final BlockEntityTranslator EMPTY_TRANSLATOR = TranslatorsInit.getBlockEntityTranslators().get("Empty"); + public static String getBedrockBlockEntityId(String id) { // This is the only exception when it comes to block entity ids if (id.contains("piston_head")) @@ -30,7 +32,7 @@ public class BlockEntityUtils { public static BlockEntityTranslator getBlockEntityTranslator(String name) { BlockEntityTranslator blockEntityTranslator = TranslatorsInit.getBlockEntityTranslators().get(name); if (blockEntityTranslator == null) { - return TranslatorsInit.getBlockEntityTranslators().get("Empty"); + return EMPTY_TRANSLATOR; } return blockEntityTranslator; diff --git a/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java b/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java index fba9e7883..4e0b68261 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java @@ -69,7 +69,7 @@ public class ChunkUtils { BlockEntry block = TranslatorsInit.getBlockTranslator().getBlockEntry(blockState); if (block.getJavaIdentifier().contains("sign[")) { Position pos = new ChunkPosition(column.getX(), column.getZ()).getBlock(x, (chunkY << 4) + y, z); - chunkData.signs.put(block.getJavaId(), TranslatorsInit.getBlockEntityTranslators().get("Sign").getDefaultBedrockTag(pos.getX(), pos.getY(), pos.getZ())); + chunkData.signs.put(block.getJavaId(), TranslatorsInit.getBlockEntityTranslators().get("Sign").getDefaultBedrockTag("Sign", pos.getX(), pos.getY(), pos.getZ())); } else { section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z), block.getBedrockRuntimeId()); }