mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Fix chests and potentially other block entities
This commit is contained in:
parent
d520a5670a
commit
e0f6c8a170
9 changed files with 35 additions and 55 deletions
|
@ -176,10 +176,10 @@ public class TranslatorsInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerBlockEntityTranslators() {
|
private static void registerBlockEntityTranslators() {
|
||||||
blockEntityTranslators.put("Empty", new EmptyBlockEntityTranslator("empty", "Empty"));
|
blockEntityTranslators.put("Empty", new EmptyBlockEntityTranslator());
|
||||||
blockEntityTranslators.put("Sign", new SignBlockEntityTranslator("minecraft:sign", "Sign"));
|
blockEntityTranslators.put("Sign", new SignBlockEntityTranslator());
|
||||||
blockEntityTranslators.put("Campfire", new CampfireBlockEntityTranslator("minecraft:campfire", "Campfire"));
|
blockEntityTranslators.put("Campfire", new CampfireBlockEntityTranslator());
|
||||||
blockEntityTranslators.put("Banner", new BannerBlockEntityTranslator("minecraft:banner", "Banner"));
|
blockEntityTranslators.put("Banner", new BannerBlockEntityTranslator());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerInventoryTranslators() {
|
private static void registerInventoryTranslators() {
|
||||||
|
|
|
@ -36,10 +36,6 @@ import java.util.List;
|
||||||
|
|
||||||
public class BannerBlockEntityTranslator extends BlockEntityTranslator {
|
public class BannerBlockEntityTranslator extends BlockEntityTranslator {
|
||||||
|
|
||||||
public BannerBlockEntityTranslator(String javaId, String bedrockId) {
|
|
||||||
super(javaId, bedrockId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Tag<?>> translateTag(CompoundTag tag) {
|
public List<Tag<?>> translateTag(CompoundTag tag) {
|
||||||
List<Tag<?>> tags = new ArrayList<>();
|
List<Tag<?>> tags = new ArrayList<>();
|
||||||
|
@ -59,15 +55,15 @@ public class BannerBlockEntityTranslator extends BlockEntityTranslator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag getDefaultJavaTag(int x, int y, int z) {
|
public CompoundTag getDefaultJavaTag(String javaId, int x, int y, int z) {
|
||||||
CompoundTag tag = getConstantJavaTag(x, y, z);
|
CompoundTag tag = getConstantJavaTag(javaId, x, y, z);
|
||||||
tag.put(new ListTag("Patterns"));
|
tag.put(new ListTag("Patterns"));
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(int x, int y, int z) {
|
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||||
CompoundTagBuilder tagBuilder = getConstantBedrockTag(x, y, z).toBuilder();
|
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
|
||||||
tagBuilder.listTag("Patterns", com.nukkitx.nbt.tag.CompoundTag.class, new ArrayList<>());
|
tagBuilder.listTag("Patterns", com.nukkitx.nbt.tag.CompoundTag.class, new ArrayList<>());
|
||||||
return tagBuilder.buildRootTag();
|
return tagBuilder.buildRootTag();
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,32 +32,30 @@ import com.nukkitx.nbt.CompoundTagBuilder;
|
||||||
import com.nukkitx.nbt.tag.Tag;
|
import com.nukkitx.nbt.tag.Tag;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.geysermc.connector.utils.BlockEntityUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
public abstract class BlockEntityTranslator {
|
public abstract class BlockEntityTranslator {
|
||||||
|
|
||||||
protected String javaId;
|
|
||||||
protected String bedrockId;
|
|
||||||
|
|
||||||
public abstract List<Tag<?>> translateTag(CompoundTag tag);
|
public abstract List<Tag<?>> 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) {
|
public com.nukkitx.nbt.tag.CompoundTag getBlockEntityTag(CompoundTag tag) {
|
||||||
int x = Integer.parseInt(String.valueOf(tag.getValue().get("x").getValue()));
|
int x = Integer.parseInt(String.valueOf(tag.getValue().get("x").getValue()));
|
||||||
int y = Integer.parseInt(String.valueOf(tag.getValue().get("y").getValue()));
|
int y = Integer.parseInt(String.valueOf(tag.getValue().get("y").getValue()));
|
||||||
int z = Integer.parseInt(String.valueOf(tag.getValue().get("z").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);
|
translateTag(tag).forEach(tagBuilder::tag);
|
||||||
return tagBuilder.buildRootTag();
|
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("");
|
CompoundTag tag = new CompoundTag("");
|
||||||
tag.put(new IntTag("x", x));
|
tag.put(new IntTag("x", x));
|
||||||
tag.put(new IntTag("y", y));
|
tag.put(new IntTag("y", y));
|
||||||
|
@ -66,7 +64,7 @@ public abstract class BlockEntityTranslator {
|
||||||
return tag;
|
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()
|
CompoundTagBuilder tagBuilder = CompoundTagBuilder.builder()
|
||||||
.intTag("x", x)
|
.intTag("x", x)
|
||||||
.intTag("y", y)
|
.intTag("y", y)
|
||||||
|
|
|
@ -39,10 +39,6 @@ import java.util.List;
|
||||||
|
|
||||||
public class CampfireBlockEntityTranslator extends BlockEntityTranslator {
|
public class CampfireBlockEntityTranslator extends BlockEntityTranslator {
|
||||||
|
|
||||||
public CampfireBlockEntityTranslator(String javaId, String bedrockId) {
|
|
||||||
super(javaId, bedrockId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Tag<?>> translateTag(CompoundTag tag) {
|
public List<Tag<?>> translateTag(CompoundTag tag) {
|
||||||
List<Tag<?>> tags = new ArrayList<>();
|
List<Tag<?>> tags = new ArrayList<>();
|
||||||
|
@ -56,15 +52,15 @@ public class CampfireBlockEntityTranslator extends BlockEntityTranslator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag getDefaultJavaTag(int x, int y, int z) {
|
public CompoundTag getDefaultJavaTag(String javaId, int x, int y, int z) {
|
||||||
CompoundTag tag = getConstantJavaTag(x, y, z);
|
CompoundTag tag = getConstantJavaTag(javaId, x, y, z);
|
||||||
tag.put(new ListTag("Items"));
|
tag.put(new ListTag("Items"));
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(int x, int y, int z) {
|
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||||
CompoundTagBuilder tagBuilder = getConstantBedrockTag(x, y, z).toBuilder();
|
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("Item1", new HashMap<>()));
|
||||||
tagBuilder.tag(new com.nukkitx.nbt.tag.CompoundTag("Item2", new HashMap<>()));
|
tagBuilder.tag(new com.nukkitx.nbt.tag.CompoundTag("Item2", new HashMap<>()));
|
||||||
tagBuilder.tag(new com.nukkitx.nbt.tag.CompoundTag("Item3", new HashMap<>()));
|
tagBuilder.tag(new com.nukkitx.nbt.tag.CompoundTag("Item3", new HashMap<>()));
|
||||||
|
|
|
@ -38,10 +38,6 @@ import java.util.List;
|
||||||
|
|
||||||
public class ContainerBlockEntityTranslator extends BlockEntityTranslator {
|
public class ContainerBlockEntityTranslator extends BlockEntityTranslator {
|
||||||
|
|
||||||
public ContainerBlockEntityTranslator(String javaId, String bedrockId) {
|
|
||||||
super(javaId, bedrockId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Tag<?>> translateTag(CompoundTag tag) {
|
public List<Tag<?>> translateTag(CompoundTag tag) {
|
||||||
List<Tag<?>> tags = new ArrayList<>();
|
List<Tag<?>> tags = new ArrayList<>();
|
||||||
|
@ -58,15 +54,15 @@ public class ContainerBlockEntityTranslator extends BlockEntityTranslator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag getDefaultJavaTag(int x, int y, int z) {
|
public CompoundTag getDefaultJavaTag(String javaId, int x, int y, int z) {
|
||||||
CompoundTag tag = getConstantJavaTag(x, y, z);
|
CompoundTag tag = getConstantJavaTag(javaId, x, y, z);
|
||||||
tag.put(new ListTag("Items"));
|
tag.put(new ListTag("Items"));
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(int x, int y, int z) {
|
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||||
CompoundTagBuilder tagBuilder = getConstantBedrockTag(x, y, z).toBuilder();
|
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
|
||||||
tagBuilder.listTag("Items", com.nukkitx.nbt.tag.CompoundTag.class, new ArrayList<>());
|
tagBuilder.listTag("Items", com.nukkitx.nbt.tag.CompoundTag.class, new ArrayList<>());
|
||||||
return tagBuilder.buildRootTag();
|
return tagBuilder.buildRootTag();
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,22 +33,18 @@ import java.util.List;
|
||||||
|
|
||||||
public class EmptyBlockEntityTranslator extends BlockEntityTranslator {
|
public class EmptyBlockEntityTranslator extends BlockEntityTranslator {
|
||||||
|
|
||||||
public EmptyBlockEntityTranslator(String javaId, String bedrockId) {
|
|
||||||
super(javaId, bedrockId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Tag<?>> translateTag(CompoundTag tag) {
|
public List<Tag<?>> translateTag(CompoundTag tag) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag getDefaultJavaTag(int x, int y, int z) {
|
public CompoundTag getDefaultJavaTag(String javaId, int x, int y, int z) {
|
||||||
return getConstantJavaTag(x, y, z);
|
return getConstantJavaTag(javaId, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(int x, int y, int z) {
|
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||||
return getConstantBedrockTag(x, y, z);
|
return getConstantBedrockTag(bedrockId, x, y, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,10 +38,6 @@ import java.util.List;
|
||||||
|
|
||||||
public class SignBlockEntityTranslator extends BlockEntityTranslator {
|
public class SignBlockEntityTranslator extends BlockEntityTranslator {
|
||||||
|
|
||||||
public SignBlockEntityTranslator(String javaId, String bedrockId) {
|
|
||||||
super(javaId, bedrockId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Tag<?>> translateTag(CompoundTag tag) {
|
public List<Tag<?>> translateTag(CompoundTag tag) {
|
||||||
List<Tag<?>> tags = new ArrayList<>();
|
List<Tag<?>> tags = new ArrayList<>();
|
||||||
|
@ -61,8 +57,8 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag getDefaultJavaTag(int x, int y, int z) {
|
public CompoundTag getDefaultJavaTag(String javaId, int x, int y, int z) {
|
||||||
CompoundTag tag = getConstantJavaTag(x, y, 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("Text1", "{\"text\":\"\"}"));
|
||||||
tag.put(new com.github.steveice10.opennbt.tag.builtin.StringTag("Text2", "{\"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\":\"\"}"));
|
tag.put(new com.github.steveice10.opennbt.tag.builtin.StringTag("Text3", "{\"text\":\"\"}"));
|
||||||
|
@ -71,8 +67,8 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(int x, int y, int z) {
|
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||||
CompoundTagBuilder tagBuilder = getConstantBedrockTag(x, y, z).toBuilder();
|
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
|
||||||
tagBuilder.stringTag("Text", "");
|
tagBuilder.stringTag("Text", "");
|
||||||
return tagBuilder.buildRootTag();
|
return tagBuilder.buildRootTag();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@ import org.geysermc.connector.network.translators.block.entity.BlockEntityTransl
|
||||||
|
|
||||||
public class BlockEntityUtils {
|
public class BlockEntityUtils {
|
||||||
|
|
||||||
|
private static final BlockEntityTranslator EMPTY_TRANSLATOR = TranslatorsInit.getBlockEntityTranslators().get("Empty");
|
||||||
|
|
||||||
public static String getBedrockBlockEntityId(String id) {
|
public static String getBedrockBlockEntityId(String id) {
|
||||||
// This is the only exception when it comes to block entity ids
|
// This is the only exception when it comes to block entity ids
|
||||||
if (id.contains("piston_head"))
|
if (id.contains("piston_head"))
|
||||||
|
@ -30,7 +32,7 @@ public class BlockEntityUtils {
|
||||||
public static BlockEntityTranslator getBlockEntityTranslator(String name) {
|
public static BlockEntityTranslator getBlockEntityTranslator(String name) {
|
||||||
BlockEntityTranslator blockEntityTranslator = TranslatorsInit.getBlockEntityTranslators().get(name);
|
BlockEntityTranslator blockEntityTranslator = TranslatorsInit.getBlockEntityTranslators().get(name);
|
||||||
if (blockEntityTranslator == null) {
|
if (blockEntityTranslator == null) {
|
||||||
return TranslatorsInit.getBlockEntityTranslators().get("Empty");
|
return EMPTY_TRANSLATOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return blockEntityTranslator;
|
return blockEntityTranslator;
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class ChunkUtils {
|
||||||
BlockEntry block = TranslatorsInit.getBlockTranslator().getBlockEntry(blockState);
|
BlockEntry block = TranslatorsInit.getBlockTranslator().getBlockEntry(blockState);
|
||||||
if (block.getJavaIdentifier().contains("sign[")) {
|
if (block.getJavaIdentifier().contains("sign[")) {
|
||||||
Position pos = new ChunkPosition(column.getX(), column.getZ()).getBlock(x, (chunkY << 4) + y, z);
|
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 {
|
} else {
|
||||||
section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z), block.getBedrockRuntimeId());
|
section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z), block.getBedrockRuntimeId());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue