2011-06-19 07:23:45 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
// CraftBukkit start
|
2011-06-19 07:23:45 +02:00
|
|
|
import org.bukkit.craftbukkit.entity.CraftEntity;
|
2011-11-27 05:22:24 +01:00
|
|
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
2011-06-19 07:23:45 +02:00
|
|
|
import org.bukkit.event.entity.EntityTargetEvent;
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
public class EntityGhast extends EntityFlying implements IMonster {
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
public int h;
|
|
|
|
public double i;
|
|
|
|
public double j;
|
|
|
|
public double bn;
|
|
|
|
private Entity target;
|
|
|
|
private int br;
|
|
|
|
public int bo;
|
|
|
|
public int bp;
|
2012-12-20 05:03:52 +01:00
|
|
|
private int explosionPower = 1;
|
2011-06-19 07:23:45 +02:00
|
|
|
|
|
|
|
public EntityGhast(World world) {
|
|
|
|
super(world);
|
2012-07-29 09:33:13 +02:00
|
|
|
this.a(4.0F, 4.0F);
|
2011-06-27 00:25:01 +02:00
|
|
|
this.fireProof = true;
|
2013-07-01 13:03:00 +02:00
|
|
|
this.b = 5;
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
public boolean damageEntity(DamageSource damagesource, float f) {
|
2012-11-06 13:05:28 +01:00
|
|
|
if (this.isInvulnerable()) {
|
|
|
|
return false;
|
2013-03-13 23:33:27 +01:00
|
|
|
} else if ("fireball".equals(damagesource.n()) && damagesource.getEntity() instanceof EntityHuman) {
|
2013-07-01 13:03:00 +02:00
|
|
|
super.damageEntity(damagesource, 1000.0F);
|
2011-11-20 09:01:14 +01:00
|
|
|
((EntityHuman) damagesource.getEntity()).a((Statistic) AchievementList.y);
|
|
|
|
return true;
|
|
|
|
} else {
|
2013-07-01 13:03:00 +02:00
|
|
|
return super.damageEntity(damagesource, f);
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
2011-06-19 07:23:45 +02:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
protected void a() {
|
|
|
|
super.a();
|
2011-06-19 07:23:45 +02:00
|
|
|
this.datawatcher.a(16, Byte.valueOf((byte) 0));
|
|
|
|
}
|
|
|
|
|
2013-09-19 20:25:08 +02:00
|
|
|
protected void az() {
|
|
|
|
super.az();
|
2013-07-09 01:43:37 +02:00
|
|
|
this.getAttributeInstance(GenericAttributes.a).setValue(10.0D);
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
|
|
|
|
2013-09-19 20:25:08 +02:00
|
|
|
protected void bl() {
|
2011-09-24 23:03:31 +02:00
|
|
|
if (!this.world.isStatic && this.world.difficulty == 0) {
|
2011-06-19 07:23:45 +02:00
|
|
|
this.die();
|
|
|
|
}
|
|
|
|
|
2013-09-19 20:25:08 +02:00
|
|
|
this.u();
|
2013-07-01 13:03:00 +02:00
|
|
|
this.bo = this.bp;
|
|
|
|
double d0 = this.i - this.locX;
|
|
|
|
double d1 = this.j - this.locY;
|
|
|
|
double d2 = this.bn - this.locZ;
|
2012-07-29 09:33:13 +02:00
|
|
|
double d3 = d0 * d0 + d1 * d1 + d2 * d2;
|
2011-06-19 07:23:45 +02:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (d3 < 1.0D || d3 > 3600.0D) {
|
2013-07-01 13:03:00 +02:00
|
|
|
this.i = this.locX + (double) ((this.random.nextFloat() * 2.0F - 1.0F) * 16.0F);
|
|
|
|
this.j = this.locY + (double) ((this.random.nextFloat() * 2.0F - 1.0F) * 16.0F);
|
|
|
|
this.bn = this.locZ + (double) ((this.random.nextFloat() * 2.0F - 1.0F) * 16.0F);
|
2011-06-19 07:23:45 +02:00
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
if (this.h-- <= 0) {
|
|
|
|
this.h += this.random.nextInt(5) + 2;
|
2012-07-29 09:33:13 +02:00
|
|
|
d3 = (double) MathHelper.sqrt(d3);
|
2013-07-01 13:03:00 +02:00
|
|
|
if (this.a(this.i, this.j, this.bn, d3)) {
|
2011-06-19 07:23:45 +02:00
|
|
|
this.motX += d0 / d3 * 0.1D;
|
|
|
|
this.motY += d1 / d3 * 0.1D;
|
|
|
|
this.motZ += d2 / d3 * 0.1D;
|
|
|
|
} else {
|
2013-07-01 13:03:00 +02:00
|
|
|
this.i = this.locX;
|
|
|
|
this.j = this.locY;
|
|
|
|
this.bn = this.locZ;
|
2011-06-19 07:23:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
if (this.target != null && this.target.dead) {
|
2011-06-19 07:23:45 +02:00
|
|
|
// CraftBukkit start
|
2011-06-27 00:25:01 +02:00
|
|
|
EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), null, EntityTargetEvent.TargetReason.TARGET_DIED);
|
|
|
|
this.world.getServer().getPluginManager().callEvent(event);
|
2011-06-19 07:23:45 +02:00
|
|
|
|
|
|
|
if (!event.isCancelled()) {
|
|
|
|
if (event.getTarget() == null) {
|
2011-06-27 00:25:01 +02:00
|
|
|
this.target = null;
|
2011-06-19 07:23:45 +02:00
|
|
|
} else {
|
2011-06-27 00:25:01 +02:00
|
|
|
this.target = ((CraftEntity) event.getTarget()).getHandle();
|
2011-06-19 07:23:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
if (this.target == null || this.br-- <= 0) {
|
2011-06-19 07:23:45 +02:00
|
|
|
// CraftBukkit start
|
2011-11-30 00:17:43 +01:00
|
|
|
Entity target = this.world.findNearbyVulnerablePlayer(this, 100.0D);
|
2011-06-19 07:23:45 +02:00
|
|
|
if (target != null) {
|
2011-06-27 00:25:01 +02:00
|
|
|
EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), target.getBukkitEntity(), EntityTargetEvent.TargetReason.CLOSEST_PLAYER);
|
|
|
|
this.world.getServer().getPluginManager().callEvent(event);
|
2011-06-19 07:23:45 +02:00
|
|
|
|
|
|
|
if (!event.isCancelled()) {
|
|
|
|
if (event.getTarget() == null) {
|
2011-06-27 00:25:01 +02:00
|
|
|
this.target = null;
|
2011-06-19 07:23:45 +02:00
|
|
|
} else {
|
2011-06-27 00:25:01 +02:00
|
|
|
this.target = ((CraftEntity) event.getTarget()).getHandle();
|
2011-06-19 07:23:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
if (this.target != null) {
|
2013-07-01 13:03:00 +02:00
|
|
|
this.br = 20;
|
2011-06-19 07:23:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double d4 = 64.0D;
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (this.target != null && this.target.e((Entity) this) < d4 * d4) {
|
2011-06-27 00:25:01 +02:00
|
|
|
double d5 = this.target.locX - this.locX;
|
2011-11-30 00:17:43 +01:00
|
|
|
double d6 = this.target.boundingBox.b + (double) (this.target.length / 2.0F) - (this.locY + (double) (this.length / 2.0F));
|
2011-06-27 00:25:01 +02:00
|
|
|
double d7 = this.target.locZ - this.locZ;
|
2011-06-19 07:23:45 +02:00
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
this.aN = this.yaw = -((float) Math.atan2(d5, d7)) * 180.0F / 3.1415927F;
|
|
|
|
if (this.o(this.target)) {
|
|
|
|
if (this.bp == 10) {
|
2011-11-20 09:01:14 +01:00
|
|
|
this.world.a((EntityHuman) null, 1007, (int) this.locX, (int) this.locY, (int) this.locZ, 0);
|
2011-06-19 07:23:45 +02:00
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
++this.bp;
|
|
|
|
if (this.bp == 20) {
|
2011-11-20 09:01:14 +01:00
|
|
|
this.world.a((EntityHuman) null, 1008, (int) this.locX, (int) this.locY, (int) this.locZ, 0);
|
2012-10-25 05:53:23 +02:00
|
|
|
EntityLargeFireball entitylargefireball = new EntityLargeFireball(this.world, this, d5, d6, d7);
|
2012-12-20 05:03:52 +01:00
|
|
|
|
2013-09-19 20:25:08 +02:00
|
|
|
// CraftBukkit - set bukkitYield when setting explosionpower
|
|
|
|
entitylargefireball.bukkitYield = entitylargefireball.yield = this.explosionPower;
|
2011-06-19 07:23:45 +02:00
|
|
|
double d8 = 4.0D;
|
2013-07-01 13:03:00 +02:00
|
|
|
Vec3D vec3d = this.j(1.0F);
|
2011-06-19 07:23:45 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
entitylargefireball.locX = this.locX + vec3d.c * d8;
|
|
|
|
entitylargefireball.locY = this.locY + (double) (this.length / 2.0F) + 0.5D;
|
|
|
|
entitylargefireball.locZ = this.locZ + vec3d.e * d8;
|
|
|
|
this.world.addEntity(entitylargefireball);
|
2013-07-01 13:03:00 +02:00
|
|
|
this.bp = -40;
|
2011-06-19 07:23:45 +02:00
|
|
|
}
|
2013-07-01 13:03:00 +02:00
|
|
|
} else if (this.bp > 0) {
|
|
|
|
--this.bp;
|
2011-06-19 07:23:45 +02:00
|
|
|
}
|
|
|
|
} else {
|
2013-07-01 13:03:00 +02:00
|
|
|
this.aN = this.yaw = -((float) Math.atan2(this.motX, this.motZ)) * 180.0F / 3.1415927F;
|
|
|
|
if (this.bp > 0) {
|
|
|
|
--this.bp;
|
2011-06-19 07:23:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.world.isStatic) {
|
2011-09-24 23:03:31 +02:00
|
|
|
byte b0 = this.datawatcher.getByte(16);
|
2013-07-01 13:03:00 +02:00
|
|
|
byte b1 = (byte) (this.bp > 10 ? 1 : 0);
|
2011-06-19 07:23:45 +02:00
|
|
|
|
|
|
|
if (b0 != b1) {
|
2011-06-27 00:25:01 +02:00
|
|
|
this.datawatcher.watch(16, Byte.valueOf(b1));
|
2011-06-19 07:23:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean a(double d0, double d1, double d2, double d3) {
|
2013-07-01 13:03:00 +02:00
|
|
|
double d4 = (this.i - this.locX) / d3;
|
|
|
|
double d5 = (this.j - this.locY) / d3;
|
|
|
|
double d6 = (this.bn - this.locZ) / d3;
|
2011-06-19 07:23:45 +02:00
|
|
|
AxisAlignedBB axisalignedbb = this.boundingBox.clone();
|
|
|
|
|
|
|
|
for (int i = 1; (double) i < d3; ++i) {
|
|
|
|
axisalignedbb.d(d4, d5, d6);
|
2012-07-29 09:33:13 +02:00
|
|
|
if (!this.world.getCubes(this, axisalignedbb).isEmpty()) {
|
2011-06-19 07:23:45 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
protected String r() {
|
2011-06-19 07:23:45 +02:00
|
|
|
return "mob.ghast.moan";
|
|
|
|
}
|
|
|
|
|
2013-09-19 20:25:08 +02:00
|
|
|
protected String aO() {
|
2011-06-19 07:23:45 +02:00
|
|
|
return "mob.ghast.scream";
|
|
|
|
}
|
|
|
|
|
2013-09-19 20:25:08 +02:00
|
|
|
protected String aP() {
|
2011-06-19 07:23:45 +02:00
|
|
|
return "mob.ghast.death";
|
|
|
|
}
|
|
|
|
|
2012-01-14 21:03:48 +01:00
|
|
|
protected int getLootId() {
|
2011-06-19 07:23:45 +02:00
|
|
|
return Item.SULPHUR.id;
|
|
|
|
}
|
|
|
|
|
2011-11-30 00:17:43 +01:00
|
|
|
protected void dropDeathLoot(boolean flag, int i) {
|
2011-11-27 05:22:24 +01:00
|
|
|
// CraftBukkit start
|
2012-07-22 08:18:00 +02:00
|
|
|
java.util.List<org.bukkit.inventory.ItemStack> loot = new java.util.ArrayList<org.bukkit.inventory.ItemStack>();
|
2011-11-20 09:01:14 +01:00
|
|
|
int j = this.random.nextInt(2) + this.random.nextInt(1 + i);
|
|
|
|
|
|
|
|
int k;
|
|
|
|
|
2011-11-27 05:22:24 +01:00
|
|
|
if (j > 0) {
|
2012-12-17 08:31:41 +01:00
|
|
|
loot.add(CraftItemStack.asNewCraftStack(Item.GHAST_TEAR, j));
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
j = this.random.nextInt(3) + this.random.nextInt(1 + i);
|
|
|
|
|
2011-11-27 05:22:24 +01:00
|
|
|
if (j > 0) {
|
2012-12-17 08:31:41 +01:00
|
|
|
loot.add(CraftItemStack.asNewCraftStack(Item.SULPHUR, j));
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
2011-11-27 05:22:24 +01:00
|
|
|
|
2012-07-22 08:18:00 +02:00
|
|
|
org.bukkit.craftbukkit.event.CraftEventFactory.callEntityDeathEvent(this, loot);
|
2011-11-27 05:22:24 +01:00
|
|
|
// CraftBukkit end
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
|
|
|
|
2013-09-19 20:25:08 +02:00
|
|
|
protected float ba() {
|
2011-06-19 07:23:45 +02:00
|
|
|
return 10.0F;
|
|
|
|
}
|
|
|
|
|
2012-01-14 21:03:48 +01:00
|
|
|
public boolean canSpawn() {
|
|
|
|
return this.random.nextInt(20) == 0 && super.canSpawn() && this.world.difficulty > 0;
|
2011-06-19 07:23:45 +02:00
|
|
|
}
|
|
|
|
|
2013-07-09 01:43:37 +02:00
|
|
|
public int bv() {
|
2011-06-19 07:23:45 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2012-12-20 05:03:52 +01:00
|
|
|
|
|
|
|
public void b(NBTTagCompound nbttagcompound) {
|
|
|
|
super.b(nbttagcompound);
|
|
|
|
nbttagcompound.setInt("ExplosionPower", this.explosionPower);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(NBTTagCompound nbttagcompound) {
|
|
|
|
super.a(nbttagcompound);
|
|
|
|
if (nbttagcompound.hasKey("ExplosionPower")) {
|
|
|
|
this.explosionPower = nbttagcompound.getInt("ExplosionPower");
|
|
|
|
}
|
|
|
|
}
|
2011-06-19 07:23:45 +02:00
|
|
|
}
|