2011-01-08 08:40:42 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
import java.util.Calendar;
|
|
|
|
|
2013-03-29 02:18:11 +01:00
|
|
|
//CraftBukkit start
|
|
|
|
import org.bukkit.event.entity.EntityCombustByEntityEvent;
|
|
|
|
import org.bukkit.event.entity.EntityCombustEvent;
|
|
|
|
//CraftBukkit end
|
2011-01-08 08:40:42 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
public class EntityZombie extends EntityMonster {
|
2011-01-08 08:40:42 +01:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
private int d = 0;
|
2013-04-12 01:28:15 +02:00
|
|
|
private int lastTick = MinecraftServer.currentTick; // CraftBukkit
|
2012-10-25 05:53:23 +02:00
|
|
|
|
2011-01-08 08:40:42 +01:00
|
|
|
public EntityZombie(World world) {
|
|
|
|
super(world);
|
2011-01-29 22:50:29 +01:00
|
|
|
this.texture = "/mob/zombie.png";
|
2013-03-13 23:33:27 +01:00
|
|
|
this.bI = 0.23F;
|
2012-07-29 09:33:13 +02:00
|
|
|
this.getNavigation().b(true);
|
2012-03-01 11:49:23 +01:00
|
|
|
this.goalSelector.a(0, new PathfinderGoalFloat(this));
|
|
|
|
this.goalSelector.a(1, new PathfinderGoalBreakDoor(this));
|
2013-03-13 23:33:27 +01:00
|
|
|
this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, EntityHuman.class, this.bI, false));
|
|
|
|
this.goalSelector.a(3, new PathfinderGoalMeleeAttack(this, EntityVillager.class, this.bI, true));
|
|
|
|
this.goalSelector.a(4, new PathfinderGoalMoveTowardsRestriction(this, this.bI));
|
|
|
|
this.goalSelector.a(5, new PathfinderGoalMoveThroughVillage(this, this.bI, false));
|
|
|
|
this.goalSelector.a(6, new PathfinderGoalRandomStroll(this, this.bI));
|
2012-03-01 11:49:23 +01:00
|
|
|
this.goalSelector.a(7, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F));
|
|
|
|
this.goalSelector.a(7, new PathfinderGoalRandomLookaround(this));
|
2013-03-13 23:33:27 +01:00
|
|
|
this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this, true));
|
2012-03-01 11:49:23 +01:00
|
|
|
this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, 16.0F, 0, true));
|
|
|
|
this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntityVillager.class, 16.0F, 0, false));
|
2011-01-08 08:40:42 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
protected int ay() {
|
|
|
|
return 40;
|
|
|
|
}
|
|
|
|
|
|
|
|
public float bE() {
|
|
|
|
return super.bE() * (this.isBaby() ? 1.5F : 1.0F);
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void a() {
|
|
|
|
super.a();
|
|
|
|
this.getDataWatcher().a(12, Byte.valueOf((byte) 0));
|
|
|
|
this.getDataWatcher().a(13, Byte.valueOf((byte) 0));
|
|
|
|
this.getDataWatcher().a(14, Byte.valueOf((byte) 0));
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
public int getMaxHealth() {
|
|
|
|
return 20;
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public int aZ() {
|
|
|
|
int i = super.aZ() + 2;
|
2012-10-25 05:53:23 +02:00
|
|
|
|
|
|
|
if (i > 20) {
|
|
|
|
i = 20;
|
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
protected boolean bh() {
|
2012-03-01 11:49:23 +01:00
|
|
|
return true;
|
2012-01-12 23:10:13 +01:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public boolean isBaby() {
|
|
|
|
return this.getDataWatcher().getByte(12) == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setBaby(boolean flag) {
|
2012-11-05 19:09:40 +01:00
|
|
|
this.getDataWatcher().watch(12, Byte.valueOf((byte) (flag ? 1 : 0))); // CraftBukkit - added flag
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isVillager() {
|
|
|
|
return this.getDataWatcher().getByte(13) == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setVillager(boolean flag) {
|
|
|
|
this.getDataWatcher().watch(13, Byte.valueOf((byte) (flag ? 1 : 0)));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void c() {
|
2012-11-06 13:05:28 +01:00
|
|
|
if (this.world.u() && !this.world.isStatic && !this.isBaby()) {
|
2012-07-29 09:33:13 +02:00
|
|
|
float f = this.c(1.0F);
|
2011-01-08 08:40:42 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (f > 0.5F && this.random.nextFloat() * 30.0F < (f - 0.4F) * 2.0F && this.world.l(MathHelper.floor(this.locX), MathHelper.floor(this.locY), MathHelper.floor(this.locZ))) {
|
2012-10-25 05:53:23 +02:00
|
|
|
boolean flag = true;
|
|
|
|
ItemStack itemstack = this.getEquipment(4);
|
|
|
|
|
|
|
|
if (itemstack != null) {
|
2013-03-13 23:33:27 +01:00
|
|
|
if (itemstack.g()) {
|
|
|
|
itemstack.setData(itemstack.j() + this.random.nextInt(2));
|
|
|
|
if (itemstack.j() >= itemstack.l()) {
|
2012-10-25 05:53:23 +02:00
|
|
|
this.a(itemstack);
|
|
|
|
this.setEquipment(4, (ItemStack) null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
flag = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
// CraftBukkit start
|
|
|
|
EntityCombustEvent event = new EntityCombustEvent(this.getBukkitEntity(), 8);
|
|
|
|
this.world.getServer().getPluginManager().callEvent(event);
|
2011-02-23 13:56:36 +01:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if (!event.isCancelled()) {
|
|
|
|
this.setOnFire(event.getDuration());
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2011-01-10 09:30:34 +01:00
|
|
|
}
|
2011-01-08 08:40:42 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
super.c();
|
2011-01-08 08:40:42 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public void l_() {
|
2012-10-25 05:53:23 +02:00
|
|
|
if (!this.world.isStatic && this.o()) {
|
|
|
|
int i = this.q();
|
|
|
|
|
2013-04-12 01:28:15 +02:00
|
|
|
// CraftBukkit start - Use wall time instead of ticks for villager conversion
|
|
|
|
int elapsedTicks = Math.max(1, MinecraftServer.currentTick - this.lastTick);
|
|
|
|
this.lastTick = MinecraftServer.currentTick;
|
|
|
|
i *= elapsedTicks;
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
this.d -= i;
|
|
|
|
if (this.d <= 0) {
|
|
|
|
this.p();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
super.l_();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean m(Entity entity) {
|
|
|
|
boolean flag = super.m(entity);
|
|
|
|
|
|
|
|
if (flag && this.bG() == null && this.isBurning() && this.random.nextFloat() < (float) this.world.difficulty * 0.3F) {
|
2013-03-29 02:18:11 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
EntityCombustByEntityEvent event = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), 2 * this.world.difficulty);
|
|
|
|
this.world.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (!event.isCancelled()) {
|
|
|
|
entity.setOnFire(event.getDuration());
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2013-03-13 23:33:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return flag;
|
2011-01-08 08:40:42 +01:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public int c(Entity entity) {
|
2013-03-13 23:33:27 +01:00
|
|
|
ItemStack itemstack = this.bG();
|
|
|
|
float f = (float) (this.getMaxHealth() - this.getHealth()) / (float) this.getMaxHealth();
|
|
|
|
int i = 3 + MathHelper.d(f * 4.0F);
|
2012-10-25 05:53:23 +02:00
|
|
|
|
|
|
|
if (itemstack != null) {
|
|
|
|
i += itemstack.a((Entity) this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
protected String bb() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return "mob.zombie.say";
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
protected String bc() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return "mob.zombie.hurt";
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
protected String bd() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return "mob.zombie.death";
|
2011-01-08 08:40:42 +01:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
protected void a(int i, int j, int k, int l) {
|
2012-11-06 13:05:28 +01:00
|
|
|
this.makeSound("mob.zombie.step", 0.15F, 1.0F);
|
2011-01-08 08:40:42 +01:00
|
|
|
}
|
|
|
|
|
2012-01-14 21:03:48 +01:00
|
|
|
protected int getLootId() {
|
2011-09-15 02:23:52 +02:00
|
|
|
return Item.ROTTEN_FLESH.id;
|
2011-01-08 08:40:42 +01:00
|
|
|
}
|
2011-11-20 09:01:14 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public EnumMonsterType getMonsterType() {
|
|
|
|
return EnumMonsterType.UNDEAD;
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
2012-03-01 11:49:23 +01:00
|
|
|
|
2013-03-25 05:22:32 +01:00
|
|
|
// CraftBukkit start - Return rare dropped item instead of dropping it
|
2012-07-29 09:33:13 +02:00
|
|
|
protected ItemStack l(int i) {
|
2012-10-25 05:53:23 +02:00
|
|
|
switch (this.random.nextInt(3)) {
|
2012-07-29 09:33:13 +02:00
|
|
|
case 0:
|
2012-10-25 05:53:23 +02:00
|
|
|
return new ItemStack(Item.IRON_INGOT.id, 1, 0);
|
2012-07-29 09:33:13 +02:00
|
|
|
case 1:
|
2012-10-25 05:53:23 +02:00
|
|
|
return new ItemStack(Item.CARROT.id, 1, 0);
|
2012-07-29 09:33:13 +02:00
|
|
|
case 2:
|
2012-10-25 05:53:23 +02:00
|
|
|
return new ItemStack(Item.POTATO.id, 1, 0);
|
2012-07-29 09:33:13 +02:00
|
|
|
default:
|
|
|
|
return null;
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-21 02:55:45 +01:00
|
|
|
// CraftBukkit end
|
2012-10-25 05:53:23 +02:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
protected void bH() {
|
|
|
|
super.bH();
|
2012-10-25 05:53:23 +02:00
|
|
|
if (this.random.nextFloat() < (this.world.difficulty == 3 ? 0.05F : 0.01F)) {
|
|
|
|
int i = this.random.nextInt(3);
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
this.setEquipment(0, new ItemStack(Item.IRON_SWORD));
|
|
|
|
} else {
|
|
|
|
this.setEquipment(0, new ItemStack(Item.IRON_SPADE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b(NBTTagCompound nbttagcompound) {
|
|
|
|
super.b(nbttagcompound);
|
|
|
|
if (this.isBaby()) {
|
|
|
|
nbttagcompound.setBoolean("IsBaby", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.isVillager()) {
|
|
|
|
nbttagcompound.setBoolean("IsVillager", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
nbttagcompound.setInt("ConversionTime", this.o() ? this.d : -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(NBTTagCompound nbttagcompound) {
|
|
|
|
super.a(nbttagcompound);
|
|
|
|
if (nbttagcompound.getBoolean("IsBaby")) {
|
|
|
|
this.setBaby(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nbttagcompound.getBoolean("IsVillager")) {
|
|
|
|
this.setVillager(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nbttagcompound.hasKey("ConversionTime") && nbttagcompound.getInt("ConversionTime") > -1) {
|
|
|
|
this.a(nbttagcompound.getInt("ConversionTime"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(EntityLiving entityliving) {
|
|
|
|
super.a(entityliving);
|
|
|
|
if (this.world.difficulty >= 2 && entityliving instanceof EntityVillager) {
|
|
|
|
if (this.world.difficulty == 2 && this.random.nextBoolean()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityZombie entityzombie = new EntityZombie(this.world);
|
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
entityzombie.k(entityliving);
|
2012-10-25 05:53:23 +02:00
|
|
|
this.world.kill(entityliving);
|
2013-03-13 23:33:27 +01:00
|
|
|
entityzombie.bJ();
|
2012-10-25 05:53:23 +02:00
|
|
|
entityzombie.setVillager(true);
|
|
|
|
if (entityliving.isBaby()) {
|
|
|
|
entityzombie.setBaby(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.world.addEntity(entityzombie);
|
|
|
|
this.world.a((EntityHuman) null, 1016, (int) this.locX, (int) this.locY, (int) this.locZ, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public void bJ() {
|
|
|
|
this.h(this.random.nextFloat() < au[this.world.difficulty]);
|
2012-10-25 05:53:23 +02:00
|
|
|
if (this.world.random.nextFloat() < 0.05F) {
|
|
|
|
this.setVillager(true);
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
this.bH();
|
|
|
|
this.bI();
|
2012-10-25 05:53:23 +02:00
|
|
|
if (this.getEquipment(4) == null) {
|
2013-03-13 23:33:27 +01:00
|
|
|
Calendar calendar = this.world.U();
|
2012-10-25 05:53:23 +02:00
|
|
|
|
|
|
|
if (calendar.get(2) + 1 == 10 && calendar.get(5) == 31 && this.random.nextFloat() < 0.25F) {
|
|
|
|
this.setEquipment(4, new ItemStack(this.random.nextFloat() < 0.1F ? Block.JACK_O_LANTERN : Block.PUMPKIN));
|
|
|
|
this.dropChances[4] = 0.0F;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public boolean a_(EntityHuman entityhuman) {
|
|
|
|
ItemStack itemstack = entityhuman.cb();
|
2012-10-25 05:53:23 +02:00
|
|
|
|
|
|
|
if (itemstack != null && itemstack.getItem() == Item.GOLDEN_APPLE && itemstack.getData() == 0 && this.isVillager() && this.hasEffect(MobEffectList.WEAKNESS)) {
|
|
|
|
if (!entityhuman.abilities.canInstantlyBuild) {
|
|
|
|
--itemstack.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemstack.count <= 0) {
|
|
|
|
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, (ItemStack) null);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.world.isStatic) {
|
|
|
|
this.a(this.random.nextInt(2401) + 3600);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void a(int i) {
|
|
|
|
this.d = i;
|
|
|
|
this.getDataWatcher().watch(14, Byte.valueOf((byte) 1));
|
|
|
|
this.o(MobEffectList.WEAKNESS.id);
|
|
|
|
this.addEffect(new MobEffect(MobEffectList.INCREASE_DAMAGE.id, i, Math.min(this.world.difficulty - 1, 0)));
|
|
|
|
this.world.broadcastEntityEffect(this, (byte) 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean o() {
|
|
|
|
return this.getDataWatcher().getByte(14) == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void p() {
|
|
|
|
EntityVillager entityvillager = new EntityVillager(this.world);
|
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
entityvillager.k(this);
|
2013-03-13 23:33:27 +01:00
|
|
|
entityvillager.bJ();
|
2012-10-25 05:53:23 +02:00
|
|
|
entityvillager.q();
|
|
|
|
if (this.isBaby()) {
|
|
|
|
entityvillager.setAge(-24000);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.world.kill(this);
|
|
|
|
this.world.addEntity(entityvillager);
|
|
|
|
entityvillager.addEffect(new MobEffect(MobEffectList.CONFUSION.id, 200, 0));
|
|
|
|
this.world.a((EntityHuman) null, 1017, (int) this.locX, (int) this.locY, (int) this.locZ, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected int q() {
|
|
|
|
int i = 1;
|
|
|
|
|
|
|
|
if (this.random.nextFloat() < 0.01F) {
|
|
|
|
int j = 0;
|
|
|
|
|
|
|
|
for (int k = (int) this.locX - 4; k < (int) this.locX + 4 && j < 14; ++k) {
|
|
|
|
for (int l = (int) this.locY - 4; l < (int) this.locY + 4 && j < 14; ++l) {
|
|
|
|
for (int i1 = (int) this.locZ - 4; i1 < (int) this.locZ + 4 && j < 14; ++i1) {
|
|
|
|
int j1 = this.world.getTypeId(k, l, i1);
|
|
|
|
|
|
|
|
if (j1 == Block.IRON_FENCE.id || j1 == Block.BED.id) {
|
|
|
|
if (this.random.nextFloat() < 0.3F) {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
++j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
2011-01-08 08:40:42 +01:00
|
|
|
}
|