|
27 | 27 |
|
28 | 28 | import org.cloudburstmc.nbt.NbtMap; |
29 | 29 | import org.cloudburstmc.nbt.NbtMapBuilder; |
| 30 | +import org.geysermc.geyser.entity.EntityDefinition; |
30 | 31 | import org.geysermc.geyser.level.block.type.BlockState; |
| 32 | +import org.geysermc.geyser.registry.Registries; |
31 | 33 | import org.geysermc.geyser.session.GeyserSession; |
32 | 34 | import org.geysermc.mcprotocollib.protocol.data.game.level.block.BlockEntityType; |
33 | 35 |
|
34 | 36 | @BlockEntity(type = BlockEntityType.TRIAL_SPAWNER) |
35 | 37 | 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. |
36 | 39 | @Override |
37 | 40 | public void translateTag(GeyserSession session, NbtMapBuilder bedrockNbt, NbtMap javaNbt, BlockState blockState) { |
38 | 41 | if (javaNbt == null) { |
39 | 42 | return; |
40 | 43 | } |
41 | 44 |
|
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()); |
47 | 56 | } |
48 | 57 | } |
0 commit comments