private static SpawnType getSpawnType(Chunk chunk, int x, int y, int z) { World world = chunk.getWorld(); BlockPos pos = new BlockPos(x, y, z); if (!WorldEntitySpawner.canCreatureTypeSpawnAtLocation(EntityLiving.SpawnPlacementType.ON_GROUND, world, pos) || chunk.getLightFor(EnumSkyBlock.BLOCK, pos) >= 8) return SpawnType.NEVER; BlockPos p = new BlockPos(x, y , z); AxisAlignedBB aabb = new AxisAlignedBB(p); if (!world.checkNoEntityCollision(aabb) || !world.getEntitiesWithinAABBExcludingEntity(null, aabb).isEmpty() || world.containsAnyLiquid(aabb)) return SpawnType.NEVER; if (chunk.getLightFor(EnumSkyBlock.SKY, pos) >= 8) return SpawnType.NIGHT_ONLY; return SpawnType.ALWAYS; }
private static int getSpawnMode(Chunk chunk, int x, int y, int z) { World world = chunk.getWorld(); BlockPos pos = new BlockPos(x, y, z); if (!WorldEntitySpawner.canCreatureTypeSpawnAtLocation(SpawnPlacementType.ON_GROUND, world, pos) || chunk.getLightFor(EnumSkyBlock.BLOCK, pos) >= 8) { return 0; } c.set(x + 0.2, y + 0.01, z + 0.2, x + 0.8, y + 1.8, z + 0.8); AxisAlignedBB aabb = c.aabb(); if (!world.checkNoEntityCollision(aabb) || !world.getEntitiesWithinAABBExcludingEntity(null, aabb).isEmpty() || world.containsAnyLiquid(aabb)) { return 0; } if (chunk.getLightFor(EnumSkyBlock.SKY, pos) >= 8) { return 1; } return 2; }
private BlockPos findDarkSpot() { IMeeCreep entity = helper.getMeeCreep(); World world = entity.getWorld(); AxisAlignedBB box = getActionBox(); return GeneralTools.traverseBoxFirst(box, p -> { if (world.isAirBlock(p) && WorldEntitySpawner.canCreatureTypeSpawnAtLocation(EntityLiving.SpawnPlacementType.ON_GROUND, world, p)) { int light = world.getLightFromNeighbors(p); if (light < 7) { return p; } } return null; }); }
private BlockPos findDarkSpot() { World world = helper.getMeeCreep().getWorld(); BlockPos position = options.getPlayer().getPosition(); AxisAlignedBB box = new AxisAlignedBB(position.add(-6, -4, -6), position.add(6, 4, 6)); return GeneralTools.traverseBoxFirst(box, p -> { if (world.isAirBlock(p) && WorldEntitySpawner.canCreatureTypeSpawnAtLocation(EntityLiving.SpawnPlacementType.ON_GROUND, world, p)) { int light = world.getLightFromNeighbors(p); if (light < 7) { return p; } } return null; }); }
@Override public boolean isPossible(World world, BlockPos pos, EnumFacing side) { // @todo config for area AxisAlignedBB box = new AxisAlignedBB(pos.add(-10, -5, -10), pos.add(10, 5, 10)); // AxisAlignedBB box = new AxisAlignedBB(pos.add(-2, -2, -2), pos.add(2, 2, 2)); return GeneralTools.traverseBoxTest(box, p -> { if (WorldEntitySpawner.canCreatureTypeSpawnAtLocation(EntityLiving.SpawnPlacementType.ON_GROUND, world, p)) { int light = world.getLightFromNeighbors(p); if (light < 7) { return true; } } return false; }); }
@Nullable private Vec3d findRandomSpawnPos(BlockPos pos) { for (int i = 0; i < 10; ++i) { BlockPos blockpos = pos.add(this.worldObj.rand.nextInt(16) - 8, this.worldObj.rand.nextInt(6) - 3, this.worldObj.rand.nextInt(16) - 8); if (this.theVillage.isBlockPosWithinSqVillageRadius(blockpos) && WorldEntitySpawner.canCreatureTypeSpawnAtLocation(EntityLiving.SpawnPlacementType.ON_GROUND, this.worldObj, blockpos)) { return new Vec3d((double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ()); } } return null; }
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 static boolean canMonsterSpawnAt(int x, int y, int z) { //return SpawnerAnimals.canCreatureTypeSpawnAtLocation(EnumCreatureType.MONSTER, getWorld(), x,y,z); // < 1.8 //return SpawnerAnimals.func_180267_a(EntityLiving.SpawnPlacementType.ON_GROUND, getWorld(), new BlockPos(x,y,z)); // 1.8 EntityLiving.SpawnPlacementType type = EntityLiving.SpawnPlacementType.ON_GROUND; return WorldEntitySpawner.canCreatureTypeSpawnAtLocation(type, getWorld(), new BlockPos(x,y,z)); }
@Override public void populate(int chunkX, int chunkZ) { int x = chunkX * 16; int z = chunkZ * 16; BlockPos pos = new BlockPos(x, 0, z); Biome biome = this.worldObj.getBiome(pos.add(16, 0, 16)); this.rand.setSeed(this.worldObj.getSeed()); long l1 = (this.rand.nextLong() / 2L) * 2L + 1L; long l2 = (this.rand.nextLong() / 2L) * 2L + 1L; this.rand.setSeed((long)chunkX * l1 + (long)chunkZ * l2 ^ this.worldObj.getSeed()); biome.decorate(this.worldObj, this.rand, pos); if (gumCount < 800) { ++gumCount; } else if (this.rand.nextInt(100) == 0) { boolean resetCounter = false; resetCounter = this.golden_island.generate(this.worldObj, this.rand, pos.add(this.rand.nextInt(16) + 8, this.rand.nextInt(64) + 32, this.rand.nextInt(16) + 8)); if (resetCounter) { gumCount = 0; } } if (this.rand.nextInt(3) == 0) { this.dungeon_bronze.generate(this.worldObj, this.rand, pos.add(this.rand.nextInt(16), this.rand.nextInt(64) + 32, this.rand.nextInt(16))); } if(this.rand.nextInt(500) == 0) { BlockPos newPos = pos.add(this.rand.nextInt(16), this.rand.nextInt(32) + 64, this.rand.nextInt(16)); this.dungeon_silver.generate(this.worldObj, this.rand, newPos); } WorldEntitySpawner.performWorldGenSpawning(this.worldObj, biome, x + 8, z + 8, 16, 16, this.rand); }
protected static boolean canMobSpawn(@Nonnull final BlockPos pos) { return WorldEntitySpawner.canCreatureTypeSpawnAtLocation(SpawnPlacementType.ON_GROUND, EnvironState.getWorld(), pos); }
@Override public void populate(int chunkX, int chunkZ) { BlockFalling.fallInstantly = true; int x = chunkX * 16; int z = chunkZ * 16; BlockPos pos = new BlockPos(x, 0, z); Biome biome = this.world.getBiome(pos.add(16, 0, 16)); this.random.setSeed(this.world.getSeed()); long k = this.random.nextLong() / 2L * 2L + 1L; long l = this.random.nextLong() / 2L * 2L + 1L; this.random.setSeed((long) chunkX * k + (long) chunkZ * l ^ this.world.getSeed()); boolean generatedVillage = false; if (this.decorate) { ForgeEventFactory.onChunkPopulate(true, this, this.world, this.random, chunkX, chunkZ, generatedVillage); biome.decorate(this.world, this.random, new BlockPos(x, 0, z)); if (TerrainGen.populate(this, this.world, this.random, chunkX, chunkZ, generatedVillage, PopulateChunkEvent.Populate.EventType.ANIMALS)) { WorldEntitySpawner.performWorldGenSpawning(this.world, biome, x + 8, z + 8, 16, 16, this.random); } pos = pos.add(8, 0, 8); if (TerrainGen.populate(this, this.world, this.random, chunkX, chunkZ, generatedVillage, PopulateChunkEvent.Populate.EventType.ICE)) { for (int offsetX = 0; offsetX < 16; ++offsetX) { for (int offsetZ = 0; offsetZ < 16; ++offsetZ) { BlockPos snowPos = this.world.getPrecipitationHeight(pos.add(offsetX, 0, offsetZ)); BlockPos groundPos = snowPos.down(); if (this.world.canBlockFreezeWater(groundPos)) { this.world.setBlockState(groundPos, Blocks.ICE.getDefaultState(), 2); } if (this.world.canSnowAt(snowPos, true)) { this.world.setBlockState(snowPos, Blocks.SNOW_LAYER.getDefaultState(), 2); } } } } ForgeEventFactory.onChunkPopulate(false, this, this.world, this.random, chunkX, chunkZ, generatedVillage); } BlockFalling.fallInstantly = false; }
@Override public EnumActionResult onItemUse(EntityPlayer player, World worldObj, BlockPos posIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { ItemStack stack = player.getHeldItem(hand); if (side == null || posIn == null || side != EnumFacing.UP) { if (!worldObj.isRemote) { UtilChat.addChatMessage(player, "item.tool_spawn_inspect.up"); } return super.onItemUse(player, worldObj, posIn, hand, side, hitX, hitY, hitZ); } boolean showOdds = player.isSneaking(); if (!worldObj.isRemote) { ChunkProviderServer s = (ChunkProviderServer) worldObj.getChunkProvider(); BlockPos pos = posIn.offset(side); Chunk chunk = worldObj.getChunkFromBlockCoords(pos); if (worldObj.getChunkProvider() instanceof ChunkProviderServer) { List<SpawnDetail> names = new ArrayList<SpawnDetail>(); for (EnumCreatureType creatureType : EnumCreatureType.values()) { List<Biome.SpawnListEntry> list = s.getPossibleCreatures(creatureType, pos); for (Biome.SpawnListEntry entry : list) { if (WorldEntitySpawner.canCreatureTypeSpawnAtLocation(EntitySpawnPlacementRegistry.getPlacementForEntity(entry.entityClass), worldObj, pos)) { names.add(new SpawnDetail(entry, creatureType)); //hack since witherskeleton is not its own class/entry, just a mob modifier like zombietypes or villagertypes if (entry.entityClass.equals(EntitySkeleton.class) && player.dimension == Const.Dimension.nether) { names.add(new SpawnDetail("WitherSkeleton", creatureType, entry.itemWeight)); } } } } if (names.size() > 0) { String strLight = "Light: " + chunk.getLightSubtracted(pos, 0) + " (" + chunk.getLightFor(EnumSkyBlock.SKY, pos) + " sky, " + chunk.getLightFor(EnumSkyBlock.BLOCK, pos) + " block)"; UtilChat.addChatMessage(player, strLight); Collections.sort(names, new Comparator<SpawnDetail>() { @Override public int compare(SpawnDetail o1, SpawnDetail o2) { return o1.getSortBy().compareTo(o2.getSortBy()); } }); List<String> csv = new ArrayList<String>(); for (SpawnDetail detail : names) { csv.add(detail.toString(showOdds)); } UtilChat.addChatMessage(player, String.join(", ", csv)); } else { UtilChat.addChatMessage(player, "item.tool_spawn_inspect.empty"); } } } player.getCooldownTracker().setCooldown(this, COOLDOWN); super.onUse(stack, player, worldObj, hand); return super.onItemUse(player, worldObj, posIn, hand, side, hitX, hitY, hitZ); }