Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package net.minecraft.server;
2
3// CraftBukkit start
4
5import org.bukkit.craftbukkit.entity.CraftEntity;
6import org.bukkit.event.entity.EntityTargetEvent;
7// CraftBukkit end
8
9public class EntityGhast extends EntityFlying implements IMonster {
10
11 public int a = 0;
12 public double b;
13 public double c;
14 public double d;
15 private Entity target = null;
16 private int h = 0;
17 public int e = 0;
18 public int f = 0;
19
20 public EntityGhast(World world) {
21 super(world);
22 this.texture = "/mob/ghast.png";
23 this.b(4.0F, 4.0F);
24 this.fireProof = true;
25 }
26
27 protected void b() {
28 super.b();
29 this.datawatcher.a(16, Byte.valueOf((byte) 0));
30 }
31
32 public void m_() {
33 super.m_();
34 byte b0 = this.datawatcher.a(16);
35
36 this.texture = b0 == 1 ? "/mob/ghast_fire.png" : "/mob/ghast.png";
37 }
38
39 protected void c_() {
40 if (!this.world.isStatic && this.world.spawnMonsters == 0) {
41 this.die();
42 }
43
44 this.U();
45 this.e = this.f;
46 double d0 = this.b - this.locX;
47 double d1 = this.c - this.locY;
48 double d2 = this.d - this.locZ;
49 double d3 = (double) MathHelper.a(d0 * d0 + d1 * d1 + d2 * d2);
50
51 if (d3 < 1.0D || d3 > 60.0D) {
52 this.b = this.locX + (double) ((this.random.nextFloat() * 2.0F - 1.0F) * 16.0F);
53 this.c = this.locY + (double) ((this.random.nextFloat() * 2.0F - 1.0F) * 16.0F);
54 this.d = this.locZ + (double) ((this.random.nextFloat() * 2.0F - 1.0F) * 16.0F);
55 } else if (this.a-- <= 0) {
56 this.a += this.random.nextInt(5) + 2;
57 if (this.a(this.b, this.c, this.d, d3)) {
58 this.motX += d0 / d3 * 0.1D;
59 this.motY += d1 / d3 * 0.1D;
60 this.motZ += d2 / d3 * 0.1D;
61 } else {
62 this.b = this.locX;
63 this.c = this.locY;
64 this.d = this.locZ;
65 }
66 }
67
68 if (this.target != null && this.target.dead) {
69 // CraftBukkit start
70 EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), null, EntityTargetEvent.TargetReason.TARGET_DIED);
71 this.world.getServer().getPluginManager().callEvent(event);
72
73 if (!event.isCancelled()) {
74 if (event.getTarget() == null) {
75 this.target = null;
76 } else {
77 this.target = ((CraftEntity) event.getTarget()).getHandle();
78 }
79 }
80 // CraftBukkit end
81 }
82
83 if (this.target == null || this.h-- <= 0) {
84 // CraftBukkit start
85 Entity target = this.world.findNearbyPlayer(this, 100.0D);
86 if (target != null) {
87 EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), target.getBukkitEntity(), EntityTargetEvent.TargetReason.CLOSEST_PLAYER);
88 this.world.getServer().getPluginManager().callEvent(event);
89
90 if (!event.isCancelled()) {
91 if (event.getTarget() == null) {
92 this.target = null;
93 } else {
94 this.target = ((CraftEntity) event.getTarget()).getHandle();
95 }
96 }
97 }
98 // CraftBukkit end
99 if (this.target != null) {
100 this.h = 20;
101 }
102 }
103
104 double d4 = 64.0D;
105
106 if (this.target != null && this.target.g(this) < d4 * d4) {
107 double d5 = this.target.locX - this.locX;
108 double d6 = this.target.boundingBox.b + (double) (this.target.width / 2.0F) - (this.locY + (double) (this.width / 2.0F));
109 double d7 = this.target.locZ - this.locZ;
110
111 this.K = this.yaw = -((float) Math.atan2(d5, d7)) * 180.0F / 3.1415927F;
112 if (this.e(this.target)) {
113 if (this.f == 10) {
114 this.world.makeSound(this, "mob.ghast.charge", this.k(), (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
115 }
116
117 ++this.f;
118 if (this.f == 20) {
119 this.world.makeSound(this, "mob.ghast.fireball", this.k(), (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
120 EntityFireball entityfireball = new EntityFireball(this.world, this, d5, d6, d7);
121 double d8 = 4.0D;
122 Vec3D vec3d = this.b(1.0F);
123
124 entityfireball.locX = this.locX + vec3d.a * d8;
125 entityfireball.locY = this.locY + (double) (this.width / 2.0F) + 0.5D;
126 entityfireball.locZ = this.locZ + vec3d.c * d8;
127 this.world.addEntity(entityfireball);
128 this.f = -40;
129 }
130 } else if (this.f > 0) {
131 --this.f;
132 }
133 } else {
134 this.K = this.yaw = -((float) Math.atan2(this.motX, this.motZ)) * 180.0F / 3.1415927F;
135 if (this.f > 0) {
136 --this.f;
137 }
138 }
139
140 if (!this.world.isStatic) {
141 byte b0 = this.datawatcher.a(16);
142 byte b1 = (byte) (this.f > 10 ? 1 : 0);
143
144 if (b0 != b1) {
145 this.datawatcher.watch(16, Byte.valueOf(b1));
146 }
147 }
148 }
149
150 private boolean a(double d0, double d1, double d2, double d3) {
151 double d4 = (this.b - this.locX) / d3;
152 double d5 = (this.c - this.locY) / d3;
153 double d6 = (this.d - this.locZ) / d3;
154 AxisAlignedBB axisalignedbb = this.boundingBox.clone();
155
156 for (int i = 1; (double) i < d3; ++i) {
157 axisalignedbb.d(d4, d5, d6);
158 if (this.world.getEntities(this, axisalignedbb).size() > 0) {
159 return false;
160 }
161 }
162
163 return true;
164 }
165
166 protected String g() {
167 return "mob.ghast.moan";
168 }
169
170 protected String h() {
171 return "mob.ghast.scream";
172 }
173
174 protected String i() {
175 return "mob.ghast.death";
176 }
177
178 protected int j() {
179 return Item.SULPHUR.id;
180 }
181
182 protected float k() {
183 return 10.0F;
184 }
185
186 public boolean d() {
187 return this.random.nextInt(20) == 0 && super.d() && this.world.spawnMonsters > 0;
188 }
189
190 public int l() {
191 return 1;
192 }
193}