3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-18 22:10:06 +01:00
Paper/src/main/java/net/minecraft/server/EntityMonster.java

150 Zeilen
4.7 KiB
Java

2011-01-29 22:50:29 +01:00
package net.minecraft.server;
// CraftBukkit start
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityTargetEvent;
// CraftBukkit end
2011-09-15 02:23:52 +02:00
public abstract class EntityMonster extends EntityCreature implements IMonster {
2011-01-29 22:50:29 +01:00
protected int damage = 2;
2011-01-29 22:50:29 +01:00
public EntityMonster(World world) {
super(world);
2011-11-20 09:01:14 +01:00
this.az = 5;
2011-01-29 22:50:29 +01:00
}
2011-11-20 09:01:14 +01:00
public void d() {
float f = this.a(1.0F);
2011-01-29 22:50:29 +01:00
if (f > 0.5F) {
2011-11-20 09:01:14 +01:00
this.aS += 2;
2011-01-29 22:50:29 +01:00
}
2011-11-20 09:01:14 +01:00
super.d();
2011-01-29 22:50:29 +01:00
}
2011-11-20 09:01:14 +01:00
public void w_() {
super.w_();
if (!this.world.isStatic && this.world.difficulty == 0) {
this.die();
2011-01-29 22:50:29 +01:00
}
}
protected Entity findTarget() {
2011-11-20 09:01:14 +01:00
EntityHuman entityhuman = this.world.b(this, 16.0D);
2011-01-29 22:50:29 +01:00
2011-11-20 09:01:14 +01:00
return entityhuman != null && this.g(entityhuman) ? entityhuman : null;
2011-01-29 22:50:29 +01:00
}
2011-09-15 02:23:52 +02:00
public boolean damageEntity(DamageSource damagesource, int i) {
if (super.damageEntity(damagesource, i)) {
2011-09-15 18:36:27 +02:00
Entity entity = damagesource.getEntity();
2011-09-15 02:23:52 +02:00
2011-01-29 22:50:29 +01:00
if (this.passenger != entity && this.vehicle != entity) {
if (entity != this) {
// CraftBukkit start
org.bukkit.entity.Entity bukkitTarget = entity == null ? null : entity.getBukkitEntity();
2011-02-23 13:56:36 +01:00
EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), bukkitTarget, EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY);
this.world.getServer().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) {
this.target = null;
2011-01-29 22:50:29 +01:00
} else {
this.target = ((CraftEntity) event.getTarget()).getHandle();
2011-01-29 22:50:29 +01:00
}
}
// CraftBukkit end
}
return true;
} else {
return true;
}
} else {
return false;
}
}
2011-11-20 09:01:14 +01:00
protected boolean d(Entity entity) {
int i = this.damage;
if (this.hasEffect(MobEffectList.INCREASE_DAMAGE)) {
i += 3 << this.getEffect(MobEffectList.INCREASE_DAMAGE).getAmplifier();
}
if (this.hasEffect(MobEffectList.WEAKNESS)) {
i -= 2 << this.getEffect(MobEffectList.WEAKNESS).getAmplifier();
}
2011-09-15 02:23:52 +02:00
// CraftBukkit start - this is still duplicated here and EntityHuman because it's possible for lastDamage EntityMonster
// to damage another EntityMonster, and we want to catch those events.
// This does not fire events for slime attacks, av they're not lastDamage EntityMonster.
if (entity instanceof EntityLiving && !(entity instanceof EntityHuman)) {
org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity();
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(this.getBukkitEntity(), damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK, this.damage);
this.world.getServer().getPluginManager().callEvent(event);
2011-11-20 09:01:14 +01:00
i = event.getDamage();
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
if (!event.isCancelled()) {
2011-11-20 09:01:14 +01:00
return entity.damageEntity(DamageSource.mobAttack(this), i);
2011-01-29 22:50:29 +01:00
}
2011-02-23 13:56:36 +01:00
2011-09-15 02:23:52 +02:00
return false;
}
// CraftBukkit end
2011-11-20 09:01:14 +01:00
return entity.damageEntity(DamageSource.mobAttack(this), i);
2011-09-15 02:23:52 +02: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;
2011-11-20 09:01:14 +01:00
this.d(entity);
2011-01-29 22:50:29 +01:00
}
}
protected float a(int i, int j, int k) {
2011-09-15 02:23:52 +02:00
return 0.5F - this.world.m(i, j, k);
2011-01-29 22:50:29 +01:00
}
public void b(NBTTagCompound nbttagcompound) {
super.b(nbttagcompound);
}
2011-04-20 22:47:26 +02:00
public void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound);
}
2011-11-20 09:01:14 +01:00
protected boolean y() {
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 {
int l = this.world.getLightLevel(i, j, k);
2011-01-29 22:50:29 +01:00
2011-11-20 09:01:14 +01:00
if (this.world.v()) {
2011-09-15 02:23:52 +02:00
int i1 = this.world.k;
2011-04-20 22:47:26 +02:00
2011-09-15 02:23:52 +02:00
this.world.k = 10;
2011-04-20 22:47:26 +02:00
l = this.world.getLightLevel(i, j, k);
2011-09-15 02:23:52 +02:00
this.world.k = i1;
2011-04-20 22:47:26 +02:00
}
2011-11-20 09:01:14 +01:00
return l <= this.random.nextInt(8);
2011-01-29 22:50:29 +01:00
}
}
2011-11-20 09:01:14 +01:00
public boolean g() {
return this.y() && super.g();
}
2011-01-29 22:50:29 +01:00
}