2011-06-19 07:23:45 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
// CraftBukkit start
|
2011-11-27 05:22:24 +01:00
|
|
|
import java.util.List;
|
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.event.CraftEventFactory;
|
|
|
|
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 {
|
|
|
|
|
|
|
|
public int a = 0;
|
|
|
|
public double b;
|
|
|
|
public double c;
|
|
|
|
public double d;
|
2011-06-27 00:25:01 +02:00
|
|
|
private Entity target = null;
|
2011-06-19 07:23:45 +02:00
|
|
|
private int h = 0;
|
|
|
|
public int e = 0;
|
|
|
|
public int f = 0;
|
|
|
|
|
|
|
|
public EntityGhast(World world) {
|
|
|
|
super(world);
|
|
|
|
this.texture = "/mob/ghast.png";
|
|
|
|
this.b(4.0F, 4.0F);
|
2011-06-27 00:25:01 +02:00
|
|
|
this.fireProof = true;
|
2011-11-20 09:01:14 +01:00
|
|
|
this.az = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean damageEntity(DamageSource damagesource, int i) {
|
|
|
|
if ("fireball".equals(damagesource.l()) && damagesource.getEntity() instanceof EntityHuman) {
|
|
|
|
super.damageEntity(damagesource, 1000);
|
|
|
|
((EntityHuman) damagesource.getEntity()).a((Statistic) AchievementList.y);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return super.damageEntity(damagesource, i);
|
|
|
|
}
|
2011-06-19 07:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void b() {
|
|
|
|
super.b();
|
|
|
|
this.datawatcher.a(16, Byte.valueOf((byte) 0));
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
public int getMaxHealth() {
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void w_() {
|
|
|
|
super.w_();
|
2011-09-24 23:03:31 +02:00
|
|
|
byte b0 = this.datawatcher.getByte(16);
|
2011-06-19 07:23:45 +02:00
|
|
|
|
|
|
|
this.texture = b0 == 1 ? "/mob/ghast_fire.png" : "/mob/ghast.png";
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
protected void m_() {
|
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();
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
this.ak();
|
2011-06-19 07:23:45 +02:00
|
|
|
this.e = this.f;
|
|
|
|
double d0 = this.b - this.locX;
|
|
|
|
double d1 = this.c - this.locY;
|
|
|
|
double d2 = this.d - this.locZ;
|
|
|
|
double d3 = (double) MathHelper.a(d0 * d0 + d1 * d1 + d2 * d2);
|
|
|
|
|
|
|
|
if (d3 < 1.0D || d3 > 60.0D) {
|
|
|
|
this.b = this.locX + (double) ((this.random.nextFloat() * 2.0F - 1.0F) * 16.0F);
|
|
|
|
this.c = this.locY + (double) ((this.random.nextFloat() * 2.0F - 1.0F) * 16.0F);
|
|
|
|
this.d = this.locZ + (double) ((this.random.nextFloat() * 2.0F - 1.0F) * 16.0F);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.a-- <= 0) {
|
|
|
|
this.a += this.random.nextInt(5) + 2;
|
|
|
|
if (this.a(this.b, this.c, this.d, d3)) {
|
|
|
|
this.motX += d0 / d3 * 0.1D;
|
|
|
|
this.motY += d1 / d3 * 0.1D;
|
|
|
|
this.motZ += d2 / d3 * 0.1D;
|
|
|
|
} else {
|
|
|
|
this.b = this.locX;
|
|
|
|
this.c = this.locY;
|
|
|
|
this.d = this.locZ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
if (this.target == null || this.h-- <= 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
|
2011-06-27 00:25:01 +02:00
|
|
|
if (this.target != null) {
|
2011-06-19 07:23:45 +02:00
|
|
|
this.h = 20;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double d4 = 64.0D;
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
if (this.target != null && this.target.i(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
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
this.V = this.yaw = -((float) Math.atan2(d5, d7)) * 180.0F / 3.1415927F;
|
|
|
|
if (this.g(this.target)) {
|
2011-06-19 07:23:45 +02:00
|
|
|
if (this.f == 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
|
|
|
}
|
|
|
|
|
|
|
|
++this.f;
|
|
|
|
if (this.f == 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);
|
2011-06-19 07:23:45 +02:00
|
|
|
EntityFireball entityfireball = new EntityFireball(this.world, this, d5, d6, d7);
|
|
|
|
double d8 = 4.0D;
|
2011-11-20 09:01:14 +01:00
|
|
|
Vec3D vec3d = this.d(1.0F);
|
2011-06-19 07:23:45 +02:00
|
|
|
|
|
|
|
entityfireball.locX = this.locX + vec3d.a * d8;
|
2011-11-30 00:17:43 +01:00
|
|
|
entityfireball.locY = this.locY + (double) (this.length / 2.0F) + 0.5D;
|
2011-06-19 07:23:45 +02:00
|
|
|
entityfireball.locZ = this.locZ + vec3d.c * d8;
|
|
|
|
this.world.addEntity(entityfireball);
|
|
|
|
this.f = -40;
|
|
|
|
}
|
|
|
|
} else if (this.f > 0) {
|
|
|
|
--this.f;
|
|
|
|
}
|
|
|
|
} else {
|
2011-11-20 09:01:14 +01:00
|
|
|
this.V = this.yaw = -((float) Math.atan2(this.motX, this.motZ)) * 180.0F / 3.1415927F;
|
2011-06-19 07:23:45 +02:00
|
|
|
if (this.f > 0) {
|
|
|
|
--this.f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.world.isStatic) {
|
2011-09-24 23:03:31 +02:00
|
|
|
byte b0 = this.datawatcher.getByte(16);
|
2011-06-19 07:23:45 +02:00
|
|
|
byte b1 = (byte) (this.f > 10 ? 1 : 0);
|
|
|
|
|
|
|
|
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) {
|
|
|
|
double d4 = (this.b - this.locX) / d3;
|
|
|
|
double d5 = (this.c - this.locY) / d3;
|
|
|
|
double d6 = (this.d - this.locZ) / d3;
|
|
|
|
AxisAlignedBB axisalignedbb = this.boundingBox.clone();
|
|
|
|
|
|
|
|
for (int i = 1; (double) i < d3; ++i) {
|
|
|
|
axisalignedbb.d(d4, d5, d6);
|
2012-01-12 16:27:39 +01:00
|
|
|
if (this.world.a(this, axisalignedbb).size() > 0) {
|
2011-06-19 07:23:45 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
protected String c_() {
|
2011-06-19 07:23:45 +02:00
|
|
|
return "mob.ghast.moan";
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
protected String m() {
|
2011-06-19 07:23:45 +02:00
|
|
|
return "mob.ghast.scream";
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
protected String n() {
|
2011-06-19 07:23:45 +02:00
|
|
|
return "mob.ghast.death";
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
protected int e() {
|
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
|
|
|
|
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) {
|
|
|
|
loot.add(new CraftItemStack(Item.GHAST_TEAR.id, 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) {
|
|
|
|
loot.add(new CraftItemStack(Item.SULPHUR.id, j));
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
2011-11-27 05:22:24 +01:00
|
|
|
|
|
|
|
CraftEventFactory.callEntityDeathEvent(this, loot);
|
|
|
|
// CraftBukkit end
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected float o() {
|
2011-06-19 07:23:45 +02:00
|
|
|
return 10.0F;
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
public boolean g() {
|
|
|
|
return this.random.nextInt(20) == 0 && super.g() && this.world.difficulty > 0;
|
2011-06-19 07:23:45 +02:00
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
public int p() {
|
2011-06-19 07:23:45 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|