Search in sources :

Example 1 with WeightedSpawnerEntity

use of net.minecraft.util.WeightedSpawnerEntity in project SpongeCommon by SpongePowered.

the class SpawnerUtils method setNextEntity.

@SuppressWarnings("unchecked")
public static void setNextEntity(MobSpawnerBaseLogic logic, WeightedSerializableObject<EntityArchetype> value) {
    NBTTagCompound compound = NbtTranslator.getInstance().translateData(value.get().getEntityData());
    if (!compound.hasKey(NbtDataUtil.ENTITY_TYPE_ID)) {
        final ResourceLocation key = EntityList.getKey((Class<? extends Entity>) value.get().getType().getEntityClass());
        compound.setString(NbtDataUtil.ENTITY_TYPE_ID, key != null ? key.toString() : "");
    }
    logic.setNextSpawnData(new WeightedSpawnerEntity((int) value.getWeight(), compound));
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WeightedSpawnerEntity(net.minecraft.util.WeightedSpawnerEntity)

Example 2 with WeightedSpawnerEntity

use of net.minecraft.util.WeightedSpawnerEntity in project Minestuck by mraof.

the class StructureBlockUtil method placeSpawner.

public static boolean placeSpawner(BlockPos pos, World world, StructureBoundingBox bb, String entityName) {
    WeightedSpawnerEntity entity = new WeightedSpawnerEntity();
    entity.getNbt().setString("id", entityName);
    entity.getNbt().setBoolean("spawned", true);
    return placeSpawner(pos, world, bb, entity);
}
Also used : WeightedSpawnerEntity(net.minecraft.util.WeightedSpawnerEntity)

Example 3 with WeightedSpawnerEntity

use of net.minecraft.util.WeightedSpawnerEntity in project SpongeCommon by SpongePowered.

the class SpawnerUtils method getEntities.

public static WeightedTable<EntityArchetype> getEntities(MobSpawnerBaseLogic logic) {
    WeightedTable<EntityArchetype> possibleEntities = new WeightedTable<>();
    for (WeightedSpawnerEntity weightedEntity : logic.potentialSpawns) {
        NBTTagCompound nbt = weightedEntity.getNbt();
        EntityType type = EntityUtil.fromNameToType(nbt.getString(NbtDataUtil.ENTITY_TYPE_ID)).orElse(EntityTypes.PIG);
        EntityArchetype archetype = EntityArchetype.builder().type(type).entityData(NbtTranslator.getInstance().translateFrom(nbt)).build();
        possibleEntities.add(new WeightedSerializableObject<>(archetype, weightedEntity.itemWeight));
    }
    return possibleEntities;
}
Also used : EntityType(org.spongepowered.api.entity.EntityType) WeightedTable(org.spongepowered.api.util.weighted.WeightedTable) EntityArchetype(org.spongepowered.api.entity.EntityArchetype) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WeightedSpawnerEntity(net.minecraft.util.WeightedSpawnerEntity)

Example 4 with WeightedSpawnerEntity

use of net.minecraft.util.WeightedSpawnerEntity in project SpongeCommon by SpongePowered.

the class SpawnerUtils method setEntities.

@SuppressWarnings("unchecked")
public static void setEntities(MobSpawnerBaseLogic logic, WeightedTable<EntityArchetype> table) {
    logic.potentialSpawns.clear();
    for (TableEntry<EntityArchetype> entry : table) {
        if (!(entry instanceof WeightedObject)) {
            continue;
        }
        WeightedObject<EntityArchetype> object = (WeightedObject<EntityArchetype>) entry;
        NBTTagCompound compound = NbtTranslator.getInstance().translateData(object.get().getEntityData());
        if (!compound.hasKey(NbtDataUtil.ENTITY_TYPE_ID)) {
            final ResourceLocation key = EntityList.getKey((Class<? extends Entity>) object.get().getType().getEntityClass());
            compound.setString(NbtDataUtil.ENTITY_TYPE_ID, key != null ? key.toString() : "");
        }
        logic.potentialSpawns.add(new WeightedSpawnerEntity((int) entry.getWeight(), compound));
    }
}
Also used : WeightedObject(org.spongepowered.api.util.weighted.WeightedObject) EntityArchetype(org.spongepowered.api.entity.EntityArchetype) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WeightedSpawnerEntity(net.minecraft.util.WeightedSpawnerEntity)

Aggregations

WeightedSpawnerEntity (net.minecraft.util.WeightedSpawnerEntity)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 ResourceLocation (net.minecraft.util.ResourceLocation)2 EntityArchetype (org.spongepowered.api.entity.EntityArchetype)2 EntityType (org.spongepowered.api.entity.EntityType)1 WeightedObject (org.spongepowered.api.util.weighted.WeightedObject)1 WeightedTable (org.spongepowered.api.util.weighted.WeightedTable)1