Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/src/main/java/net/minecraft/server/TileEntityMobSpawner.java

110 Zeilen
4.3 KiB
Java

package net.minecraft.server;
public class TileEntityMobSpawner extends TileEntity {
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;
public TileEntityMobSpawner() {
this.spawnDelay = 20;
}
public void a(String s) {
this.mobName = s;
}
public boolean a() {
return this.world.a((double) this.e + 0.5D, (double) this.f + 0.5D, (double) this.g + 0.5D, 16.0D) != null;
}
2011-04-20 22:47:26 +02:00
public void g_() {
2011-02-23 03:37:56 +01:00
this.c = this.b;
2011-01-29 22:50:29 +01:00
if (this.a()) {
double d0 = (double) ((float) this.e + this.world.random.nextFloat());
double d1 = (double) ((float) this.f + this.world.random.nextFloat());
double d2 = (double) ((float) this.g + this.world.random.nextFloat());
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);
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;
}
if (this.spawnDelay == -1) {
2011-02-23 03:37:56 +01:00
this.c();
}
if (this.spawnDelay > 0) {
--this.spawnDelay;
2011-01-29 22:50:29 +01:00
} else {
byte b0 = 4;
for (int i = 0; i < b0; ++i) {
EntityLiving entityliving = (EntityLiving) ((EntityLiving) EntityTypes.a(this.mobName, this.world));
2011-01-29 22:50:29 +01:00
if (entityliving == null) {
return;
}
// CraftBukkit start - The world we're spawning in accepts this creature
boolean isAnimal = entityliving instanceof EntityAnimal || entityliving instanceof EntityWaterAnimal;
if ((isAnimal && !this.world.allowAnimals) || (!isAnimal && !this.world.allowMonsters)) {
return;
}
// CraftBukkit end
int j = this.world.a(entityliving.getClass(), AxisAlignedBB.b((double) this.e, (double) this.f, (double) this.g, (double) (this.e + 1), (double) (this.f + 1), (double) (this.g + 1)).b(8.0D, 4.0D, 8.0D)).size();
2011-01-29 22:50:29 +01:00
if (j >= 6) {
2011-02-23 03:37:56 +01:00
this.c();
2011-01-29 22:50:29 +01:00
return;
}
if (entityliving != null) {
double d3 = (double) this.e + (this.world.random.nextDouble() - this.world.random.nextDouble()) * 4.0D;
double d4 = (double) (this.f + this.world.random.nextInt(3) - 1);
double d5 = (double) this.g + (this.world.random.nextDouble() - this.world.random.nextDouble()) * 4.0D;
2011-01-29 22:50:29 +01:00
entityliving.setPositionRotation(d3, d4, d5, this.world.random.nextFloat() * 360.0F, 0.0F);
2011-04-20 22:47:26 +02:00
if (entityliving.d()) {
this.world.addEntity(entityliving);
2011-01-29 22:50:29 +01:00
for (int k = 0; k < 20; ++k) {
d0 = (double) this.e + 0.5D + ((double) this.world.random.nextFloat() - 0.5D) * 2.0D;
d1 = (double) this.f + 0.5D + ((double) this.world.random.nextFloat() - 0.5D) * 2.0D;
d2 = (double) this.g + 0.5D + ((double) this.world.random.nextFloat() - 0.5D) * 2.0D;
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-29 22:50:29 +01:00
}
2011-05-28 22:50:08 +02:00
entityliving.R();
2011-02-23 03:37:56 +01:00
this.c();
2011-01-29 22:50:29 +01:00
}
}
}
2011-04-20 22:47:26 +02:00
super.g_();
}
}
}
2011-02-23 03:37:56 +01:00
private void c() {
this.spawnDelay = 200 + this.world.random.nextInt(600);
}
public void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound);
this.mobName = nbttagcompound.getString("EntityId");
this.spawnDelay = nbttagcompound.d("Delay");
}
public void b(NBTTagCompound nbttagcompound) {
super.b(nbttagcompound);
nbttagcompound.setString("EntityId", this.mobName);
nbttagcompound.a("Delay", (short) this.spawnDelay);
}
}