use of net.minecraft.world.biome.Biome.SpawnListEntry in project BiomeTweaker by superckl.
the class ScriptCommandCreateBiome method perform.
@Override
public void perform() throws Exception {
if (RegistryEventHandler.registry == null)
throw new IllegalStateException("No biome registry avilable! Make sure you're using the biome registry script stage!");
if (this.toCopy == null) {
final BiomeTweakerBiome biome = new BiomeTweakerBiome(new BiomeProperties("BiomeTweaker Biome").setBaseHeight(0.125F).setHeightVariation(0.05F).setTemperature(0.8F).setRainfall(0.4F));
if (!MinecraftForge.EVENT_BUS.post(new BiomeTweakEvent.Create(this, biome))) {
biome.setRegistryName(ModData.MOD_ID, this.rLoc.toLowerCase());
RegistryEventHandler.registry.register(biome);
BiomeTweaker.getInstance().onTweak(Biome.getIdForBiome(biome));
}
} else {
final Iterator<Biome> it = this.toCopy.getIterator();
if (!it.hasNext())
throw new IllegalStateException("No biome found to copy!");
final Biome toCopy = it.next();
if (it.hasNext())
LogHelper.warn("More than one biome found to copy! Only the first one will be copied.");
Constructor<? extends Biome> construct = null;
try {
// catches all vanilla biomes
if (ScriptCommandCreateBiome.extraParameters.containsKey(toCopy.getBiomeClass())) {
final List<? extends Property<?>> props = ScriptCommandCreateBiome.extraParameters.get(toCopy.getBiomeClass());
final Class<?>[] types = new Class<?>[props.size() + 1];
for (int i = 0; i < props.size(); i++) types[i] = Primitives.unwrap(props.get(i).getTypeClass());
types[types.length - 1] = BiomeProperties.class;
construct = toCopy.getBiomeClass().getConstructor(types);
} else
construct = toCopy.getBiomeClass().getConstructor(BiomeProperties.class);
} catch (final Exception e) {
try {
// Catches most BOP biomes
construct = toCopy.getBiomeClass().getConstructor();
} catch (final Exception e1) {
}
}
Biome biome;
if (construct == null) {
LogHelper.warn("Unable to copy biome class " + toCopy.getBiomeClass().getCanonicalName() + "! Some functionality may not be copied!");
biome = new BiomeTweakerBiome(new BiomeProperties("BiomeTweaker Biome").setBaseHeight(0.125F).setHeightVariation(0.05F).setTemperature(0.8F).setRainfall(0.4F));
} else
switch(construct.getParameterCount()) {
case 0:
biome = construct.newInstance();
break;
case 1:
biome = construct.newInstance(new BiomeProperties(toCopy.getBiomeName()));
break;
default:
final List<? extends Property<?>> props = ScriptCommandCreateBiome.extraParameters.get(toCopy.getBiomeClass());
final Object[] objs = new Object[props.size() + 1];
for (int i = 0; i < props.size(); i++) objs[i] = props.get(i).get(toCopy);
objs[objs.length - 1] = new BiomeProperties(toCopy.getBiomeName());
biome = construct.newInstance(objs);
break;
}
if (MinecraftForge.EVENT_BUS.post(new BiomeTweakEvent.Create(this, biome)))
return;
biome.setRegistryName(ModData.MOD_ID, this.rLoc.toLowerCase());
RegistryEventHandler.registry.register(biome);
// Copy props
for (final Property<?> prop : BiomePropertyManager.getAllProperties()) if (prop.isCopyable())
prop.copy(toCopy, biome);
// Copy dict types
if (BiomeDictionary.hasAnyType(toCopy))
BiomeDictionary.addTypes(biome, BiomeDictionary.getTypes(toCopy).toArray(new BiomeDictionary.Type[0]));
// Copy spawns
for (final EnumCreatureType type : EnumCreatureType.values()) {
final List<SpawnListEntry> entries = biome.getSpawnableList(type);
entries.clear();
entries.addAll(toCopy.getSpawnableList(type));
}
BiomeTweaker.getInstance().onTweak(Biome.getIdForBiome(biome));
}
}
use of net.minecraft.world.biome.Biome.SpawnListEntry in project BiomeTweaker by superckl.
the class ScriptCommandAddRemoveSpawn method perform.
@Override
public void perform() throws Exception {
final Class<? extends Entity> clazz2 = EntityHelper.getEntityClass(this.entityClass);
if (clazz2 == null)
throw new IllegalArgumentException("Failed to find entity class: " + this.entityClass);
if (!EntityLiving.class.isAssignableFrom(clazz2))
throw new IllegalArgumentException("entity class " + this.entityClass + " is not assignable to EntityLiving. It cannot be spawned!");
final Class<? extends EntityLiving> clazz = WarningHelper.uncheckedCast(clazz2);
final SpawnListEntry entry = new SpawnListEntry(clazz, this.weight, this.minCount, this.maxCount);
final Iterator<Biome> it = this.pack.getIterator();
while (it.hasNext()) {
final Biome biome = it.next();
if (this.remove && MinecraftForge.EVENT_BUS.post(new BiomeTweakEvent.RemoveSpawn(this, biome, this.type, clazz)))
continue;
else if (!this.remove && MinecraftForge.EVENT_BUS.post(new BiomeTweakEvent.AddSpawn(this, biome, entry)))
continue;
if (this.remove)
this.removeEntry(clazz, biome.getSpawnableList(this.type));
else
biome.getSpawnableList(this.type).add(new Biome.SpawnListEntry(clazz, this.weight, this.minCount, this.maxCount));
BiomeTweaker.getInstance().onTweak(Biome.getIdForBiome(biome));
}
}
use of net.minecraft.world.biome.Biome.SpawnListEntry in project malmo by Microsoft.
the class ServerStateMachine method onGetPotentialSpawns.
/**
* Called by Forge - call setCanceled(true) to prevent spawning in our world.
*/
@SubscribeEvent
public void onGetPotentialSpawns(PotentialSpawns ps) {
// Decide whether or not to allow spawning.
// We shouldn't allow spawning unless it has been specifically turned on - whether
// a mission is running or not. (Otherwise spawning may happen in between missions.)
boolean allowSpawning = false;
if (currentMissionInit() != null && currentMissionInit().getMission() != null) {
// There is a mission running - does it allow spawning?
ServerSection ss = currentMissionInit().getMission().getServerSection();
ServerInitialConditions sic = (ss != null) ? ss.getServerInitialConditions() : null;
if (sic != null)
allowSpawning = (sic.isAllowSpawning() == Boolean.TRUE);
if (allowSpawning && sic.getAllowedMobs() != null && !sic.getAllowedMobs().isEmpty()) {
// Spawning is allowed, but restricted to our list:
Iterator<SpawnListEntry> it = ps.getList().iterator();
while (it.hasNext()) {
// Is this on our list?
SpawnListEntry sle = it.next();
net.minecraftforge.fml.common.registry.EntityEntry entry = net.minecraftforge.fml.common.registry.EntityRegistry.getEntry(sle.entityClass);
String mobName = entry == null ? null : entry.getName();
boolean allowed = false;
for (EntityTypes mob : sic.getAllowedMobs()) {
if (mob.value().equals(mobName))
allowed = true;
}
if (!allowed)
it.remove();
}
}
}
// Cancel spawn event:
if (!allowSpawning)
ps.setCanceled(true);
}
Aggregations