Search in sources :

Example 1 with BaseSpawnerAccessor

use of org.spongepowered.common.accessor.world.level.BaseSpawnerAccessor in project SpongeCommon by SpongePowered.

the class MobSpawnerData method register.

// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
    registrator.asMutable(SpawnerBlockEntityAccessor.class).create(Keys.MAX_NEARBY_ENTITIES).get(h -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$maxNearbyEntities()).set((h, v) -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$maxNearbyEntities(v)).create(Keys.MAX_SPAWN_DELAY).get(h -> new SpongeTicks(((BaseSpawnerAccessor) h.accessor$spawner()).accessor$maxSpawnDelay())).set((h, v) -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$maxSpawnDelay((int) v.ticks())).create(Keys.MIN_SPAWN_DELAY).get(h -> new SpongeTicks(((BaseSpawnerAccessor) h.accessor$spawner()).accessor$minSpawnDelay())).set((h, v) -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$minSpawnDelay((int) v.ticks())).create(Keys.NEXT_ENTITY_TO_SPAWN).get(h -> MobSpawnerData.getNextEntity((BaseSpawnerAccessor) h.accessor$spawner())).set((h, v) -> MobSpawnerData.setNextEntity(h.accessor$spawner(), v)).create(Keys.REMAINING_SPAWN_DELAY).get(h -> new SpongeTicks(((BaseSpawnerAccessor) h.accessor$spawner()).accessor$spawnDelay())).set((h, v) -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$spawnDelay((int) v.ticks())).create(Keys.REQUIRED_PLAYER_RANGE).get(h -> (double) ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$requiredPlayerRange()).set((h, v) -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$requiredPlayerRange(v.intValue())).create(Keys.SPAWN_COUNT).get(h -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$spawnCount()).set((h, v) -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$spawnCount(v)).create(Keys.SPAWN_RANGE).get(h -> (double) ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$spawnRange()).set((h, v) -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$spawnRange(v.intValue())).create(Keys.SPAWNABLE_ENTITIES).get(h -> MobSpawnerData.getEntities(h.accessor$spawner())).set((h, v) -> {
        final BaseSpawnerAccessor logic = (BaseSpawnerAccessor) h.accessor$spawner();
        MobSpawnerData.setEntities(logic, v);
        MobSpawnerData.setNextEntity((BaseSpawner) logic, MobSpawnerData.getNextEntity(logic));
    });
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) Constants(org.spongepowered.common.util.Constants) SpawnData(net.minecraft.world.level.SpawnData) TableEntry(org.spongepowered.api.util.weighted.TableEntry) SpongeEntityArchetypeBuilder(org.spongepowered.common.entity.SpongeEntityArchetypeBuilder) WeightedSerializableObject(org.spongepowered.api.util.weighted.WeightedSerializableObject) NBTTranslator(org.spongepowered.common.data.persistence.NBTTranslator) Registry(net.minecraft.core.Registry) WeighedRandom_WeighedRandomItemAccessor(org.spongepowered.common.accessor.util.WeighedRandom_WeighedRandomItemAccessor) Keys(org.spongepowered.api.data.Keys) CompoundTag(net.minecraft.nbt.CompoundTag) EntityTypes(org.spongepowered.api.entity.EntityTypes) WeightedObject(org.spongepowered.api.util.weighted.WeightedObject) BaseSpawnerAccessor(org.spongepowered.common.accessor.world.level.BaseSpawnerAccessor) BaseSpawner(net.minecraft.world.level.BaseSpawner) DataProviderRegistrator(org.spongepowered.common.data.provider.DataProviderRegistrator) WeightedTable(org.spongepowered.api.util.weighted.WeightedTable) ResourceKey(org.spongepowered.api.ResourceKey) EntityType(org.spongepowered.api.entity.EntityType) SpongeTicks(org.spongepowered.common.util.SpongeTicks) SpawnerBlockEntityAccessor(org.spongepowered.common.accessor.world.level.block.entity.SpawnerBlockEntityAccessor) EntityArchetype(org.spongepowered.api.entity.EntityArchetype) BaseSpawnerAccessor(org.spongepowered.common.accessor.world.level.BaseSpawnerAccessor) SpawnerBlockEntityAccessor(org.spongepowered.common.accessor.world.level.block.entity.SpawnerBlockEntityAccessor) SpongeTicks(org.spongepowered.common.util.SpongeTicks)

Example 2 with BaseSpawnerAccessor

use of org.spongepowered.common.accessor.world.level.BaseSpawnerAccessor 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 SpawnData (net.minecraft.world.level.SpawnData)2 EntityArchetype (org.spongepowered.api.entity.EntityArchetype)2 WeightedTable (org.spongepowered.api.util.weighted.WeightedTable)2 WeighedRandom_WeighedRandomItemAccessor (org.spongepowered.common.accessor.util.WeighedRandom_WeighedRandomItemAccessor)2 BaseSpawnerAccessor (org.spongepowered.common.accessor.world.level.BaseSpawnerAccessor)2 Registry (net.minecraft.core.Registry)1 BaseSpawner (net.minecraft.world.level.BaseSpawner)1 ResourceKey (org.spongepowered.api.ResourceKey)1 Keys (org.spongepowered.api.data.Keys)1 EntityType (org.spongepowered.api.entity.EntityType)1 EntityTypes (org.spongepowered.api.entity.EntityTypes)1 TableEntry (org.spongepowered.api.util.weighted.TableEntry)1 WeightedObject (org.spongepowered.api.util.weighted.WeightedObject)1 WeightedSerializableObject (org.spongepowered.api.util.weighted.WeightedSerializableObject)1 SpawnerBlockEntityAccessor (org.spongepowered.common.accessor.world.level.block.entity.SpawnerBlockEntityAccessor)1 NBTTranslator (org.spongepowered.common.data.persistence.NBTTranslator)1 DataProviderRegistrator (org.spongepowered.common.data.provider.DataProviderRegistrator)1 SpongeEntityArchetypeBuilder (org.spongepowered.common.entity.SpongeEntityArchetypeBuilder)1