Paper/src/main/java/net/minecraft/server/EntityPigZombie.java

142 lines
4.1 KiB
Java
Raw Normal View History

package net.minecraft.server;
import java.util.List;
// CraftBukkit start
2011-01-26 20:26:24 +01:00
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
2011-01-26 20:26:24 +01:00
import org.bukkit.event.entity.EntityTargetEvent;
// CraftBukkit end
public class EntityPigZombie extends EntityZombie {
public int angerLevel = 0; // CraftBukkit - private -> public
private int soundDelay = 0;
2011-09-15 02:23:52 +02:00
private static final ItemStack g = new ItemStack(Item.GOLD_SWORD, 1);
public EntityPigZombie(World world) {
super(world);
2011-01-29 22:50:29 +01:00
this.texture = "/mob/pigzombie.png";
2012-01-12 23:10:13 +01:00
this.bb = 0.5F;
this.damage = 5;
this.fireProof = true;
}
2012-01-12 23:10:13 +01:00
protected boolean as() {
return false;
}
public void y_() {
this.bb = this.target != null ? 0.95F : 0.5F;
if (this.soundDelay > 0 && --this.soundDelay == 0) {
2011-11-20 09:01:14 +01:00
this.world.makeSound(this, "mob.zombiepig.zpigangry", this.o() * 2.0F, ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F) * 1.8F);
}
2011-01-29 22:50:29 +01:00
2012-01-12 23:10:13 +01:00
super.y_();
}
public boolean canSpawn() {
2012-01-12 23:10:13 +01:00
return this.world.difficulty > 0 && this.world.containsEntity(this.boundingBox) && this.world.a((Entity) this, this.boundingBox).size() == 0 && !this.world.c(this.boundingBox);
}
2011-04-20 22:47:26 +02:00
public void b(NBTTagCompound nbttagcompound) {
super.b(nbttagcompound);
nbttagcompound.setShort("Anger", (short) this.angerLevel);
}
2011-04-20 22:47:26 +02:00
public void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound);
this.angerLevel = nbttagcompound.getShort("Anger");
}
protected Entity findTarget() {
return this.angerLevel == 0 ? null : super.findTarget();
}
2011-11-20 09:01:14 +01:00
public void d() {
super.d();
}
2011-09-15 02:23:52 +02:00
public boolean damageEntity(DamageSource damagesource, int 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 (entity instanceof EntityHuman) {
2012-01-12 16:27:39 +01:00
List list = this.world.getEntities(this, this.boundingBox.grow(32.0D, 32.0D, 32.0D));
2011-01-29 22:50:29 +01:00
for (int j = 0; j < list.size(); ++j) {
Entity entity1 = (Entity) list.get(j);
if (entity1 instanceof EntityPigZombie) {
EntityPigZombie entitypigzombie = (EntityPigZombie) entity1;
2011-11-20 09:01:14 +01:00
entitypigzombie.f(entity);
}
}
2011-11-20 09:01:14 +01:00
this.f(entity);
}
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
return super.damageEntity(damagesource, i);
}
2011-11-20 09:01:14 +01:00
private void f(Entity entity) {
2011-01-26 20:26:24 +01:00
// 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.PIG_ZOMBIE_TARGET);
this.world.getServer().getPluginManager().callEvent(event);
2011-02-23 13:56:36 +01:00
if (event.isCancelled()) {
return;
}
if (event.getTarget() == null) {
this.target = null;
return;
2011-01-26 20:26:24 +01:00
}
entity = ((CraftEntity) event.getTarget()).getHandle();
2011-01-26 20:26:24 +01:00
// CraftBukkit end
this.target = entity;
this.angerLevel = 400 + this.random.nextInt(400);
this.soundDelay = this.random.nextInt(40);
}
2011-11-20 09:01:14 +01:00
protected String c_() {
return "mob.zombiepig.zpig";
}
2011-11-20 09:01:14 +01:00
protected String m() {
return "mob.zombiepig.zpighurt";
}
2011-11-20 09:01:14 +01:00
protected String n() {
return "mob.zombiepig.zpigdeath";
}
protected void dropDeathLoot(boolean flag, int i) {
// CraftBukkit start
List<org.bukkit.inventory.ItemStack> loot = new java.util.ArrayList<org.bukkit.inventory.ItemStack>();
2011-11-20 09:01:14 +01:00
int j = this.random.nextInt(2 + i);
int k;
if (j > 0) {
loot.add(new CraftItemStack(Item.ROTTEN_FLESH.id, j));
2011-11-20 09:01:14 +01:00
}
j = this.random.nextInt(2 + i);
if (j > 0) {
loot.add(new CraftItemStack(Item.GOLD_NUGGET.id, j));
2011-11-20 09:01:14 +01:00
}
CraftEventFactory.callEntityDeathEvent(this, loot);
// CraftBukkit end
2011-11-20 09:01:14 +01:00
}
protected int getLootId() {
2011-11-20 09:01:14 +01:00
return Item.ROTTEN_FLESH.id;
}
}