2011-01-29 22:50:29 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
import org.bukkit.craftbukkit.CraftServer;
|
|
|
|
import org.bukkit.craftbukkit.entity.CraftEntity;
|
|
|
|
|
|
|
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
|
|
|
import org.bukkit.event.entity.EntityTargetEvent;
|
|
|
|
import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
public class EntityMonster extends EntityCreature implements IMonster {
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
protected int damage = 2;
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
public EntityMonster(World world) {
|
|
|
|
super(world);
|
|
|
|
this.health = 20;
|
|
|
|
}
|
|
|
|
|
2011-04-20 22:47:26 +02:00
|
|
|
public void u() {
|
2011-02-23 03:37:56 +01:00
|
|
|
float f = this.c(1.0F);
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (f > 0.5F) {
|
2011-04-20 22:47:26 +02:00
|
|
|
this.au += 2;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
2011-04-20 22:47:26 +02:00
|
|
|
super.u();
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
2011-04-20 22:47:26 +02:00
|
|
|
public void p_() {
|
|
|
|
super.p_();
|
2011-04-20 19:05:14 +02:00
|
|
|
if (this.world.spawnMonsters == 0) {
|
|
|
|
this.die();
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
protected Entity findTarget() {
|
2011-01-29 22:50:29 +01:00
|
|
|
EntityHuman entityhuman = this.world.a(this, 16.0D);
|
|
|
|
|
2011-02-23 03:37:56 +01:00
|
|
|
return entityhuman != null && this.e(entityhuman) ? entityhuman : null;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public boolean damageEntity(Entity entity, int i) {
|
|
|
|
if (super.damageEntity(entity, i)) {
|
2011-01-29 22:50:29 +01:00
|
|
|
if (this.passenger != entity && this.vehicle != entity) {
|
|
|
|
if (entity != this) {
|
|
|
|
// CraftBukkit start
|
2011-02-23 13:56:36 +01:00
|
|
|
CraftServer server = ((WorldServer) this.world).getServer();
|
2011-01-29 22:50:29 +01:00
|
|
|
org.bukkit.entity.Entity bukkitTarget = null;
|
|
|
|
if (entity != null) {
|
|
|
|
bukkitTarget = entity.getBukkitEntity();
|
|
|
|
}
|
2011-02-23 13:56:36 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), bukkitTarget, TargetReason.TARGET_ATTACKED_ENTITY);
|
|
|
|
server.getPluginManager().callEvent(event);
|
2011-02-23 13:56:36 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (!event.isCancelled()) {
|
|
|
|
if (event.getTarget() == null) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.target = null;
|
2011-01-29 22:50:29 +01:00
|
|
|
} else {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.target = ((CraftEntity) event.getTarget()).getHandle();
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void a(Entity entity, float f) {
|
2011-03-31 22:40:00 +02:00
|
|
|
if (this.attackTicks <= 0 && f < 2.0F && entity.boundingBox.e > this.boundingBox.b && entity.boundingBox.b < this.boundingBox.e) {
|
2011-01-29 22:50:29 +01:00
|
|
|
this.attackTicks = 20;
|
2011-02-24 13:49:48 +01:00
|
|
|
// CraftBukkit start - this is still duplicated here and EntityHuman because it's possible for an EntityMonster
|
|
|
|
// to damage another EntityMonster, and we want to catch those events.
|
|
|
|
// This does not fire events for slime attacks, as they're not an EntityMonster.
|
|
|
|
if (entity instanceof EntityLiving && !(entity instanceof EntityHuman)) {
|
2011-01-29 22:50:29 +01:00
|
|
|
CraftServer server = ((WorldServer) this.world).getServer();
|
|
|
|
org.bukkit.entity.Entity damager = this.getBukkitEntity();
|
|
|
|
org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity();
|
|
|
|
DamageCause damageType = EntityDamageEvent.DamageCause.ENTITY_ATTACK;
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(damager, damagee, damageType, this.damage);
|
2011-01-29 22:50:29 +01:00
|
|
|
server.getPluginManager().callEvent(event);
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (!event.isCancelled()) {
|
|
|
|
entity.damageEntity(this, event.getDamage());
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
2011-02-23 13:56:36 +01:00
|
|
|
return;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2011-02-23 13:56:36 +01:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
entity.damageEntity(this, this.damage);
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected float a(int i, int j, int k) {
|
|
|
|
return 0.5F - this.world.l(i, j, k);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b(NBTTagCompound nbttagcompound) {
|
|
|
|
super.b(nbttagcompound);
|
|
|
|
}
|
|
|
|
|
2011-04-20 22:47:26 +02:00
|
|
|
public void a(NBTTagCompound nbttagcompound) {
|
|
|
|
super.a(nbttagcompound);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean d() {
|
2011-04-20 19:05:14 +02:00
|
|
|
int i = MathHelper.floor(this.locX);
|
|
|
|
int j = MathHelper.floor(this.boundingBox.b);
|
|
|
|
int k = MathHelper.floor(this.locZ);
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (this.world.a(EnumSkyBlock.SKY, i, j, k) > this.random.nextInt(32)) {
|
|
|
|
return false;
|
|
|
|
} else {
|
2011-04-20 19:05:14 +02:00
|
|
|
int l = this.world.getLightLevel(i, j, k);
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-04-20 22:47:26 +02:00
|
|
|
if (this.world.u()) {
|
|
|
|
int i1 = this.world.f;
|
|
|
|
|
|
|
|
this.world.f = 10;
|
|
|
|
l = this.world.getLightLevel(i, j, k);
|
|
|
|
this.world.f = i1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return l <= this.random.nextInt(8) && super.d();
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|