2011-01-25 19:14:06 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; // CraftBukkit
|
2011-06-21 22:20:11 +02:00
|
|
|
|
2011-01-25 19:14:06 +01:00
|
|
|
public class TileEntityMobSpawner extends TileEntity {
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public int spawnDelay = -1;
|
2011-05-14 16:29:42 +02:00
|
|
|
public String mobName = "Pig"; // CraftBukkit - private -> public
|
2011-02-23 03:37:56 +01:00
|
|
|
public double b;
|
|
|
|
public double c = 0.0D;
|
2011-01-25 19:14:06 +01:00
|
|
|
|
|
|
|
public TileEntityMobSpawner() {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.spawnDelay = 20;
|
2011-01-25 19:14:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(String s) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.mobName = s;
|
2011-01-25 19:14:06 +01:00
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
public boolean c() {
|
2011-11-30 00:17:43 +01:00
|
|
|
return this.world.findNearbyPlayer((double) this.x + 0.5D, (double) this.y + 0.5D, (double) this.z + 0.5D, 16.0D) != null;
|
2011-01-25 19:14:06 +01:00
|
|
|
}
|
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
public void q_() {
|
2011-02-23 03:37:56 +01:00
|
|
|
this.c = this.b;
|
2011-11-20 09:01:14 +01:00
|
|
|
if (this.c()) {
|
2011-06-27 00:25:01 +02:00
|
|
|
double d0 = (double) ((float) this.x + this.world.random.nextFloat());
|
|
|
|
double d1 = (double) ((float) this.y + this.world.random.nextFloat());
|
|
|
|
double d2 = (double) ((float) this.z + this.world.random.nextFloat());
|
2011-01-25 19:14:06 +01:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
this.world.a("smoke", d0, d1, d2, 0.0D, 0.0D, 0.0D);
|
|
|
|
this.world.a("flame", d0, d1, d2, 0.0D, 0.0D, 0.0D);
|
2011-01-25 19:14:06 +01:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
for (this.b += (double) (1000.0F / ((float) this.spawnDelay + 200.0F)); this.b > 360.0D; this.c -= 360.0D) {
|
2011-02-23 03:37:56 +01:00
|
|
|
this.b -= 360.0D;
|
2011-01-25 19:14:06 +01:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:02:25 +02:00
|
|
|
if (!this.world.isStatic) {
|
|
|
|
if (this.spawnDelay == -1) {
|
2011-11-20 09:01:14 +01:00
|
|
|
this.e();
|
2011-06-30 00:02:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.spawnDelay > 0) {
|
|
|
|
--this.spawnDelay;
|
|
|
|
return;
|
|
|
|
}
|
2011-01-25 19:14:06 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
byte b0 = 4;
|
|
|
|
|
|
|
|
for (int i = 0; i < b0; ++i) {
|
2011-12-11 16:59:55 +01:00
|
|
|
// CraftBukkit start - bad entity detection
|
2012-01-14 21:03:48 +01:00
|
|
|
Entity mob = EntityTypes.createEntityByName(this.mobName, this.world);
|
2011-12-11 16:59:55 +01:00
|
|
|
|
|
|
|
if (!(mob instanceof EntityLiving)) {
|
|
|
|
mobName = "Pig";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityLiving entityliving = (EntityLiving) ((EntityLiving) mob);
|
2012-02-29 22:31:04 +01:00
|
|
|
// CraftBukkit end
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-09-26 09:59:03 +02:00
|
|
|
if (entityliving == null) {
|
2011-01-29 22:50:29 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-12 16:27:39 +01:00
|
|
|
int j = this.world.a(entityliving.getClass(), AxisAlignedBB.b((double) this.x, (double) this.y, (double) this.z, (double) (this.x + 1), (double) (this.y + 1), (double) (this.z + 1)).grow(8.0D, 4.0D, 8.0D)).size();
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (j >= 6) {
|
2011-11-20 09:01:14 +01:00
|
|
|
this.e();
|
2011-01-29 22:50:29 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-26 09:59:03 +02:00
|
|
|
if (entityliving != null) {
|
2011-06-27 00:25:01 +02:00
|
|
|
double d3 = (double) this.x + (this.world.random.nextDouble() - this.world.random.nextDouble()) * 4.0D;
|
|
|
|
double d4 = (double) (this.y + this.world.random.nextInt(3) - 1);
|
|
|
|
double d5 = (double) this.z + (this.world.random.nextDouble() - this.world.random.nextDouble()) * 4.0D;
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-09-26 09:59:03 +02:00
|
|
|
entityliving.setPositionRotation(d3, d4, d5, this.world.random.nextFloat() * 360.0F, 0.0F);
|
2012-01-14 21:03:48 +01:00
|
|
|
if (entityliving.canSpawn()) {
|
2012-02-29 22:31:04 +01:00
|
|
|
this.world.addEntity(entityliving, SpawnReason.SPAWNER); // CraftBukkit
|
|
|
|
this.world.triggerEffect(2004, this.x, this.y, this.z, 0);
|
2012-03-01 11:49:23 +01:00
|
|
|
entityliving.aB();
|
2011-11-20 09:01:14 +01:00
|
|
|
this.e();
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-25 19:14:06 +01:00
|
|
|
}
|
2011-06-30 00:02:25 +02:00
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
super.q_();
|
2011-01-25 19:14:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
private void e() {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.spawnDelay = 200 + this.world.random.nextInt(600);
|
2011-01-25 19:14:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(NBTTagCompound nbttagcompound) {
|
|
|
|
super.a(nbttagcompound);
|
2011-04-20 19:05:14 +02:00
|
|
|
this.mobName = nbttagcompound.getString("EntityId");
|
2011-11-30 00:17:43 +01:00
|
|
|
this.spawnDelay = nbttagcompound.getShort("Delay");
|
2011-01-25 19:14:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void b(NBTTagCompound nbttagcompound) {
|
|
|
|
super.b(nbttagcompound);
|
2011-04-20 19:05:14 +02:00
|
|
|
nbttagcompound.setString("EntityId", this.mobName);
|
2011-11-30 00:17:43 +01:00
|
|
|
nbttagcompound.setShort("Delay", (short) this.spawnDelay);
|
2011-01-25 19:14:06 +01:00
|
|
|
}
|
2012-03-01 11:49:23 +01:00
|
|
|
|
|
|
|
public Packet d() {
|
|
|
|
int i = EntityTypes.a(this.mobName);
|
|
|
|
|
|
|
|
return new Packet132TileEntityData(this.x, this.y, this.z, 1, i);
|
|
|
|
}
|
2011-01-25 19:14:06 +01:00
|
|
|
}
|