1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
package net.minecraft.server;
// CraftBukkit start
import java.util.List;
import org.bukkit.Location;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.entity.EndermanPickupEvent;
import org.bukkit.event.entity.EndermanPlaceEvent;
// CraftBukkit end
public class EntityEnderman extends EntityMonster {
private static boolean[] b = new boolean[256];
public boolean a = false;
private int g = 0;
private int h = 0;
public EntityEnderman(World world) {
super(world);
this.texture = "/mob/enderman.png";
this.bb = 0.2F;
this.damage = 7;
this.b(0.6F, 2.9F);
this.bP = 1.0F;
}
public int getMaxHealth() {
return 40;
}
protected void b() {
super.b();
this.datawatcher.a(16, new Byte((byte) 0));
this.datawatcher.a(17, new Byte((byte) 0));
}
public void b(NBTTagCompound nbttagcompound) {
super.b(nbttagcompound);
nbttagcompound.setShort("carried", (short) this.getCarriedId());
nbttagcompound.setShort("carriedData", (short) this.getCarriedData());
}
public void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound);
this.setCarriedId(nbttagcompound.getShort("carried"));
this.setCarriedData(nbttagcompound.getShort("carriedData"));
}
protected Entity findTarget() {
EntityHuman entityhuman = this.world.findNearbyVulnerablePlayer(this, 64.0D);
if (entityhuman != null) {
if (this.c(entityhuman)) {
if (this.h++ == 5) {
this.h = 0;
return entityhuman;
}
} else {
this.h = 0;
}
}
return null;
}
public float a(float f) {
return super.a(f);
}
private boolean c(EntityHuman entityhuman) {
ItemStack itemstack = entityhuman.inventory.armor[3];
if (itemstack != null && itemstack.id == Block.PUMPKIN.id) {
return false;
} else {
Vec3D vec3d = entityhuman.e(1.0F).b();
Vec3D vec3d1 = Vec3D.create(this.locX - entityhuman.locX, this.boundingBox.b + (double) (this.length / 2.0F) - (entityhuman.locY + (double) entityhuman.y()), this.locZ - entityhuman.locZ);
double d0 = vec3d1.c();
vec3d1 = vec3d1.b();
double d1 = vec3d.a(vec3d1);
return d1 > 1.0D - 0.025D / d0 ? entityhuman.g(this) : false;
}
}
public void d() {
if (this.aJ()) {
this.damageEntity(DamageSource.DROWN, 1);
}
this.a = this.target != null;
this.bb = this.target != null ? 6.5F : 0.3F;
int i;
if (!this.world.isStatic) {
int j;
int k;
int l;
if (this.getCarriedId() == 0) {
if (this.random.nextInt(20) == 0) {
i = MathHelper.floor(this.locX - 2.0D + this.random.nextDouble() * 4.0D);
j = MathHelper.floor(this.locY + this.random.nextDouble() * 3.0D);
k = MathHelper.floor(this.locZ - 2.0D + this.random.nextDouble() * 4.0D);
l = this.world.getTypeId(i, j, k);
if (b[l]) {
// CraftBukkit start - pickup event
EndermanPickupEvent pickup = new EndermanPickupEvent(this.getBukkitEntity(), this.world.getWorld().getBlockAt(i, j, k));
this.world.getServer().getPluginManager().callEvent(pickup);
if (!pickup.isCancelled()) {
this.setCarriedId(this.world.getTypeId(i, j, k));
this.setCarriedData(this.world.getData(i, j, k));
this.world.setTypeId(i, j, k, 0);
}
// CraftBukkit end
}
}
} else if (this.random.nextInt(2000) == 0) {
i = MathHelper.floor(this.locX - 1.0D + this.random.nextDouble() * 2.0D);
j = MathHelper.floor(this.locY + this.random.nextDouble() * 2.0D);
k = MathHelper.floor(this.locZ - 1.0D + this.random.nextDouble() * 2.0D);
l = this.world.getTypeId(i, j, k);
int i1 = this.world.getTypeId(i, j - 1, k);
if (l == 0 && i1 > 0 && Block.byId[i1].b()) {
// CraftBukkit start - place event
EndermanPlaceEvent place = new EndermanPlaceEvent(this.getBukkitEntity(), new Location(this.world.getWorld(), i, j, k));
this.world.getServer().getPluginManager().callEvent(place);
if (!place.isCancelled()) {
this.world.setTypeIdAndData(i, j, k, this.getCarriedId(), this.getCarriedData());
this.setCarriedId(0);
}
// CraftBukkit end
}
}
}
for (i = 0; i < 2; ++i) {
this.world.a("portal", this.locX + (this.random.nextDouble() - 0.5D) * (double) this.width, this.locY + this.random.nextDouble() * (double) this.length - 0.25D, this.locZ + (this.random.nextDouble() - 0.5D) * (double) this.width, (this.random.nextDouble() - 0.5D) * 2.0D, -this.random.nextDouble(), (this.random.nextDouble() - 0.5D) * 2.0D);
}
if (this.world.e() && !this.world.isStatic) {
float f = this.a(1.0F);
if (f > 0.5F && this.world.isChunkLoaded(MathHelper.floor(this.locX), MathHelper.floor(this.locY), MathHelper.floor(this.locZ)) && this.random.nextFloat() * 30.0F < (f - 0.4F) * 2.0F) {
this.target = null;
this.w_();
}
}
if (this.aJ()) {
this.target = null;
this.w_();
}
this.aZ = false;
if (this.target != null) {
this.a(this.target, 100.0F, 100.0F);
}
if (!this.world.isStatic && this.isAlive()) {
if (this.target != null) {
if (this.target instanceof EntityHuman && this.c((EntityHuman) this.target)) {
this.aW = this.aX = 0.0F;
this.bb = 0.0F;
if (this.target.i(this) < 16.0D) {
this.w_();
}
this.g = 0;
} else if (this.target.i(this) > 256.0D && this.g++ >= 30 && this.f(this.target)) {
this.g = 0;
}
} else {
this.g = 0;
}
}
super.d();
}
protected boolean w_() {
double d0 = this.locX + (this.random.nextDouble() - 0.5D) * 64.0D;
double d1 = this.locY + (double) (this.random.nextInt(64) - 32);
double d2 = this.locZ + (this.random.nextDouble() - 0.5D) * 64.0D;
return this.b(d0, d1, d2);
}
protected boolean f(Entity entity) {
Vec3D vec3d = Vec3D.create(this.locX - entity.locX, this.boundingBox.b + (double) (this.length / 2.0F) - entity.locY + (double) entity.y(), this.locZ - entity.locZ);
vec3d = vec3d.b();
double d0 = 16.0D;
double d1 = this.locX + (this.random.nextDouble() - 0.5D) * 8.0D - vec3d.a * d0;
double d2 = this.locY + (double) (this.random.nextInt(16) - 8) - vec3d.b * d0;
double d3 = this.locZ + (this.random.nextDouble() - 0.5D) * 8.0D - vec3d.c * d0;
return this.b(d1, d2, d3);
}
protected boolean b(double d0, double d1, double d2) {
double d3 = this.locX;
double d4 = this.locY;
double d5 = this.locZ;
this.locX = d0;
this.locY = d1;
this.locZ = d2;
boolean flag = false;
int i = MathHelper.floor(this.locX);
int j = MathHelper.floor(this.locY);
int k = MathHelper.floor(this.locZ);
int l;
if (this.world.isLoaded(i, j, k)) {
boolean flag1 = false;
while (!flag1 && j > 0) {
l = this.world.getTypeId(i, j - 1, k);
if (l != 0 && Block.byId[l].material.isSolid()) {
flag1 = true;
} else {
--this.locY;
--j;
}
}
if (flag1) {
this.setPosition(this.locX, this.locY, this.locZ);
if (this.world.a((Entity) this, this.boundingBox).size() == 0 && !this.world.c(this.boundingBox)) {
flag = true;
}
}
}
if (!flag) {
this.setPosition(d3, d4, d5);
return false;
} else {
short short1 = 128;
for (l = 0; l < short1; ++l) {
double d6 = (double) l / ((double) short1 - 1.0D);
float f = (this.random.nextFloat() - 0.5F) * 0.2F;
float f1 = (this.random.nextFloat() - 0.5F) * 0.2F;
float f2 = (this.random.nextFloat() - 0.5F) * 0.2F;
double d7 = d3 + (this.locX - d3) * d6 + (this.random.nextDouble() - 0.5D) * (double) this.width * 2.0D;
double d8 = d4 + (this.locY - d4) * d6 + this.random.nextDouble() * (double) this.length;
double d9 = d5 + (this.locZ - d5) * d6 + (this.random.nextDouble() - 0.5D) * (double) this.width * 2.0D;
this.world.a("portal", d7, d8, d9, (double) f, (double) f1, (double) f2);
}
this.world.makeSound(d3, d4, d5, "mob.endermen.portal", 1.0F, 1.0F);
this.world.makeSound(this, "mob.endermen.portal", 1.0F, 1.0F);
return true;
}
}
protected String c_() {
return "mob.endermen.idle";
}
protected String m() {
return "mob.endermen.hit";
}
protected String n() {
return "mob.endermen.death";
}
protected int getLootId() {
return Item.ENDER_PEARL.id;
}
protected void dropDeathLoot(boolean flag, int i) {
int j = this.getLootId();
if (j > 0) {
// CraftBukkit start - whole method
List<org.bukkit.inventory.ItemStack> loot = new java.util.ArrayList<org.bukkit.inventory.ItemStack>();
int count = this.random.nextInt(2 + i);
if ((j > 0) && (count > 0)) {
loot.add(new org.bukkit.inventory.ItemStack(j, count));
}
CraftEventFactory.callEntityDeathEvent(this, loot);
// CraftBukkit end
}
}
public void setCarriedId(int i) {
this.datawatcher.watch(16, Byte.valueOf((byte) (i & 255)));
}
public int getCarriedId() {
return this.datawatcher.getByte(16);
}
public void setCarriedData(int i) {
this.datawatcher.watch(17, Byte.valueOf((byte) (i & 255)));
}
public int getCarriedData() {
return this.datawatcher.getByte(17);
}
public boolean damageEntity(DamageSource damagesource, int i) {
if (damagesource instanceof EntityDamageSourceIndirect) {
for (int j = 0; j < 64; ++j) {
if (this.w_()) {
return true;
}
}
return false;
} else {
return super.damageEntity(damagesource, i);
}
}
static {
b[Block.GRASS.id] = true;
b[Block.DIRT.id] = true;
b[Block.SAND.id] = true;
b[Block.GRAVEL.id] = true;
b[Block.YELLOW_FLOWER.id] = true;
b[Block.RED_ROSE.id] = true;
b[Block.BROWN_MUSHROOM.id] = true;
b[Block.RED_MUSHROOM.id] = true;
b[Block.TNT.id] = true;
b[Block.CACTUS.id] = true;
b[Block.CLAY.id] = true;
b[Block.PUMPKIN.id] = true;
b[Block.MELON.id] = true;
b[Block.MYCEL.id] = true;
}
}
|