use of org.spongepowered.common.accessor.util.WeighedRandom_WeighedRandomItemAccessor in project SpongeCommon by SpongePowered.
the class MobSpawnerData method getNextEntity.
// @formatter:on
private static WeightedSerializableObject<EntityArchetype> getNextEntity(final BaseSpawnerAccessor logic) {
final int weight = ((WeighedRandom_WeighedRandomItemAccessor) logic.accessor$nextSpawnData()).accessor$weight();
final String resourceLocation = logic.accessor$nextSpawnData().getTag().getString(Constants.Entity.ENTITY_TYPE_ID);
final EntityType<?> type = Registry.ENTITY_TYPE.getOptional(new ResourceLocation(resourceLocation)).map(EntityType.class::cast).orElse(EntityTypes.PIG.get());
final CompoundTag data = logic.accessor$nextSpawnData().getTag();
final EntityArchetype archetype = SpongeEntityArchetypeBuilder.pooled().type(type).entityData(NBTTranslator.INSTANCE.translateFrom(data)).build();
return new WeightedSerializableObject<>(archetype, weight);
}
use of org.spongepowered.common.accessor.util.WeighedRandom_WeighedRandomItemAccessor in project SpongeCommon by SpongePowered.
the class MobSpawnerData method getEntities.
private static WeightedTable<EntityArchetype> getEntities(final BaseSpawner logic) {
final WeightedTable<EntityArchetype> possibleEntities = new WeightedTable<>();
for (final SpawnData weightedEntity : ((BaseSpawnerAccessor) logic).accessor$spawnPotentials()) {
final CompoundTag nbt = weightedEntity.getTag();
final String resourceLocation = nbt.getString(Constants.Entity.ENTITY_TYPE_ID);
final EntityType<?> type = Registry.ENTITY_TYPE.getOptional(new ResourceLocation(resourceLocation)).map(EntityType.class::cast).orElse(EntityTypes.PIG.get());
final EntityArchetype archetype = SpongeEntityArchetypeBuilder.pooled().type(type).entityData(NBTTranslator.INSTANCE.translateFrom(nbt)).build();
possibleEntities.add(new WeightedSerializableObject<>(archetype, ((WeighedRandom_WeighedRandomItemAccessor) weightedEntity).accessor$weight()));
}
return possibleEntities;
}
Aggregations