Skip to content

Commit e6bf3ff

Browse files
committed
Proper trial spawner block entity data
1 parent 21ccafc commit e6bf3ff

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
* metadata translators needed to translate the properties sent from the server. The translators are structured in such
4848
* a way that inserting a new one (for example in version updates) is convenient.
4949
*
50+
* @param identifier the Bedrock identifier of this entity
5051
* @param <T> the entity type this definition represents
5152
*/
5253
public record EntityDefinition<T extends Entity>(EntityFactory<T> factory, EntityType entityType, String identifier,

core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SpawnerBlockEntityTranslator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void translateTag(GeyserSession session, NbtMapBuilder bedrockNbt, NbtMap
107107
bedrockNbt.put("isMovable", (byte) 1);
108108
}
109109

110-
static void translateSpawnData(@NonNull NbtMapBuilder builder, @Nullable NbtMap spawnData) {
110+
private static void translateSpawnData(@NonNull NbtMapBuilder builder, @Nullable NbtMap spawnData) {
111111
if (spawnData == null) {
112112
return;
113113
}

core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,31 @@
2727

2828
import org.cloudburstmc.nbt.NbtMap;
2929
import org.cloudburstmc.nbt.NbtMapBuilder;
30+
import org.geysermc.geyser.entity.EntityDefinition;
3031
import org.geysermc.geyser.level.block.type.BlockState;
32+
import org.geysermc.geyser.registry.Registries;
3133
import org.geysermc.geyser.session.GeyserSession;
3234
import org.geysermc.mcprotocollib.protocol.data.game.level.block.BlockEntityType;
3335

3436
@BlockEntity(type = BlockEntityType.TRIAL_SPAWNER)
3537
public class TrialSpawnerBlockEntityTranslator extends BlockEntityTranslator {
38+
// Note that it would appear block entity updates don't include the NBT, but we do need it on chunk load.
3639
@Override
3740
public void translateTag(GeyserSession session, NbtMapBuilder bedrockNbt, NbtMap javaNbt, BlockState blockState) {
3841
if (javaNbt == null) {
3942
return;
4043
}
4144

42-
// trial spawners have "spawn_data" instead of "SpawnData"
43-
SpawnerBlockEntityTranslator.translateSpawnData(bedrockNbt, javaNbt.getCompound("spawn_data", null));
44-
45-
// Because trial spawners don't exist on bedrock yet
46-
bedrockNbt.put("id", "MobSpawner");
45+
NbtMap entityData = javaNbt.getCompound("spawn_data").getCompound("entity");
46+
if (entityData.isEmpty()) {
47+
return;
48+
}
49+
NbtMapBuilder spawnData = NbtMap.builder();
50+
EntityDefinition<?> definition = Registries.JAVA_ENTITY_IDENTIFIERS.get(entityData.getString("id"));
51+
if (definition != null) {
52+
spawnData.putString("TypeId", definition.identifier());
53+
}
54+
spawnData.putInt("Weight", entityData.getInt("Size", 1)); // ??? presumably since these are the only other two extra attributes
55+
bedrockNbt.putCompound("spawn_data", spawnData.build());
4756
}
4857
}

0 commit comments

Comments
 (0)