mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-12-04 14:04:53 +01:00
Merge pull request #118 from Tim203/block-entities
Be able to see Signs
This commit is contained in:
commit
7c5bd5b700
5 changed files with 29 additions and 22 deletions
|
@ -42,8 +42,7 @@ public abstract class BlockEntityTranslator {
|
||||||
|
|
||||||
public abstract com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(int x, int y, int z);
|
public abstract com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(int x, int y, int z);
|
||||||
|
|
||||||
public com.nukkitx.nbt.tag.CompoundTag getBlockEntityTag(CompoundTag tag) {
|
public com.nukkitx.nbt.tag.CompoundTag getBlockEntityTag(CompoundTag tag, String id) {
|
||||||
String id = BlockEntityUtils.getBedrockBlockEntityId((String) tag.get("id").getValue());
|
|
||||||
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()));
|
||||||
|
@ -70,4 +69,9 @@ public abstract class BlockEntityTranslator {
|
||||||
.stringTag("id", id);
|
.stringTag("id", id);
|
||||||
return tagBuilder.buildRootTag();
|
return tagBuilder.buildRootTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
protected <T> T getOrDefault(com.github.steveice10.opennbt.tag.builtin.Tag tag, T defaultValue) {
|
||||||
|
return (tag != null && tag.getValue() != null) ? (T) tag.getValue() : defaultValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,10 +42,10 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator {
|
||||||
public List<Tag<?>> translateTag(CompoundTag tag) {
|
public List<Tag<?>> translateTag(CompoundTag tag) {
|
||||||
List<Tag<?>> tags = new ArrayList<>();
|
List<Tag<?>> tags = new ArrayList<>();
|
||||||
|
|
||||||
String line1 = (String) tag.getValue().get("Text1").getValue();
|
String line1 = getOrDefault(tag.getValue().get("Text1"), "");
|
||||||
String line2 = (String) tag.getValue().get("Text2").getValue();
|
String line2 = getOrDefault(tag.getValue().get("Text2"), "");
|
||||||
String line3 = (String) tag.getValue().get("Text3").getValue();
|
String line3 = getOrDefault(tag.getValue().get("Text3"), "");
|
||||||
String line4 = (String) tag.getValue().get("Text4").getValue();
|
String line4 = getOrDefault(tag.getValue().get("Text4"), "");
|
||||||
|
|
||||||
tags.add(new StringTag("Text", MessageUtils.getBedrockMessage(Message.fromString(line1))
|
tags.add(new StringTag("Text", MessageUtils.getBedrockMessage(Message.fromString(line1))
|
||||||
+ "\n" + MessageUtils.getBedrockMessage(Message.fromString(line2))
|
+ "\n" + MessageUtils.getBedrockMessage(Message.fromString(line2))
|
||||||
|
@ -60,10 +60,10 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator {
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag getDefaultJavaTag(int x, int y, int z) {
|
public CompoundTag getDefaultJavaTag(int x, int y, int z) {
|
||||||
CompoundTag tag = getConstantJavaTag("minecraft:sign", x, y, z);
|
CompoundTag tag = getConstantJavaTag("minecraft:sign", 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\":\"\"}"));
|
||||||
tag.put(new com.github.steveice10.opennbt.tag.builtin.StringTag("Text4", "\"text\":\"\""));
|
tag.put(new com.github.steveice10.opennbt.tag.builtin.StringTag("Text4", "{\"text\":\"\"}"));
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class JavaUpdateTileEntityTranslator extends PacketTranslator<ServerUpdat
|
||||||
|
|
||||||
String id = BlockEntityUtils.getBedrockBlockEntityId(packet.getType().name());
|
String id = BlockEntityUtils.getBedrockBlockEntityId(packet.getType().name());
|
||||||
BlockEntityTranslator translator = BlockEntityUtils.getBlockEntityTranslator(id);
|
BlockEntityTranslator translator = BlockEntityUtils.getBlockEntityTranslator(id);
|
||||||
blockEntityPacket.setData(translator.getBlockEntityTag(packet.getNbt()));
|
blockEntityPacket.setData(translator.getBlockEntityTag(packet.getNbt(), id));
|
||||||
session.getUpstream().sendPacket(blockEntityPacket);
|
session.getUpstream().sendPacket(blockEntityPacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,16 @@ public class ChunkUtils {
|
||||||
BlockState blockState = chunk.get(x, y, z);
|
BlockState blockState = chunk.get(x, y, z);
|
||||||
BlockEntry block = TranslatorsInit.getBlockTranslator().getBedrockBlock(blockState);
|
BlockEntry block = TranslatorsInit.getBlockTranslator().getBedrockBlock(blockState);
|
||||||
|
|
||||||
|
// Block entity data for signs is not sent in this packet, which is needed
|
||||||
|
// for bedrock, so we need to check the block itself
|
||||||
|
// if (block.getJavaIdentifier().contains("sign")) {
|
||||||
|
//// SignBlockEntityTranslator sign = (SignBlockEntityTranslator) BlockEntityUtils.getBlockEntityTranslator("Sign");
|
||||||
|
//// blockEntities.add(sign.getDefaultJavaTag(x, y, z));
|
||||||
|
// section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z), 0);
|
||||||
|
//// System.out.println("Found sign at " + x + " " + y + " " + z);
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z),
|
section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z),
|
||||||
block.getBedrockId() << 4 | block.getBedrockData());
|
block.getBedrockId() << 4 | block.getBedrockData());
|
||||||
|
|
||||||
|
@ -48,13 +58,6 @@ public class ChunkUtils {
|
||||||
section.getBlockStorageArray()[1].setFullBlock(ChunkSection.blockPosition(x, y, z),
|
section.getBlockStorageArray()[1].setFullBlock(ChunkSection.blockPosition(x, y, z),
|
||||||
9 << 4); // water id
|
9 << 4); // water id
|
||||||
}
|
}
|
||||||
|
|
||||||
// Block entity data for signs is not sent in this packet, which is needed
|
|
||||||
// for bedrock, so we need to check the block itself
|
|
||||||
if (block.getJavaIdentifier().contains("sign")) {
|
|
||||||
SignBlockEntityTranslator sign = (SignBlockEntityTranslator) BlockEntityUtils.getBlockEntityTranslator("Sign");
|
|
||||||
blockEntities.add(sign.getDefaultJavaTag(x, y, z));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,14 +66,14 @@ public class ChunkUtils {
|
||||||
List<com.nukkitx.nbt.tag.CompoundTag> bedrockBlockEntities = new ArrayList<>();
|
List<com.nukkitx.nbt.tag.CompoundTag> bedrockBlockEntities = new ArrayList<>();
|
||||||
for (CompoundTag tag : blockEntities) {
|
for (CompoundTag tag : blockEntities) {
|
||||||
Tag idTag = tag.get("id");
|
Tag idTag = tag.get("id");
|
||||||
if (idTag == null) {
|
if (idTag == null && !tag.contains("Sign")) {
|
||||||
GeyserLogger.DEFAULT.debug("Got tag with no id: " + tag.getValue());
|
GeyserLogger.DEFAULT.debug("Got tag with no id: " + tag.getValue());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String id = BlockEntityUtils.getBedrockBlockEntityId((String) tag.get("id").getValue());
|
String id = idTag == null ? "Sign" : BlockEntityUtils.getBedrockBlockEntityId((String) idTag.getValue());
|
||||||
BlockEntityTranslator blockEntityTranslator = BlockEntityUtils.getBlockEntityTranslator(id);
|
BlockEntityTranslator blockEntityTranslator = BlockEntityUtils.getBlockEntityTranslator(id);
|
||||||
bedrockBlockEntities.add(blockEntityTranslator.getBlockEntityTag(tag));
|
bedrockBlockEntities.add(blockEntityTranslator.getBlockEntityTag(tag, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
chunkData.blockEntities = bedrockBlockEntities;
|
chunkData.blockEntities = bedrockBlockEntities;
|
||||||
|
|
|
@ -132,7 +132,7 @@ public class MessageUtils {
|
||||||
base += "r";
|
base += "r";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return base;
|
return base;
|
||||||
|
|
Loading…
Reference in a new issue