use of net.minecraft.world.biome.Biome.SpawnListEntry in project MinecraftForge by MinecraftForge.
the class EntityRegistry method addSpawn.
/**
* Add a spawn entry for the supplied entity in the supplied {@link Biome} list
* @param entityClass Entity class added
* @param weightedProb Probability
* @param min Min spawn count
* @param max Max spawn count
* @param typeOfCreature Type of spawn
* @param biomes List of biomes
*/
public static void addSpawn(Class<? extends EntityLiving> entityClass, int weightedProb, int min, int max, EnumCreatureType typeOfCreature, Biome... biomes) {
for (Biome biome : biomes) {
List<SpawnListEntry> spawns = biome.getSpawnableList(typeOfCreature);
boolean found = false;
for (SpawnListEntry entry : spawns) {
//Adjusting an existing spawn entry
if (entry.entityClass == entityClass) {
entry.itemWeight = weightedProb;
entry.minGroupCount = min;
entry.maxGroupCount = max;
found = true;
break;
}
}
if (!found)
spawns.add(new SpawnListEntry(entityClass, weightedProb, min, max));
}
}
use of net.minecraft.world.biome.Biome.SpawnListEntry in project Minestuck by mraof.
the class SburbHandler method getUnderlingList.
public static List<SpawnListEntry> getUnderlingList(BlockPos pos, World world) {
BlockPos spawn = world.getSpawnPoint();
int difficulty = (int) Math.round(Math.sqrt(new Vec3i(pos.getX() >> 4, 0, pos.getZ() >> 4).distanceSq(new Vec3i(spawn.getX() >> 4, 0, spawn.getZ() >> 4))));
difficulty = Math.min(30, difficulty / 3);
if (difficultyList[difficulty] != null)
return difficultyList[difficulty];
ArrayList<SpawnListEntry> list = new ArrayList<SpawnListEntry>();
int impWeight, ogreWeight = 0, basiliskWeight = 0, lichWeight = 0, giclopsWeight = 0;
if (difficulty < 8)
impWeight = difficulty + 1;
else {
impWeight = 8 - (difficulty - 8) / 3;
if (difficulty < 20)
ogreWeight = (difficulty - 5) / 3;
else
ogreWeight = 5 - (difficulty - 20) / 3;
if (difficulty >= 16) {
if (difficulty < 26)
basiliskWeight = (difficulty - 14) / 2;
else
basiliskWeight = 6;
if (difficulty < 28)
lichWeight = (difficulty - 12) / 3;
else
lichWeight = 6;
if (difficulty >= 20)
if (difficulty < 30)
giclopsWeight = (difficulty - 17) / 3;
else
giclopsWeight = 5;
}
}
if (impWeight > 0)
list.add(new SpawnListEntry(EntityImp.class, impWeight, Math.max(1, (int) (impWeight / 2.5)), Math.max(3, impWeight)));
if (ogreWeight > 0)
list.add(new SpawnListEntry(EntityOgre.class, ogreWeight, ogreWeight >= 5 ? 2 : 1, Math.max(1, ogreWeight / 2)));
if (basiliskWeight > 0)
list.add(new SpawnListEntry(EntityBasilisk.class, basiliskWeight, 1, Math.max(1, basiliskWeight / 2)));
if (lichWeight > 0)
list.add(new SpawnListEntry(EntityLich.class, lichWeight, 1, Math.max(1, lichWeight / 2)));
if (giclopsWeight > 0 && !MinestuckConfig.disableGiclops)
list.add(new SpawnListEntry(EntityGiclops.class, giclopsWeight, 1, Math.max(1, giclopsWeight / 2)));
difficultyList[difficulty] = list;
return list;
}
use of net.minecraft.world.biome.Biome.SpawnListEntry in project BiomeTweaker by superckl.
the class BiomeHelper method fillJsonObject.
public static JsonObject fillJsonObject(final Biome biome, final int... coords) {
BiomeHelper.checkFields();
final JsonObject obj = new JsonObject();
obj.addProperty("ID", Biome.getIdForBiome(biome));
obj.addProperty("Name", biome.biomeName);
obj.addProperty("Resource Location", Biome.REGISTRY.getNameForObject(biome).toString());
obj.addProperty("Class", biome.getClass().getName());
obj.addProperty("Root Height", biome.getBaseHeight());
obj.addProperty("Height Variation", biome.getHeightVariation());
final boolean topNull = biome.topBlock == null || biome.topBlock.getBlock() == null || biome.topBlock.getBlock().delegate == null;
final boolean bottomNull = biome.topBlock == null || biome.topBlock.getBlock() == null || biome.topBlock.getBlock().delegate == null;
obj.addProperty("Top Block", topNull ? "ERROR" : biome.topBlock.toString());
obj.addProperty("Filler Block", bottomNull ? "ERROR" : biome.fillerBlock.toString());
if (!BiomeTweaker.getInstance().isTweakEnabled("oceanTopBlock"))
obj.addProperty("Ocean Top Block", "Disabled. Activate in BiomeTweakerCore.");
else {
final String topBlock = BiomePropertyManager.OCEAN_TOP_BLOCK.get(biome).toString();
obj.addProperty("Ocean Top Block", topBlock);
}
if (!BiomeTweaker.getInstance().isTweakEnabled("oceanFillerBlock"))
obj.addProperty("Ocean Filler Block", "Disabled. Activate in BiomeTweakerCore.");
else {
final String topBlock = BiomePropertyManager.OCEAN_FILLER_BLOCK.get(biome).toString();
obj.addProperty("Ocean Filler Block", topBlock);
}
if (!BiomeTweaker.getInstance().isTweakEnabled("actualFillerBlocks"))
obj.addProperty("Actual Filler Blocks", "Disabled. Activate in BiomeTweakerCore.");
else {
final JsonArray array = new JsonArray();
final IBlockState[] states = BiomePropertyManager.ACTUAL_FILLER_BLOCKS.get(biome);
for (final IBlockState state : states) array.add(new JsonPrimitive(state.toString()));
obj.add("Actual Filler Blocks", array);
}
try {
int i = -1;
final boolean hasCoords = (coords != null) && (coords.length == 3);
int x = 0, y = 0, z = 0;
if (hasCoords) {
x = coords[0];
y = coords[1];
z = coords[2];
}
if (!BiomeTweaker.getInstance().isTweakEnabled("grassColor"))
obj.addProperty("Grass Color", "Disabled. Activate in BiomeTweakerCore.");
else
obj.addProperty("Grass Color", "" + ((hasCoords && FMLCommonHandler.instance().getSide().isClient()) ? biome.getGrassColorAtPos(new BlockPos(x, y, z)) : (i = BiomePropertyManager.GRASS_COLOR.get(biome)) == -1 ? "Not set. Check in-game." : i));
if (!BiomeTweaker.getInstance().isTweakEnabled("foliageColor"))
obj.addProperty("Foliage Color", "Disabled. Activate in BiomeTweakerCore.");
else
obj.addProperty("Foliage Color", "" + ((hasCoords && FMLCommonHandler.instance().getSide().isClient()) ? biome.getFoliageColorAtPos(new BlockPos(x, y, z)) : (i = BiomePropertyManager.FOLIAGE_COLOR.get(biome)) == -1 ? "Not set. Check in-game." : i));
obj.addProperty("Water Color", "" + biome.getWaterColorMultiplier());
} catch (final Exception e) {
LogHelper.error("Failed to retrieve inserted fields!");
e.printStackTrace();
}
obj.addProperty("Temperature", biome.getDefaultTemperature());
obj.addProperty("Humidity", biome.getRainfall());
obj.addProperty("Water Tint", biome.getWaterColorMultiplier());
obj.addProperty("Enable Rain", biome.enableRain);
obj.addProperty("Enable Snow", biome.getEnableSnow());
JsonArray array = new JsonArray();
if (BiomeDictionary.hasAnyType(biome))
for (final Type type : BiomeDictionary.getTypes(biome)) array.add(new JsonPrimitive(type.toString()));
obj.add("Dictionary Types", array);
final JsonObject managerWeights = new JsonObject();
for (final BiomeManager.BiomeType type : BiomeManager.BiomeType.values()) {
final JsonArray subArray = new JsonArray();
final List<BiomeEntry> entries = BiomeManager.getBiomes(type);
for (final BiomeEntry entry : entries) if (Biome.getIdForBiome(entry.biome) == Biome.getIdForBiome(biome))
subArray.add(new JsonPrimitive(entry.itemWeight));
if (subArray.size() > 0)
managerWeights.add(type.name() + " Weights", subArray);
}
obj.add("BiomeManager Entries", managerWeights);
array = new JsonArray();
for (final Object entity : biome.spawnableCreatureList) {
final SpawnListEntry entry = (SpawnListEntry) entity;
final JsonObject object = new JsonObject();
object.addProperty("Entity Class", entry.entityClass.getName());
object.addProperty("Weight", entry.itemWeight);
object.addProperty("Min Group Count", entry.minGroupCount);
object.addProperty("Max Group Count", entry.maxGroupCount);
array.add(object);
}
obj.add("Spawnable Creatures", array);
array = new JsonArray();
for (final Object entity : biome.spawnableMonsterList) {
final SpawnListEntry entry = (SpawnListEntry) entity;
final JsonObject object = new JsonObject();
object.addProperty("Entity Class", entry.entityClass.getName());
object.addProperty("Weight", entry.itemWeight);
object.addProperty("Min Group Count", entry.minGroupCount);
object.addProperty("Max Group Count", entry.maxGroupCount);
array.add(object);
}
obj.add("Spawnable Monsters", array);
array = new JsonArray();
for (final Object entity : biome.spawnableWaterCreatureList) {
final SpawnListEntry entry = (SpawnListEntry) entity;
final JsonObject object = new JsonObject();
object.addProperty("Entity Class", entry.entityClass.getName());
object.addProperty("Weight", entry.itemWeight);
object.addProperty("Min Group Count", entry.minGroupCount);
object.addProperty("Max Group Count", entry.maxGroupCount);
array.add(object);
}
obj.add("Spawnable Water Creatures", array);
array = new JsonArray();
for (final Object entity : biome.spawnableCaveCreatureList) {
final SpawnListEntry entry = (SpawnListEntry) entity;
final JsonObject object = new JsonObject();
object.addProperty("Entity Class", entry.entityClass.getName());
object.addProperty("Weight", entry.itemWeight);
object.addProperty("Min Group Count", entry.minGroupCount);
object.addProperty("Max Group Count", entry.maxGroupCount);
array.add(object);
}
obj.add("Spawnable Cave Creatures", array);
obj.add("Spawn Biome", new JsonPrimitive(BiomeProvider.allowedBiomes.contains(biome)));
obj.addProperty("Tweaked", BiomeTweaker.getInstance().getTweakedBiomes().contains(-1) || BiomeTweaker.getInstance().getTweakedBiomes().contains(Biome.getIdForBiome(biome)));
IntegrationManager.INSTANCE.addBiomeInfo(biome, obj);
return obj;
}
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);
}
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));
}
}
Aggregations