Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-04 23:30:17 +01:00
Fix chests and potentially other block entities
Dieser Commit ist enthalten in:
Ursprung
d520a5670a
Commit
e0f6c8a170
@ -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() {
|
||||
|
@ -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<Tag<?>> translateTag(CompoundTag tag) {
|
||||
List<Tag<?>> 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();
|
||||
}
|
||||
|
@ -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<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) {
|
||||
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)
|
||||
|
@ -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<Tag<?>> translateTag(CompoundTag tag) {
|
||||
List<Tag<?>> 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<>()));
|
||||
|
@ -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<Tag<?>> translateTag(CompoundTag tag) {
|
||||
List<Tag<?>> 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();
|
||||
}
|
||||
|
@ -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<Tag<?>> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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<Tag<?>> translateTag(CompoundTag tag) {
|
||||
List<Tag<?>> 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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren