From 21a2c2332f56faf5564f1ff4fd01b06aec642b82 Mon Sep 17 00:00:00 2001 From: Konicai <71294714+Konicai@users.noreply.github.com> Date: Wed, 13 Dec 2023 00:48:03 -0500 Subject: [PATCH] translate trial spawners, cleanup --- .../entity/SpawnerBlockEntityTranslator.java | 40 +++++++++++-------- .../TrialSpawnerBlockEntityTranslator.java | 13 ++++-- .../java/level/JavaBlockEventTranslator.java | 9 ----- .../java/level/JavaGameEventTranslator.java | 8 ++-- gradle/libs.versions.toml | 2 +- 5 files changed, 38 insertions(+), 34 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SpawnerBlockEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SpawnerBlockEntityTranslator.java index 0aa8af279..f2b0f5a78 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SpawnerBlockEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SpawnerBlockEntityTranslator.java @@ -29,6 +29,8 @@ import com.github.steveice10.mc.protocol.data.game.level.block.BlockEntityType; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.Tag; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.nbt.NbtMapBuilder; @@ -99,24 +101,28 @@ public class SpawnerBlockEntityTranslator extends BlockEntityTranslator { builder.put("MinSpawnDelay", current.getValue()); } - CompoundTag spawnData = tag.get("SpawnData"); - if (spawnData != null) { - CompoundTag entityTag = spawnData.get("entity"); - if (entityTag.get("id") instanceof StringTag idTag) { - // As of 1.19.3, spawners can be empty - String entityId = idTag.getValue(); - builder.put("EntityIdentifier", entityId); + translateSpawnData(builder, tag.get("SpawnData")); - EntityDefinition definition = Registries.JAVA_ENTITY_IDENTIFIERS.get(entityId); - if (definition != null) { - builder.put("DisplayEntityWidth", definition.width()); - builder.put("DisplayEntityHeight", definition.height()); - builder.put("DisplayEntityScale", 1.0f); - } - } - } - - builder.put("id", "MobSpawner"); builder.put("isMovable", (byte) 1); } + + static void translateSpawnData(@NonNull NbtMapBuilder builder, @Nullable CompoundTag spawnData) { + if (spawnData == null) { + return; + } + + CompoundTag entityTag = spawnData.get("entity"); + if (entityTag.get("id") instanceof StringTag idTag) { + // As of 1.19.3, spawners can be empty + String entityId = idTag.getValue(); + builder.put("EntityIdentifier", entityId); + + EntityDefinition definition = Registries.JAVA_ENTITY_IDENTIFIERS.get(entityId); + if (definition != null) { + builder.put("DisplayEntityWidth", definition.width()); + builder.put("DisplayEntityHeight", definition.height()); + builder.put("DisplayEntityScale", 1.0f); + } + } + } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java index 93a4daba9..a6a99d868 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java @@ -30,13 +30,18 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import org.cloudburstmc.nbt.NbtMapBuilder; @BlockEntity(type = BlockEntityType.TRIAL_SPAWNER) -public class TrialSpawnerBlockEntityTranslator extends SpawnerBlockEntityTranslator { +public class TrialSpawnerBlockEntityTranslator extends BlockEntityTranslator { @Override public void translateTag(NbtMapBuilder builder, CompoundTag tag, int blockState) { - if (tag != null) { - // todo 1.20.3 doesn't seem to work - super.translateTag(builder, tag, blockState); + if (tag == null) { + return; } + + // trial spawners have "spawn_data" instead of "SpawnData" + SpawnerBlockEntityTranslator.translateSpawnData(builder, tag.get("spawn_data")); + + // Because trial spawners don't exist on bedrock yet + builder.put("id", "MobSpawner"); } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaBlockEventTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaBlockEventTranslator.java index 49c54409b..28fd2401b 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaBlockEventTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaBlockEventTranslator.java @@ -33,7 +33,6 @@ import org.cloudburstmc.nbt.NbtMapBuilder; import org.cloudburstmc.protocol.bedrock.packet.BlockEntityDataPacket; import org.cloudburstmc.protocol.bedrock.packet.BlockEventPacket; import it.unimi.dsi.fastutil.objects.Object2IntMaps; -import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.util.PlatformType; import org.geysermc.geyser.level.block.BlockStateValues; import org.geysermc.geyser.level.physics.Direction; @@ -128,14 +127,6 @@ public class JavaBlockEventTranslator extends PacketTranslator