Merge pull request #118 from Tim203/block-entities

Be able to see Signs
This commit is contained in:
Redned 2019-12-23 12:05:16 -06:00 committed by GitHub
commit 7c5bd5b700
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 22 deletions

View file

@ -42,8 +42,7 @@ public abstract class BlockEntityTranslator {
public abstract com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(int x, int y, int z);
public com.nukkitx.nbt.tag.CompoundTag getBlockEntityTag(CompoundTag tag) {
String id = BlockEntityUtils.getBedrockBlockEntityId((String) tag.get("id").getValue());
public com.nukkitx.nbt.tag.CompoundTag getBlockEntityTag(CompoundTag tag, String id) {
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()));
@ -70,4 +69,9 @@ public abstract class BlockEntityTranslator {
.stringTag("id", id);
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;
}
}

View file

@ -42,10 +42,10 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator {
public List<Tag<?>> translateTag(CompoundTag tag) {
List<Tag<?>> tags = new ArrayList<>();
String line1 = (String) tag.getValue().get("Text1").getValue();
String line2 = (String) tag.getValue().get("Text2").getValue();
String line3 = (String) tag.getValue().get("Text3").getValue();
String line4 = (String) tag.getValue().get("Text4").getValue();
String line1 = getOrDefault(tag.getValue().get("Text1"), "");
String line2 = getOrDefault(tag.getValue().get("Text2"), "");
String line3 = getOrDefault(tag.getValue().get("Text3"), "");
String line4 = getOrDefault(tag.getValue().get("Text4"), "");
tags.add(new StringTag("Text", MessageUtils.getBedrockMessage(Message.fromString(line1))
+ "\n" + MessageUtils.getBedrockMessage(Message.fromString(line2))
@ -60,10 +60,10 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator {
@Override
public CompoundTag getDefaultJavaTag(int x, int y, int 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("Text2", "\"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("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\":\"\"}"));
tag.put(new com.github.steveice10.opennbt.tag.builtin.StringTag("Text4", "{\"text\":\"\"}"));
return tag;
}

View file

@ -45,7 +45,7 @@ public class JavaUpdateTileEntityTranslator extends PacketTranslator<ServerUpdat
String id = BlockEntityUtils.getBedrockBlockEntityId(packet.getType().name());
BlockEntityTranslator translator = BlockEntityUtils.getBlockEntityTranslator(id);
blockEntityPacket.setData(translator.getBlockEntityTag(packet.getNbt()));
blockEntityPacket.setData(translator.getBlockEntityTag(packet.getNbt(), id));
session.getUpstream().sendPacket(blockEntityPacket);
}
}

View file

@ -41,6 +41,16 @@ public class ChunkUtils {
BlockState blockState = chunk.get(x, y, z);
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),
block.getBedrockId() << 4 | block.getBedrockData());
@ -48,13 +58,6 @@ public class ChunkUtils {
section.getBlockStorageArray()[1].setFullBlock(ChunkSection.blockPosition(x, y, z),
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<>();
for (CompoundTag tag : blockEntities) {
Tag idTag = tag.get("id");
if (idTag == null) {
if (idTag == null && !tag.contains("Sign")) {
GeyserLogger.DEFAULT.debug("Got tag with no id: " + tag.getValue());
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);
bedrockBlockEntities.add(blockEntityTranslator.getBlockEntityTag(tag));
bedrockBlockEntities.add(blockEntityTranslator.getBlockEntityTag(tag, id));
}
chunkData.blockEntities = bedrockBlockEntities;

View file

@ -132,7 +132,7 @@ public class MessageUtils {
base += "r";
break;
default:
break;
return "";
}
return base;