craftbukkit/src/main/java/net/minecraft/server/EntityMonster.java

170 lines
5.1 KiB
Java
Raw Normal View History

2011-01-29 22:50:29 +01:00
package net.minecraft.server;
import org.bukkit.event.entity.EntityTargetEvent; // CraftBukkit
2011-01-29 22:50:29 +01:00
2011-09-15 01:23:52 +01:00
public abstract class EntityMonster extends EntityCreature implements IMonster {
2011-01-29 22:50:29 +01:00
public EntityMonster(World world) {
super(world);
2013-07-01 06:03:00 -05:00
this.b = 5;
2011-01-29 22:50:29 +01:00
}
2013-11-04 07:07:38 -06:00
public void e() {
this.bb();
2013-07-01 06:03:00 -05:00
float f = this.d(1.0F);
2011-01-29 22:50:29 +01:00
if (f > 0.5F) {
2013-07-01 06:03:00 -05:00
this.aV += 2;
2011-01-29 22:50:29 +01:00
}
2013-11-04 07:07:38 -06:00
super.e();
2011-01-29 22:50:29 +01:00
}
2013-11-04 07:07:38 -06:00
public void h() {
super.h();
if (!this.world.isStatic && this.world.difficulty == EnumDifficulty.PEACEFUL) {
this.die();
2011-01-29 22:50:29 +01:00
}
}
2013-11-04 07:07:38 -06:00
protected String H() {
return "game.hostile.swim";
}
protected String O() {
return "game.hostile.swim.splash";
}
protected Entity findTarget() {
EntityHuman entityhuman = this.world.findNearbyVulnerablePlayer(this, 16.0D);
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
return entityhuman != null && this.o(entityhuman) ? entityhuman : null;
2011-01-29 22:50:29 +01:00
}
2013-07-01 06:03:00 -05:00
public boolean damageEntity(DamageSource damagesource, float f) {
2012-11-06 06:05:28 -06:00
if (this.isInvulnerable()) {
return false;
2013-07-01 06:03:00 -05:00
} else if (super.damageEntity(damagesource, f)) {
2011-09-15 17:36:27 +01:00
Entity entity = damagesource.getEntity();
2011-09-15 01:23:52 +01:00
2011-01-29 22:50:29 +01:00
if (this.passenger != entity && this.vehicle != entity) {
if (entity != this) {
2013-03-24 23:22:32 -05:00
// CraftBukkit start - We still need to call events for entities without goals
if (entity != this.target && (this instanceof EntityBlaze || this instanceof EntityEnderman || this instanceof EntitySpider || this instanceof EntityGiantZombie || this instanceof EntitySilverfish)) {
EntityTargetEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetEvent(this, entity, EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY);
if (!event.isCancelled()) {
if (event.getTarget() == null) {
this.target = null;
} else {
this.target = ((org.bukkit.craftbukkit.entity.CraftEntity) event.getTarget()).getHandle();
}
2011-01-29 22:50:29 +01:00
}
} else {
this.target = entity;
2011-01-29 22:50:29 +01:00
}
// CraftBukkit end
}
return true;
} else {
return true;
}
} else {
return false;
}
}
2013-11-04 07:07:38 -06:00
protected String aT() {
return "game.hostile.hurt";
}
protected String aU() {
return "game.hostile.die";
}
protected String o(int i) {
return i > 4 ? "game.hostile.hurt.fall.big" : "game.hostile.hurt.fall.small";
}
2012-11-06 06:05:28 -06:00
public boolean m(Entity entity) {
2013-07-08 19:43:37 -04:00
float f = (float) this.getAttributeInstance(GenericAttributes.e).getValue();
2013-07-01 06:03:00 -05:00
int i = 0;
if (entity instanceof EntityLiving) {
2013-07-01 06:03:00 -05:00
f += EnchantmentManager.a((EntityLiving) this, (EntityLiving) entity);
i += EnchantmentManager.getKnockbackEnchantmentLevel(this, (EntityLiving) entity);
}
2013-07-01 06:03:00 -05:00
boolean flag = entity.damageEntity(DamageSource.mobAttack(this), f);
if (flag) {
2013-07-01 06:03:00 -05:00
if (i > 0) {
entity.g((double) (-MathHelper.sin(this.yaw * 3.1415927F / 180.0F) * (float) i * 0.5F), 0.1D, (double) (MathHelper.cos(this.yaw * 3.1415927F / 180.0F) * (float) i * 0.5F));
this.motX *= 0.6D;
this.motZ *= 0.6D;
}
2013-07-01 06:03:00 -05:00
int j = EnchantmentManager.getFireAspectEnchantmentLevel(this);
2013-07-01 06:03:00 -05:00
if (j > 0) {
entity.setOnFire(j * 4);
}
2012-12-19 22:03:52 -06:00
if (entity instanceof EntityLiving) {
2013-11-04 07:07:38 -06:00
EnchantmentManager.a((EntityLiving) entity, (Entity) this);
2012-12-19 22:03:52 -06:00
}
2013-11-04 07:07:38 -06:00
EnchantmentManager.b(this, entity);
}
return flag;
2011-09-15 01:23:52 +01:00
}
protected void a(Entity entity, float f) {
if (this.attackTicks <= 0 && f < 2.0F && entity.boundingBox.e > this.boundingBox.b && entity.boundingBox.b < this.boundingBox.e) {
this.attackTicks = 20;
2012-11-06 06:05:28 -06:00
this.m(entity);
2011-01-29 22:50:29 +01:00
}
}
2012-01-12 23:10:13 +01:00
public float a(int i, int j, int k) {
2013-11-04 07:07:38 -06:00
return 0.5F - this.world.n(i, j, k);
2011-01-29 22:50:29 +01:00
}
2013-11-04 07:07:38 -06:00
protected boolean j_() {
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
2012-07-29 02:33:13 -05:00
if (this.world.b(EnumSkyBlock.SKY, i, j, k) > this.random.nextInt(32)) {
2011-01-29 22:50:29 +01:00
return false;
} else {
int l = this.world.getLightLevel(i, j, k);
2011-01-29 22:50:29 +01:00
2013-11-04 07:07:38 -06:00
if (this.world.O()) {
int i1 = this.world.j;
2011-04-20 22:47:26 +02:00
this.world.j = 10;
2011-04-20 22:47:26 +02:00
l = this.world.getLightLevel(i, j, k);
this.world.j = i1;
2011-04-20 22:47:26 +02:00
}
2011-11-20 00:01:14 -08:00
return l <= this.random.nextInt(8);
2011-01-29 22:50:29 +01:00
}
}
2011-11-20 00:01:14 -08:00
public boolean canSpawn() {
2013-11-04 07:07:38 -06:00
return this.world.difficulty != EnumDifficulty.PEACEFUL && this.j_() && super.canSpawn();
}
protected void aD() {
super.aD();
this.bc().b(GenericAttributes.e);
}
2013-11-04 07:07:38 -06:00
protected boolean aG() {
return true;
2011-11-20 00:01:14 -08:00
}
2011-01-29 22:50:29 +01:00
}