/** * Add a spawn entry for the supplied entity in the supplied {@link BiomeGenBase} 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)); } }
/** * Remove the spawn entry for the supplied entity * @param entityClass The entity class * @param typeOfCreature type of spawn * @param biomes Biomes to remove from */ public static void removeSpawn(Class <? extends EntityLiving > entityClass, EnumCreatureType typeOfCreature, Biome... biomes) { for (Biome biome : biomes) { Iterator<SpawnListEntry> spawns = biome.getSpawnableList(typeOfCreature).iterator(); while (spawns.hasNext()) { SpawnListEntry entry = spawns.next(); if (entry.entityClass == entityClass) { spawns.remove(); } } } }
@Override public SpawnListEntry getSpawnListEntryForTypeAt(EnumCreatureType creatureType, BlockPos pos) { if (m_proxyWorld != null && Util.isPrefixInCallStack(m_modPrefix)) { return m_proxyWorld.getSpawnListEntryForTypeAt(creatureType, pos); } else if (m_realWorld != null) { return m_realWorld.getSpawnListEntryForTypeAt(creatureType, pos); } else { return super.getSpawnListEntryForTypeAt(creatureType, pos); } }
@Override public boolean canCreatureTypeSpawnHere(EnumCreatureType creatureType, SpawnListEntry spawnListEntry, BlockPos pos) { if (m_proxyWorld != null && Util.isPrefixInCallStack(m_modPrefix)) { return m_proxyWorld.canCreatureTypeSpawnHere(creatureType, spawnListEntry, pos); } else if (m_realWorld != null) { return m_realWorld.canCreatureTypeSpawnHere(creatureType, spawnListEntry, pos); } else { return super.canCreatureTypeSpawnHere(creatureType, spawnListEntry, pos); } }
/** * Helper method to return an array of biomes in which an already existing instance of EntityLiving can spawn. */ private static final Biome[] getBiomeList(final Class<? extends EntityLiving> classToCopy, final EnumCreatureType creatureTypeToCopy) { final List<Biome> biomes = new ArrayList<Biome>(); for (final Biome biome : ForgeRegistries.BIOMES) { biome.getSpawnableList(creatureTypeToCopy).stream().filter(new Predicate<SpawnListEntry>() { @Override public boolean test(SpawnListEntry entry) { return entry.entityClass == classToCopy; } }) .findFirst() .ifPresent(new Consumer<SpawnListEntry>() { @Override public void accept(SpawnListEntry spawnListEntry) { biomes.add(biome); } }); } return biomes.toArray(new Biome[biomes.size()]); }
private static Biome[] getBiomeList() { List<Biome> biomes = new ArrayList<Biome>(); List<Biome> biomeList = BiomeUtils.getBiomeList(); for (Biome currentBiome : biomeList) { List<SpawnListEntry> spawnList = currentBiome.getSpawnableList(EnumCreatureType.MONSTER); for (SpawnListEntry spawnEntry : spawnList) { if (spawnEntry.entityClass == EntityEnderman.class) { biomes.add(currentBiome); } } } return biomes.toArray(new Biome[biomes.size()]); }
public PotentialSpawns(World world, EnumCreatureType type, BlockPos pos, List<SpawnListEntry> oldList) { super(world); this.pos = pos; this.type = type; if (oldList != null) { this.list = new ArrayList<SpawnListEntry>(oldList); } else { this.list = new ArrayList<SpawnListEntry>(); } }
public static boolean canTypeSpawnByDefault(Biome biome, Class <? extends EntityLiving> entityClass, EnumCreatureType type){ List<Biome.SpawnListEntry> entryList = biome.getSpawnableList(type); if(entryList == null || entryList.size() < 1) return false; for(SpawnListEntry entry : entryList){ if(entityClass.equals(entry.entityClass)){ return true; } } return false; }
@Override public List<SpawnListEntry> getPossibleCreatures(EnumCreatureType creatureType, BlockPos pos) { Biome biome = this.worldObj.getBiomeProvider().getBiome(pos); return biome != null ? biome.getSpawnableList(creatureType) : null; }
@Override public List<SpawnListEntry> getPossibleCreatures(EnumCreatureType creatureType, BlockPos pos) { if (creatureType == EnumCreatureType.MONSTER && this.oceanMonumentGenerator.isPositionInStructure(this.world, pos)){ return this.oceanMonumentGenerator.getScatteredFeatureSpawnList(); } return Lists.newArrayList(); }
private void performWorldGenSpawning(World worldIn, EnumCreatureType type, BlockPos pos ,int p_77191_2_, int p_77191_3_, int p_77191_4_, int p_77191_5_, Random randomIn) { float amount; switch (type) { case MONSTER: amount = 0.1f; break; default: amount = 0.3f; break; } List<SpawnListEntry> enteries = world.getBiome(pos).getSpawnableList(type); SpawnListEntry entry = enteries.get(rand.nextInt(enteries.size())); while (randomIn.nextFloat() < amount) { int i = entry.minGroupCount + randomIn.nextInt(1 + entry.maxGroupCount - entry.minGroupCount); IEntityLivingData ientitylivingdata = null; int j = p_77191_2_ + randomIn.nextInt(p_77191_4_); int k = p_77191_3_ + randomIn.nextInt(p_77191_5_); int l = j; int i1 = k; for (int j1 = 0; j1 < i; ++j1) { boolean flag = false; for (int k1 = 0; !flag && k1 < 4; ++k1) { BlockPos blockpos = worldIn.getTopSolidOrLiquidBlock(new BlockPos(j, 0, k)); if (WorldEntitySpawner.canCreatureTypeSpawnAtLocation(EntityLiving.SpawnPlacementType.ON_GROUND, worldIn, blockpos)) { EntityLiving entityliving; try { entityliving = entry.newInstance(worldIn); } catch (Exception exception) { exception.printStackTrace(); continue; } entityliving.setLocationAndAngles((double)((float)j + 0.5F), (double)blockpos.getY(), (double)((float)k + 0.5F), randomIn.nextFloat() * 360.0F, 0.0F); worldIn.spawnEntity(entityliving); ientitylivingdata = entityliving.onInitialSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityliving)), ientitylivingdata); flag = true; } j += randomIn.nextInt(5) - randomIn.nextInt(5); for (k += randomIn.nextInt(5) - randomIn.nextInt(5); j < p_77191_2_ || j >= p_77191_2_ + p_77191_4_ || k < p_77191_3_ || k >= p_77191_3_ + p_77191_4_; k = i1 + randomIn.nextInt(5) - randomIn.nextInt(5)) { j = l + randomIn.nextInt(5) - randomIn.nextInt(5); } } } } }
public List<Biome.SpawnListEntry> getPossibleCreatures(EnumCreatureType creatureType, BlockPos pos) { ArrayList<Biome.SpawnListEntry> list = new ArrayList<Biome.SpawnListEntry>(); list.add(new Biome.SpawnListEntry(EntityEndermite.class, 3, 2, 4)); return list; }
@Override public List<SpawnListEntry> getPossibleCreatures(EnumCreatureType creatureType, BlockPos pos) { // TODO Auto-generated method stub return null; }
public List<SpawnListEntry> getList() { return list; }
@Override public List<SpawnListEntry> getPossibleCreatures(EnumCreatureType creatureType, BlockPos pos) { return new ArrayList<SpawnListEntry>(); }
@Override @Nullable public SpawnListEntry getSpawnListEntryForTypeAt(EnumCreatureType creatureType, BlockPos pos) { return null; }
@Override public boolean canCreatureTypeSpawnHere(EnumCreatureType creatureType, SpawnListEntry spawnListEntry, BlockPos pos) { return false; }
/** 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); }
public boolean onEntitySpawning(BlockPos pos, EnumCreatureType type, List<SpawnListEntry> list) { return false; }
@Override public List<SpawnListEntry> getPossibleCreatures(EnumCreatureType creatureType, BlockPos pos) { return spawns; }
/** Initialize the structure */ public MapGenUnderworldRampart() { super(13, 9); this.spawnList.add(new SpawnListEntry(EntityUnderworldSilverfish.class, 100, 1, 1)); }
/** Initialize the structure */ public MapGenUnderworldTower() { super(12, 6); this.spawnList.add(new SpawnListEntry(EntityUnderworldSkeleton.class, 150, 3, 5)); }
@Override public List<SpawnListEntry> getPossibleCreatures(EnumCreatureType creatureType, BlockPos pos) { return Collections.emptyList(); }
boolean onEntitySpawning(BlockPos pos, EnumCreatureType type, List<SpawnListEntry> list);