Skip to content

Commit

Permalink
Proper trial spawner block entity data
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Jun 21, 2024
1 parent 21ccafc commit e6bf3ff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
* 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void translateTag(GeyserSession session, NbtMapBuilder bedrockNbt, NbtMap
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,31 @@

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());
}
}

0 comments on commit e6bf3ff

Please sign in to comment.