Retrieve block entity id

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-10-21 21:25:55 +02:00
parent 5897fcb6e3
commit eb6b37f20b
3 changed files with 14 additions and 5 deletions

View File

@ -161,7 +161,7 @@ dependencies {
}
api "com.github.Minestom:DependencyGetter:v1.0.1"
implementation 'com.github.Minestom:MinestomDataGenerator:bbb3cde8fb8220b91db5d03cb34463cabaf8a88e'
implementation 'com.github.Minestom:MinestomDataGenerator:cd5fa6e35dd199f885cb23f9e49ba0092daabbc3'
// Adventure, for user-interface
api "net.kyori:adventure-api:$adventureVersion"

View File

@ -44,7 +44,7 @@ public final class ChunkData implements Writeable {
writer.writeByte((byte) ((point.blockX() & 15) << 4 | point.blockZ() & 15)); // xz
writer.writeShort((short) point.blockY()); // y
writer.writeVarInt(0); // TODO block entity id
writer.writeVarInt(registry.blockEntityId());
final NBTCompound resultNbt = new NBTCompound();

View File

@ -157,6 +157,7 @@ public final class Registry {
private final boolean solid;
private final boolean liquid;
private final String blockEntity;
private final int blockEntityId;
private final Supplier<Material> materialSupplier;
private BlockEntry(String namespace, Map<String, Object> main, Map<String, Object> override) {
@ -174,12 +175,16 @@ public final class Registry {
this.solid = getBoolean("solid");
this.liquid = getBoolean("liquid", false);
// Block entity
{
Map<String, Object> blockEntity = element("blockEntity");
if (blockEntity != null) {
this.blockEntity = (String) blockEntity.get("namespace");
final JsonElement entityElement = element("blockEntity");
if (entityElement instanceof JsonObject) {
JsonObject entityObject = (JsonObject) entityElement;
this.blockEntity = entityObject.get("namespace").getAsString();
this.blockEntityId = entityObject.get("id").getAsInt();
} else {
this.blockEntity = null;
this.blockEntityId = 0;
}
}
{
@ -244,6 +249,10 @@ public final class Registry {
return blockEntity;
}
public int blockEntityId() {
return blockEntityId;
}
public @Nullable Material material() {
return materialSupplier.get();
}