Proper trial spawner block entity data

This commit is contained in:
Camotoy 2024-06-21 15:58:23 -04:00
parent 21ccafc40c
commit e6bf3ffdf0
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
3 changed files with 16 additions and 6 deletions

View file

@ -47,6 +47,7 @@ import java.util.function.BiConsumer;
* metadata translators needed to translate the properties sent from the server. The translators are structured in such
* a way that inserting a new one (for example in version updates) is convenient.
*
* @param identifier the Bedrock identifier of this entity
* @param <T> the entity type this definition represents
*/
public record EntityDefinition<T extends Entity>(EntityFactory<T> factory, EntityType entityType, String identifier,

View file

@ -107,7 +107,7 @@ public class SpawnerBlockEntityTranslator extends BlockEntityTranslator {
bedrockNbt.put("isMovable", (byte) 1);
}
static void translateSpawnData(@NonNull NbtMapBuilder builder, @Nullable NbtMap spawnData) {
private static void translateSpawnData(@NonNull NbtMapBuilder builder, @Nullable NbtMap spawnData) {
if (spawnData == null) {
return;
}

View file

@ -27,22 +27,31 @@ package org.geysermc.geyser.translator.level.block.entity;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtMapBuilder;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.level.block.type.BlockState;
import org.geysermc.geyser.registry.Registries;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.mcprotocollib.protocol.data.game.level.block.BlockEntityType;
@BlockEntity(type = BlockEntityType.TRIAL_SPAWNER)
public class TrialSpawnerBlockEntityTranslator extends BlockEntityTranslator {
// Note that it would appear block entity updates don't include the NBT, but we do need it on chunk load.
@Override
public void translateTag(GeyserSession session, NbtMapBuilder bedrockNbt, NbtMap javaNbt, BlockState blockState) {
if (javaNbt == null) {
return;
}
// trial spawners have "spawn_data" instead of "SpawnData"
SpawnerBlockEntityTranslator.translateSpawnData(bedrockNbt, javaNbt.getCompound("spawn_data", null));
// Because trial spawners don't exist on bedrock yet
bedrockNbt.put("id", "MobSpawner");
NbtMap entityData = javaNbt.getCompound("spawn_data").getCompound("entity");
if (entityData.isEmpty()) {
return;
}
NbtMapBuilder spawnData = NbtMap.builder();
EntityDefinition<?> definition = Registries.JAVA_ENTITY_IDENTIFIERS.get(entityData.getString("id"));
if (definition != null) {
spawnData.putString("TypeId", definition.identifier());
}
spawnData.putInt("Weight", entityData.getInt("Size", 1)); // ??? presumably since these are the only other two extra attributes
bedrockNbt.putCompound("spawn_data", spawnData.build());
}
}