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.EntityDamageByEntityEvent;
7import org.bukkit.event.entity.EntityDamageEvent;
8import org.bukkit.event.entity.EntityTargetEvent;
9// CraftBukkit end
10
11public class EntityMonster extends EntityCreature implements IMonster {
12
13 protected int damage = 2;
14
15 public EntityMonster(World world) {
16 super(world);
17 this.health = 20;
18 }
19
20 public void v() {
21 float f = this.c(1.0F);
22
23 if (f > 0.5F) {
24 this.ay += 2;
25 }
26
27 super.v();
28 }
29
30 public void m_() {
31 super.m_();
32 if (!this.world.isStatic && this.world.spawnMonsters == 0) {
33 this.die();
34 }
35 }
36
37 protected Entity findTarget() {
38 EntityHuman entityhuman = this.world.findNearbyPlayer(this, 16.0D);
39
40 return entityhuman != null && this.e(entityhuman) ? entityhuman : null;
41 }
42
43 public boolean damageEntity(Entity entity, int i) {
44 if (super.damageEntity(entity, i)) {
45 if (this.passenger != entity && this.vehicle != entity) {
46 if (entity != this) {
47 // CraftBukkit start
48 org.bukkit.entity.Entity bukkitTarget = entity == null ? null : entity.getBukkitEntity();
49
50 EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), bukkitTarget, EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY);
51 this.world.getServer().getPluginManager().callEvent(event);
52
53 if (!event.isCancelled()) {
54 if (event.getTarget() == null) {
55 this.target = null;
56 } else {
57 this.target = ((CraftEntity) event.getTarget()).getHandle();
58 }
59 }
60 // CraftBukkit end
61 }
62
63 return true;
64 } else {
65 return true;
66 }
67 } else {
68 return false;
69 }
70 }
71
72 protected void a(Entity entity, float f) {
73 if (this.attackTicks <= 0 && f < 2.0F && entity.boundingBox.e > this.boundingBox.b && entity.boundingBox.b < this.boundingBox.e) {
74 this.attackTicks = 20;
75 // CraftBukkit start - this is still duplicated here and EntityHuman because it's possible for lastDamage EntityMonster
76 // to damage another EntityMonster, and we want to catch those events.
77 // This does not fire events for slime attacks, av they're not lastDamage EntityMonster.
78 if (entity instanceof EntityLiving && !(entity instanceof EntityHuman)) {
79 org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity();
80
81 EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(this.getBukkitEntity(), damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK, this.damage);
82 this.world.getServer().getPluginManager().callEvent(event);
83
84 if (!event.isCancelled()) {
85 entity.damageEntity(this, event.getDamage());
86 }
87 return;
88 }
89 // CraftBukkit end
90
91 entity.damageEntity(this, this.damage);
92 }
93 }
94
95 protected float a(int i, int j, int k) {
96 return 0.5F - this.world.n(i, j, k);
97 }
98
99 public void b(NBTTagCompound nbttagcompound) {
100 super.b(nbttagcompound);
101 }
102
103 public void a(NBTTagCompound nbttagcompound) {
104 super.a(nbttagcompound);
105 }
106
107 public boolean d() {
108 int i = MathHelper.floor(this.locX);
109 int j = MathHelper.floor(this.boundingBox.b);
110 int k = MathHelper.floor(this.locZ);
111
112 if (this.world.a(EnumSkyBlock.SKY, i, j, k) > this.random.nextInt(32)) {
113 return false;
114 } else {
115 int l = this.world.getLightLevel(i, j, k);
116
117 if (this.world.u()) {
118 int i1 = this.world.f;
119
120 this.world.f = 10;
121 l = this.world.getLightLevel(i, j, k);
122 this.world.f = i1;
123 }
124
125 return l <= this.random.nextInt(8) && super.d();
126 }
127 }
128}