2011-06-22 17:55:04 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
import java.util.Collection;
|
2011-06-22 17:55:04 +02:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
2011-09-15 02:23:52 +02:00
|
|
|
import java.util.Random;
|
2011-06-22 17:55:04 +02:00
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
// CraftBukkit
|
|
|
|
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
|
|
|
|
|
|
|
public final class SpawnerCreature {
|
|
|
|
|
|
|
|
private static Set b = new HashSet();
|
|
|
|
protected static final Class[] a = new Class[] { EntitySpider.class, EntityZombie.class, EntitySkeleton.class};
|
|
|
|
|
|
|
|
public SpawnerCreature() {}
|
|
|
|
|
|
|
|
protected static ChunkPosition a(World world, int i, int j) {
|
|
|
|
int k = i + world.random.nextInt(16);
|
2011-09-15 02:23:52 +02:00
|
|
|
Random random = world.random;
|
|
|
|
|
|
|
|
world.getClass();
|
|
|
|
int l = random.nextInt(128);
|
2011-06-22 17:55:04 +02:00
|
|
|
int i1 = j + world.random.nextInt(16);
|
|
|
|
|
|
|
|
return new ChunkPosition(k, l, i1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final int spawnEntities(World world, boolean flag, boolean flag1) {
|
|
|
|
if (!flag && !flag1) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
b.clear();
|
|
|
|
|
|
|
|
int i;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (i = 0; i < world.players.size(); ++i) {
|
|
|
|
EntityHuman entityhuman = (EntityHuman) world.players.get(i);
|
|
|
|
int k = MathHelper.floor(entityhuman.locX / 16.0D);
|
|
|
|
|
|
|
|
j = MathHelper.floor(entityhuman.locZ / 16.0D);
|
|
|
|
byte b0 = 8;
|
|
|
|
|
|
|
|
for (int l = -b0; l <= b0; ++l) {
|
|
|
|
for (int i1 = -b0; i1 <= b0; ++i1) {
|
|
|
|
b.add(new ChunkCoordIntPair(l + k, i1 + j));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
ChunkCoordinates chunkcoordinates = world.getSpawn();
|
|
|
|
EnumCreatureType[] aenumcreaturetype = EnumCreatureType.values();
|
|
|
|
|
|
|
|
j = aenumcreaturetype.length;
|
|
|
|
|
|
|
|
for (int j1 = 0; j1 < j; ++j1) {
|
|
|
|
EnumCreatureType enumcreaturetype = aenumcreaturetype[j1];
|
|
|
|
|
|
|
|
if ((!enumcreaturetype.d() || flag1) && (enumcreaturetype.d() || flag) && world.a(enumcreaturetype.a()) <= enumcreaturetype.b() * b.size() / 256) {
|
|
|
|
Iterator iterator = b.iterator();
|
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
label91:
|
2011-06-22 17:55:04 +02:00
|
|
|
while (iterator.hasNext()) {
|
|
|
|
ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair) iterator.next();
|
|
|
|
BiomeBase biomebase = world.getWorldChunkManager().a(chunkcoordintpair);
|
|
|
|
List list = biomebase.a(enumcreaturetype);
|
|
|
|
|
|
|
|
if (list != null && !list.isEmpty()) {
|
2011-09-15 02:23:52 +02:00
|
|
|
BiomeMeta biomemeta = (BiomeMeta) WeightedRandom.a(world.random, (Collection) list);
|
2011-06-22 17:55:04 +02:00
|
|
|
ChunkPosition chunkposition = a(world, chunkcoordintpair.x * 16, chunkcoordintpair.z * 16);
|
2011-09-15 02:23:52 +02:00
|
|
|
int k1 = chunkposition.x;
|
|
|
|
int l1 = chunkposition.y;
|
|
|
|
int i2 = chunkposition.z;
|
2011-06-22 17:55:04 +02:00
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
if (!world.e(k1, l1, i2) && world.getMaterial(k1, l1, i2) == enumcreaturetype.c()) {
|
|
|
|
int j2 = 0;
|
2011-06-22 17:55:04 +02:00
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
for (int k2 = 0; k2 < 3; ++k2) {
|
|
|
|
int l2 = k1;
|
|
|
|
int i3 = l1;
|
2011-06-22 17:55:04 +02:00
|
|
|
int j3 = i2;
|
|
|
|
byte b1 = 6;
|
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
for (int k3 = 0; k3 < 4; ++k3) {
|
|
|
|
l2 += world.random.nextInt(b1) - world.random.nextInt(b1);
|
|
|
|
i3 += world.random.nextInt(1) - world.random.nextInt(1);
|
2011-06-22 17:55:04 +02:00
|
|
|
j3 += world.random.nextInt(b1) - world.random.nextInt(b1);
|
2011-09-15 02:23:52 +02:00
|
|
|
if (a(enumcreaturetype, world, l2, i3, j3)) {
|
|
|
|
float f = (float) l2 + 0.5F;
|
|
|
|
float f1 = (float) i3;
|
|
|
|
float f2 = (float) j3 + 0.5F;
|
2011-06-22 17:55:04 +02:00
|
|
|
|
|
|
|
if (world.a((double) f, (double) f1, (double) f2, 24.0D) == null) {
|
|
|
|
float f3 = f - (float) chunkcoordinates.x;
|
|
|
|
float f4 = f1 - (float) chunkcoordinates.y;
|
|
|
|
float f5 = f2 - (float) chunkcoordinates.z;
|
|
|
|
float f6 = f3 * f3 + f4 * f4 + f5 * f5;
|
|
|
|
|
|
|
|
if (f6 >= 576.0F) {
|
|
|
|
EntityLiving entityliving;
|
|
|
|
|
|
|
|
try {
|
|
|
|
entityliving = (EntityLiving) biomemeta.a.getConstructor(new Class[] { World.class}).newInstance(new Object[] { world});
|
|
|
|
} catch (Exception exception) {
|
|
|
|
exception.printStackTrace();
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
entityliving.setPositionRotation((double) f, (double) f1, (double) f2, world.random.nextFloat() * 360.0F, 0.0F);
|
|
|
|
if (entityliving.d()) {
|
2011-09-15 02:23:52 +02:00
|
|
|
++j2;
|
2011-06-22 17:55:04 +02:00
|
|
|
// CraftBukkit - added a reason for spawning this creature
|
|
|
|
world.addEntity(entityliving, SpawnReason.NATURAL);
|
|
|
|
a(entityliving, world, f, f1, f2);
|
2011-09-15 02:23:52 +02:00
|
|
|
if (j2 >= entityliving.m()) {
|
|
|
|
continue label91;
|
2011-06-22 17:55:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
i += j2;
|
2011-06-22 17:55:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean a(EnumCreatureType enumcreaturetype, World world, int i, int j, int k) {
|
2011-06-30 00:02:25 +02:00
|
|
|
return enumcreaturetype.c() == Material.WATER ? world.getMaterial(i, j, k).isLiquid() && !world.e(i, j + 1, k) : world.e(i, j - 1, k) && !world.e(i, j, k) && !world.getMaterial(i, j, k).isLiquid() && !world.e(i, j + 1, k);
|
2011-06-22 17:55:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void a(EntityLiving entityliving, World world, float f, float f1, float f2) {
|
|
|
|
if (entityliving instanceof EntitySpider && world.random.nextInt(100) == 0) {
|
|
|
|
EntitySkeleton entityskeleton = new EntitySkeleton(world);
|
|
|
|
|
|
|
|
entityskeleton.setPositionRotation((double) f, (double) f1, (double) f2, entityliving.yaw, 0.0F);
|
|
|
|
// CraftBukkit - added a reason for spawning this creature
|
|
|
|
world.addEntity(entityskeleton, SpawnReason.NATURAL);
|
|
|
|
entityskeleton.mount(entityliving);
|
|
|
|
} else if (entityliving instanceof EntitySheep) {
|
|
|
|
((EntitySheep) entityliving).setColor(EntitySheep.a(world.random));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean a(World world, List list) {
|
|
|
|
boolean flag = false;
|
|
|
|
Pathfinder pathfinder = new Pathfinder(world);
|
|
|
|
Iterator iterator = list.iterator();
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
EntityHuman entityhuman = (EntityHuman) iterator.next();
|
|
|
|
Class[] aclass = a;
|
|
|
|
|
|
|
|
if (aclass != null && aclass.length != 0) {
|
|
|
|
boolean flag1 = false;
|
|
|
|
|
|
|
|
for (int i = 0; i < 20 && !flag1; ++i) {
|
|
|
|
int j = MathHelper.floor(entityhuman.locX) + world.random.nextInt(32) - world.random.nextInt(32);
|
|
|
|
int k = MathHelper.floor(entityhuman.locZ) + world.random.nextInt(32) - world.random.nextInt(32);
|
|
|
|
int l = MathHelper.floor(entityhuman.locY) + world.random.nextInt(16) - world.random.nextInt(16);
|
|
|
|
|
|
|
|
if (l < 1) {
|
|
|
|
l = 1;
|
2011-09-15 02:23:52 +02:00
|
|
|
} else {
|
|
|
|
world.getClass();
|
|
|
|
if (l > 128) {
|
|
|
|
world.getClass();
|
|
|
|
l = 128;
|
|
|
|
}
|
2011-06-22 17:55:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int i1 = world.random.nextInt(aclass.length);
|
|
|
|
|
|
|
|
int j1;
|
|
|
|
|
2011-06-30 00:02:25 +02:00
|
|
|
for (j1 = l; j1 > 2 && !world.e(j, j1 - 1, k); --j1) {
|
2011-06-22 17:55:04 +02:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
while (!a(EnumCreatureType.MONSTER, world, j, j1, k) && j1 < l + 16) {
|
|
|
|
world.getClass();
|
|
|
|
if (j1 >= 128) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-06-22 17:55:04 +02:00
|
|
|
++j1;
|
|
|
|
}
|
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
if (j1 < l + 16) {
|
|
|
|
world.getClass();
|
|
|
|
if (j1 < 128) {
|
|
|
|
float f = (float) j + 0.5F;
|
|
|
|
float f1 = (float) j1;
|
|
|
|
float f2 = (float) k + 0.5F;
|
2011-06-22 17:55:04 +02:00
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
EntityLiving entityliving;
|
2011-06-22 17:55:04 +02:00
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
try {
|
|
|
|
entityliving = (EntityLiving) aclass[i1].getConstructor(new Class[] { World.class}).newInstance(new Object[] { world});
|
|
|
|
} catch (Exception exception) {
|
|
|
|
exception.printStackTrace();
|
|
|
|
return flag;
|
|
|
|
}
|
2011-06-22 17:55:04 +02:00
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
entityliving.setPositionRotation((double) f, (double) f1, (double) f2, world.random.nextFloat() * 360.0F, 0.0F);
|
|
|
|
if (entityliving.d()) {
|
|
|
|
PathEntity pathentity = pathfinder.a(entityliving, entityhuman, 32.0F);
|
2011-06-22 17:55:04 +02:00
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
if (pathentity != null && pathentity.a > 1) {
|
|
|
|
PathPoint pathpoint = pathentity.c();
|
2011-06-22 17:55:04 +02:00
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
if (Math.abs((double) pathpoint.a - entityhuman.locX) < 1.5D && Math.abs((double) pathpoint.c - entityhuman.locZ) < 1.5D && Math.abs((double) pathpoint.b - entityhuman.locY) < 1.5D) {
|
|
|
|
ChunkCoordinates chunkcoordinates = BlockBed.f(world, MathHelper.floor(entityhuman.locX), MathHelper.floor(entityhuman.locY), MathHelper.floor(entityhuman.locZ), 1);
|
2011-06-22 17:55:04 +02:00
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
if (chunkcoordinates == null) {
|
|
|
|
chunkcoordinates = new ChunkCoordinates(j, j1 + 1, k);
|
|
|
|
}
|
2011-06-22 17:55:04 +02:00
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
entityliving.setPositionRotation((double) ((float) chunkcoordinates.x + 0.5F), (double) chunkcoordinates.y, (double) ((float) chunkcoordinates.z + 0.5F), 0.0F, 0.0F);
|
|
|
|
// CraftBukkit - added a reason for spawning this creature
|
|
|
|
world.addEntity(entityliving, SpawnReason.BED);
|
|
|
|
a(entityliving, world, (float) chunkcoordinates.x + 0.5F, (float) chunkcoordinates.y, (float) chunkcoordinates.z + 0.5F);
|
|
|
|
entityhuman.a(true, false, false);
|
|
|
|
entityliving.Z();
|
|
|
|
flag = true;
|
|
|
|
flag1 = true;
|
|
|
|
}
|
2011-06-22 17:55:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return flag;
|
|
|
|
}
|
2011-09-15 02:23:52 +02:00
|
|
|
|
|
|
|
public static void a(World world, BiomeBase biomebase, int i, int j, int k, int l, Random random) {
|
|
|
|
List list = biomebase.a(EnumCreatureType.CREATURE);
|
|
|
|
|
|
|
|
if (!list.isEmpty()) {
|
|
|
|
while (random.nextFloat() < biomebase.d()) {
|
|
|
|
BiomeMeta biomemeta = (BiomeMeta) WeightedRandom.a(world.random, (Collection) list);
|
|
|
|
int i1 = biomemeta.b + random.nextInt(1 + biomemeta.c - biomemeta.b);
|
|
|
|
int j1 = i + random.nextInt(k);
|
|
|
|
int k1 = j + random.nextInt(l);
|
|
|
|
int l1 = j1;
|
|
|
|
int i2 = k1;
|
|
|
|
|
|
|
|
for (int j2 = 0; j2 < i1; ++j2) {
|
|
|
|
boolean flag = false;
|
|
|
|
|
|
|
|
for (int k2 = 0; !flag && k2 < 4; ++k2) {
|
|
|
|
int l2 = world.f(j1, k1);
|
|
|
|
|
|
|
|
if (a(EnumCreatureType.CREATURE, world, j1, l2, k1)) {
|
|
|
|
float f = (float) j1 + 0.5F;
|
|
|
|
float f1 = (float) l2;
|
|
|
|
float f2 = (float) k1 + 0.5F;
|
|
|
|
|
|
|
|
EntityLiving entityliving;
|
|
|
|
|
|
|
|
try {
|
|
|
|
entityliving = (EntityLiving) biomemeta.a.getConstructor(new Class[] { World.class}).newInstance(new Object[] { world});
|
|
|
|
} catch (Exception exception) {
|
|
|
|
exception.printStackTrace();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
entityliving.setPositionRotation((double) f, (double) f1, (double) f2, random.nextFloat() * 360.0F, 0.0F);
|
|
|
|
// CraftBukkit - added a reason for spawning this creature
|
|
|
|
world.addEntity(entityliving, SpawnReason.NATURAL);
|
|
|
|
a(entityliving, world, f, f1, f2);
|
|
|
|
flag = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
j1 += random.nextInt(5) - random.nextInt(5);
|
|
|
|
|
|
|
|
for (k1 += random.nextInt(5) - random.nextInt(5); j1 < i || j1 >= i + k || k1 < j || k1 >= j + k; k1 = i2 + random.nextInt(5) - random.nextInt(5)) {
|
|
|
|
j1 = l1 + random.nextInt(5) - random.nextInt(5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|