Search in sources :

Example 1 with WeighedRandom_WeighedRandomItemAccessor

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);
}
Also used : EntityArchetype(org.spongepowered.api.entity.EntityArchetype) WeighedRandom_WeighedRandomItemAccessor(org.spongepowered.common.accessor.util.WeighedRandom_WeighedRandomItemAccessor) ResourceLocation(net.minecraft.resources.ResourceLocation) CompoundTag(net.minecraft.nbt.CompoundTag) WeightedSerializableObject(org.spongepowered.api.util.weighted.WeightedSerializableObject)

Example 2 with WeighedRandom_WeighedRandomItemAccessor

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;
}
Also used : WeightedTable(org.spongepowered.api.util.weighted.WeightedTable) EntityArchetype(org.spongepowered.api.entity.EntityArchetype) ResourceLocation(net.minecraft.resources.ResourceLocation) WeighedRandom_WeighedRandomItemAccessor(org.spongepowered.common.accessor.util.WeighedRandom_WeighedRandomItemAccessor) BaseSpawnerAccessor(org.spongepowered.common.accessor.world.level.BaseSpawnerAccessor) SpawnData(net.minecraft.world.level.SpawnData) CompoundTag(net.minecraft.nbt.CompoundTag)

Aggregations

CompoundTag (net.minecraft.nbt.CompoundTag)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 EntityArchetype (org.spongepowered.api.entity.EntityArchetype)2 WeighedRandom_WeighedRandomItemAccessor (org.spongepowered.common.accessor.util.WeighedRandom_WeighedRandomItemAccessor)2 SpawnData (net.minecraft.world.level.SpawnData)1 WeightedSerializableObject (org.spongepowered.api.util.weighted.WeightedSerializableObject)1 WeightedTable (org.spongepowered.api.util.weighted.WeightedTable)1 BaseSpawnerAccessor (org.spongepowered.common.accessor.world.level.BaseSpawnerAccessor)1