2011-01-25 19:14:06 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
import java.util.Iterator;
|
|
|
|
|
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
|
2012-07-29 09:33:13 +02:00
|
|
|
private NBTTagCompound spawnData = null;
|
2011-02-23 03:37:56 +01:00
|
|
|
public double b;
|
|
|
|
public double c = 0.0D;
|
2012-07-29 09:33:13 +02:00
|
|
|
private int minSpawnDelay = 200;
|
|
|
|
private int maxSpawnDelay = 800;
|
|
|
|
private int spawnCount = 4;
|
2012-10-25 05:53:23 +02:00
|
|
|
private int maxNearbyEntities = 6;
|
|
|
|
private int requiredPlayerRange = 16;
|
|
|
|
private int spawnRange = 4;
|
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
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public boolean b() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return this.world.findNearbyPlayer((double) this.x + 0.5D, (double) this.y + 0.5D, (double) this.z + 0.5D, (double) this.requiredPlayerRange) != null;
|
2011-01-25 19:14:06 +01:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public void g() {
|
|
|
|
if (this.b()) {
|
|
|
|
if (this.world.isStatic) {
|
|
|
|
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());
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
this.world.addParticle("smoke", d0, d1, d2, 0.0D, 0.0D, 0.0D);
|
|
|
|
this.world.addParticle("flame", d0, d1, d2, 0.0D, 0.0D, 0.0D);
|
|
|
|
if (this.spawnDelay > 0) {
|
|
|
|
--this.spawnDelay;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.c = this.b;
|
|
|
|
this.b = (this.b + (double) (1000.0F / ((float) this.spawnDelay + 200.0F))) % 360.0D;
|
2012-07-29 09:33:13 +02:00
|
|
|
} else {
|
2011-06-30 00:02:25 +02:00
|
|
|
if (this.spawnDelay == -1) {
|
2012-10-25 05:53:23 +02: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
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
for (int i = 0; i < this.spawnCount; ++i) {
|
|
|
|
Entity entity = EntityTypes.createEntityByName(this.mobName, this.world);
|
2011-12-11 16:59:55 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (entity == null) {
|
2011-12-11 16:59:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
int j = this.world.a(entity.getClass(), AxisAlignedBB.a().a((double) this.x, (double) this.y, (double) this.z, (double) (this.x + 1), (double) (this.y + 1), (double) (this.z + 1)).grow((double) (this.spawnRange * 2), 4.0D, (double) (this.spawnRange * 2))).size();
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if (j >= this.maxNearbyEntities) {
|
|
|
|
this.e();
|
2011-01-29 22:50:29 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (entity != null) {
|
2012-10-25 05:53:23 +02:00
|
|
|
double d3 = (double) this.x + (this.world.random.nextDouble() - this.world.random.nextDouble()) * (double) this.spawnRange;
|
2011-06-27 00:25:01 +02:00
|
|
|
double d4 = (double) (this.y + this.world.random.nextInt(3) - 1);
|
2012-10-25 05:53:23 +02:00
|
|
|
double d5 = (double) this.z + (this.world.random.nextDouble() - this.world.random.nextDouble()) * (double) this.spawnRange;
|
2012-07-29 09:33:13 +02:00
|
|
|
EntityLiving entityliving = entity instanceof EntityLiving ? (EntityLiving) entity : null;
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
entity.setPositionRotation(d3, d4, d5, this.world.random.nextFloat() * 360.0F, 0.0F);
|
|
|
|
if (entityliving == null || entityliving.canSpawn()) {
|
|
|
|
this.a(entity);
|
2012-09-14 07:03:47 +02:00
|
|
|
this.world.addEntity(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER); // CraftBukkit
|
2012-02-29 22:31:04 +01:00
|
|
|
this.world.triggerEffect(2004, this.x, this.y, this.z, 0);
|
2012-07-29 09:33:13 +02:00
|
|
|
if (entityliving != null) {
|
2012-11-06 13:05:28 +01:00
|
|
|
entityliving.aR();
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02: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-07-29 09:33:13 +02:00
|
|
|
super.g();
|
2011-01-25 19:14:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public void a(Entity entity) {
|
|
|
|
if (this.spawnData != null) {
|
|
|
|
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
|
|
|
|
|
|
|
entity.c(nbttagcompound);
|
|
|
|
Iterator iterator = this.spawnData.c().iterator();
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
NBTBase nbtbase = (NBTBase) iterator.next();
|
|
|
|
|
|
|
|
nbttagcompound.set(nbtbase.getName(), nbtbase.clone());
|
|
|
|
}
|
|
|
|
|
|
|
|
entity.e(nbttagcompound);
|
2012-10-25 05:53:23 +02:00
|
|
|
} else if (entity instanceof EntityLiving && entity.world != null) {
|
2012-11-06 13:05:28 +01:00
|
|
|
((EntityLiving) entity).bG();
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
private void e() {
|
2012-11-06 13:05:28 +01:00
|
|
|
if (this.maxSpawnDelay <= this.minSpawnDelay) {
|
|
|
|
this.spawnDelay = this.minSpawnDelay;
|
|
|
|
} else {
|
|
|
|
this.spawnDelay = this.minSpawnDelay + this.world.random.nextInt(this.maxSpawnDelay - this.minSpawnDelay);
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
this.world.playNote(this.x, this.y, this.z, this.q().id, 1, 0);
|
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");
|
2012-07-29 09:33:13 +02:00
|
|
|
if (nbttagcompound.hasKey("SpawnData")) {
|
|
|
|
this.spawnData = nbttagcompound.getCompound("SpawnData");
|
|
|
|
} else {
|
|
|
|
this.spawnData = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nbttagcompound.hasKey("MinSpawnDelay")) {
|
|
|
|
this.minSpawnDelay = nbttagcompound.getShort("MinSpawnDelay");
|
|
|
|
this.maxSpawnDelay = nbttagcompound.getShort("MaxSpawnDelay");
|
|
|
|
this.spawnCount = nbttagcompound.getShort("SpawnCount");
|
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
|
|
|
|
if (nbttagcompound.hasKey("MaxNearbyEntities")) {
|
|
|
|
this.maxNearbyEntities = nbttagcompound.getShort("MaxNearbyEntities");
|
|
|
|
this.requiredPlayerRange = nbttagcompound.getShort("RequiredPlayerRange");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nbttagcompound.hasKey("SpawnRange")) {
|
|
|
|
this.spawnRange = nbttagcompound.getShort("SpawnRange");
|
|
|
|
}
|
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);
|
2012-07-29 09:33:13 +02:00
|
|
|
nbttagcompound.setShort("MinSpawnDelay", (short) this.minSpawnDelay);
|
|
|
|
nbttagcompound.setShort("MaxSpawnDelay", (short) this.maxSpawnDelay);
|
|
|
|
nbttagcompound.setShort("SpawnCount", (short) this.spawnCount);
|
2012-10-25 05:53:23 +02:00
|
|
|
nbttagcompound.setShort("MaxNearbyEntities", (short) this.maxNearbyEntities);
|
|
|
|
nbttagcompound.setShort("RequiredPlayerRange", (short) this.requiredPlayerRange);
|
|
|
|
nbttagcompound.setShort("SpawnRange", (short) this.spawnRange);
|
2012-07-29 09:33:13 +02:00
|
|
|
if (this.spawnData != null) {
|
|
|
|
nbttagcompound.setCompound("SpawnData", this.spawnData);
|
|
|
|
}
|
2011-01-25 19:14:06 +01:00
|
|
|
}
|
2012-03-01 11:49:23 +01:00
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
public Packet getUpdatePacket() {
|
2012-07-29 09:33:13 +02:00
|
|
|
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
2012-03-01 11:49:23 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
this.b(nbttagcompound);
|
|
|
|
return new Packet132TileEntityData(this.x, this.y, this.z, 1, nbttagcompound);
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
|
|
|
|
public void b(int i, int j) {
|
|
|
|
if (i == 1 && this.world.isStatic) {
|
|
|
|
this.spawnDelay = this.minSpawnDelay;
|
|
|
|
}
|
|
|
|
}
|
2011-01-25 19:14:06 +01:00
|
|
|
}
|