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