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

1153 Zeilen
36 KiB
Java

2011-01-29 22:50:29 +01:00
package net.minecraft.server;
2011-03-31 22:40:00 +02:00
import java.util.Iterator;
2011-01-29 22:50:29 +01:00
import java.util.List;
// CraftBukkit start
2011-02-22 01:43:12 +01:00
import org.bukkit.craftbukkit.entity.CraftItem;
import org.bukkit.craftbukkit.TrigMath;
2011-02-11 22:49:51 +01:00
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
2011-01-29 22:50:29 +01:00
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityTargetEvent;
2011-04-07 20:26:51 +02:00
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent;
2011-02-11 22:49:51 +01:00
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
2011-01-29 22:50:29 +01:00
// CraftBukkit end
public abstract class EntityHuman extends EntityLiving {
public InventoryPlayer inventory = new InventoryPlayer(this);
public Container defaultContainer;
public Container activeContainer;
2011-09-15 18:36:27 +02:00
protected FoodMetaData foodData = new FoodMetaData();
2011-09-15 02:23:52 +02:00
protected int n = 0;
public byte o = 0;
public int p = 0;
public float q;
public float r;
public boolean s = false;
public int t = 0;
2011-01-29 22:50:29 +01:00
public String name;
public int dimension;
2011-09-15 02:23:52 +02:00
public int w = 0;
2011-02-23 03:37:56 +01:00
public double x;
public double y;
2011-09-15 02:23:52 +02:00
public double z;
public double A;
public double B;
public double C;
2011-04-07 20:26:51 +02:00
// CraftBukkit start
public boolean sleeping;
public boolean fauxSleeping;
2011-06-09 15:44:25 +02:00
public String spawnWorld = "";
2011-09-15 02:23:52 +02:00
public int sleepTicks;
2011-04-07 20:26:51 +02:00
// CraftBukkit end
2011-09-15 02:23:52 +02:00
public ChunkCoordinates E;
public float F;
public float G;
2011-05-28 22:50:08 +02:00
private ChunkCoordinates b;
2011-04-20 22:47:26 +02:00
private ChunkCoordinates c;
2011-09-15 02:23:52 +02:00
public int H = 20;
protected boolean I = false;
public float J;
2011-09-15 18:36:27 +02:00
public PlayerAbilities abilities = new PlayerAbilities();
2011-09-15 02:23:52 +02:00
public int exp;
public int expLevel;
public int expTotal;
private ItemStack d;
private int e;
protected float O = 0.1F;
protected float P = 0.02F;
private int f = 0;
2011-01-29 22:50:29 +01:00
public EntityFish hookedFish = null;
public EntityHuman(World world) {
super(world);
this.defaultContainer = new ContainerPlayer(this.inventory, !world.isStatic);
this.activeContainer = this.defaultContainer;
this.height = 1.62F;
ChunkCoordinates chunkcoordinates = world.getSpawn();
2011-02-23 03:37:56 +01:00
this.setPositionRotation((double) chunkcoordinates.x + 0.5D, (double) (chunkcoordinates.y + 1), (double) chunkcoordinates.z + 0.5D, 0.0F, 0.0F);
2011-01-29 22:50:29 +01:00
this.health = 20;
2011-09-15 02:23:52 +02:00
this.ae = "humanoid";
this.ad = 180.0F;
2011-01-29 22:50:29 +01:00
this.maxFireTicks = 20;
this.texture = "/mob/char.png";
}
2011-04-20 22:47:26 +02:00
protected void b() {
super.b();
2011-02-23 03:37:56 +01:00
this.datawatcher.a(16, Byte.valueOf((byte) 0));
2011-09-15 02:23:52 +02:00
this.datawatcher.a(17, Byte.valueOf((byte) 0));
}
public boolean o_() {
return this.d != null;
}
public void E() {
if (this.d != null) {
this.d.a(this.world, this, this.e);
}
this.F();
2011-02-23 03:37:56 +01:00
}
2011-09-15 02:23:52 +02:00
public void F() {
this.d = null;
this.e = 0;
if (!this.world.isStatic) {
this.h(false);
}
}
public boolean G() {
return this.o_() && Item.byId[this.d.id].b(this.d) == EnumAnimation.c;
}
public void s_() {
if (this.d != null) {
ItemStack itemstack = this.inventory.getItemInHand();
if (itemstack != this.d) {
this.F();
} else {
if (this.e <= 25 && this.e % 4 == 0) {
this.b(itemstack, 5);
}
if (--this.e == 0 && !this.world.isStatic) {
this.C();
}
}
}
if (this.w > 0) {
--this.w;
}
if (this.isSleeping()) {
2011-02-23 03:37:56 +01:00
++this.sleepTicks;
if (this.sleepTicks > 100) {
this.sleepTicks = 100;
}
2011-05-31 15:55:45 +02:00
if (!this.world.isStatic) {
2011-09-15 02:23:52 +02:00
if (!this.w()) {
2011-05-31 15:55:45 +02:00
this.a(true, true, false);
} else if (this.world.d()) {
this.a(false, true, true);
}
2011-02-23 03:37:56 +01:00
}
} else if (this.sleepTicks > 0) {
++this.sleepTicks;
if (this.sleepTicks >= 110) {
this.sleepTicks = 0;
}
}
2011-09-15 02:23:52 +02:00
super.s_();
2011-01-29 22:50:29 +01:00
if (!this.world.isStatic && this.activeContainer != null && !this.activeContainer.b(this)) {
2011-09-15 02:23:52 +02:00
this.x();
2011-01-29 22:50:29 +01:00
this.activeContainer = this.defaultContainer;
}
2011-09-15 18:36:27 +02:00
if (this.abilities.isFlying) {
2011-09-15 02:23:52 +02:00
for (int i = 0; i < 8; ++i) {
;
}
}
2011-09-15 18:36:27 +02:00
if (this.fireTicks > 0 && this.abilities.isInvulnerable) {
2011-09-15 02:23:52 +02:00
this.fireTicks = 0;
}
this.x = this.A;
this.y = this.B;
this.z = this.C;
double d0 = this.locX - this.A;
double d1 = this.locY - this.B;
double d2 = this.locZ - this.C;
2011-01-29 22:50:29 +01:00
double d3 = 10.0D;
if (d0 > d3) {
2011-09-15 02:23:52 +02:00
this.x = this.A = this.locX;
2011-01-29 22:50:29 +01:00
}
if (d2 > d3) {
2011-09-15 02:23:52 +02:00
this.z = this.C = this.locZ;
2011-01-29 22:50:29 +01:00
}
if (d1 > d3) {
2011-09-15 02:23:52 +02:00
this.y = this.B = this.locY;
2011-01-29 22:50:29 +01:00
}
if (d0 < -d3) {
2011-09-15 02:23:52 +02:00
this.x = this.A = this.locX;
2011-01-29 22:50:29 +01:00
}
if (d2 < -d3) {
2011-09-15 02:23:52 +02:00
this.z = this.C = this.locZ;
2011-01-29 22:50:29 +01:00
}
if (d1 < -d3) {
2011-09-15 02:23:52 +02:00
this.y = this.B = this.locY;
2011-01-29 22:50:29 +01:00
}
2011-09-15 02:23:52 +02:00
this.A += d0 * 0.25D;
this.C += d2 * 0.25D;
this.B += d1 * 0.25D;
2011-04-20 22:47:26 +02:00
this.a(StatisticList.k, 1);
if (this.vehicle == null) {
2011-05-28 22:50:08 +02:00
this.c = null;
2011-04-20 22:47:26 +02:00
}
2011-09-15 02:23:52 +02:00
if (!this.world.isStatic) {
2011-09-15 18:36:27 +02:00
this.foodData.a(this);
2011-09-15 02:23:52 +02:00
}
}
protected void b(ItemStack itemstack, int i) {
if (itemstack.m() == EnumAnimation.b) {
for (int j = 0; j < i; ++j) {
Vec3D vec3d = Vec3D.create(((double) this.random.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D);
vec3d.a(-this.pitch * 3.1415927F / 180.0F);
vec3d.b(-this.yaw * 3.1415927F / 180.0F);
Vec3D vec3d1 = Vec3D.create(((double) this.random.nextFloat() - 0.5D) * 0.3D, (double) (-this.random.nextFloat()) * 0.6D - 0.3D, 0.6D);
vec3d1.a(-this.pitch * 3.1415927F / 180.0F);
vec3d1.b(-this.yaw * 3.1415927F / 180.0F);
vec3d1 = vec3d1.add(this.locX, this.locY + (double) this.t(), this.locZ);
this.world.a("iconcrack_" + itemstack.getItem().id, vec3d1.a, vec3d1.b, vec3d1.c, vec3d.a, vec3d.b + 0.05D, vec3d.c);
}
this.world.makeSound(this, "mob.eat", 0.5F + 0.5F * (float) this.random.nextInt(2), (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
}
2011-02-23 03:37:56 +01:00
}
2011-09-15 02:23:52 +02:00
protected void C() {
if (this.d != null) {
this.b(this.d, 16);
int i = this.d.count;
ItemStack itemstack = this.d.b(this.world, this);
if (itemstack != this.d || itemstack != null && itemstack.count != i) {
this.inventory.items[this.inventory.itemInHandIndex] = itemstack;
if (itemstack.count == 0) {
this.inventory.items[this.inventory.itemInHandIndex] = null;
}
}
this.F();
}
}
protected boolean H() {
return this.health <= 0 || this.isSleeping();
2011-01-29 22:50:29 +01:00
}
2011-09-15 02:23:52 +02:00
protected void x() {
2011-01-29 22:50:29 +01:00
this.activeContainer = this.defaultContainer;
}
2011-09-15 02:23:52 +02:00
public void I() {
2011-04-20 22:47:26 +02:00
double d0 = this.locX;
double d1 = this.locY;
double d2 = this.locZ;
2011-09-15 02:23:52 +02:00
super.I();
this.q = this.r;
this.r = 0.0F;
this.h(this.locX - d0, this.locY - d1, this.locZ - d2);
}
private int o() {
return this.a(MobEffectList.e) ? 6 - (1 + this.b(MobEffectList.e).c()) * 1 : (this.a(MobEffectList.f) ? 6 + (1 + this.b(MobEffectList.f).c()) * 2 : 6);
2011-01-29 22:50:29 +01:00
}
2011-02-23 03:37:56 +01:00
protected void c_() {
2011-09-15 02:23:52 +02:00
int i = this.o();
if (this.s) {
++this.t;
if (this.t >= i) {
this.t = 0;
this.s = false;
2011-01-29 22:50:29 +01:00
}
} else {
2011-09-15 02:23:52 +02:00
this.t = 0;
2011-01-29 22:50:29 +01:00
}
2011-09-15 02:23:52 +02:00
this.am = (float) this.t / (float) i;
2011-01-29 22:50:29 +01:00
}
2011-09-15 02:23:52 +02:00
public void s() {
if (this.n > 0) {
--this.n;
}
if (this.world.spawnMonsters == 0 && this.health < 20 && this.ticksLived % 20 * 12 == 0) {
// CraftBukkit - added regain reason of "REGEN" for filtering purposes.
2011-09-15 02:23:52 +02:00
this.c(1, RegainReason.REGEN);
}
this.inventory.h();
this.q = this.r;
super.s();
this.aj = this.O;
this.ak = this.P;
if (this.at()) {
this.aj = (float) ((double) this.aj + (double) this.O * 0.3D);
this.ak = (float) ((double) this.ak + (double) this.P * 0.3D);
2011-01-29 22:50:29 +01:00
}
float f = MathHelper.a(this.motX * this.motX + this.motZ * this.motZ);
2011-05-14 16:29:42 +02:00
// CraftBukkit - Math -> TrigMath
2011-02-23 13:56:36 +01:00
float f1 = (float) TrigMath.atan(-this.motY * 0.20000000298023224D) * 15.0F;
2011-01-29 22:50:29 +01:00
if (f > 0.1F) {
f = 0.1F;
}
if (!this.onGround || this.health <= 0) {
f = 0.0F;
}
if (this.onGround || this.health <= 0) {
f1 = 0.0F;
}
2011-09-15 02:23:52 +02:00
this.r += (f - this.r) * 0.4F;
this.av += (f1 - this.av) * 0.8F;
2011-01-29 22:50:29 +01:00
if (this.health > 0) {
List list = this.world.b((Entity) this, this.boundingBox.b(1.0D, 0.0D, 1.0D));
if (list != null) {
for (int i = 0; i < list.size(); ++i) {
Entity entity = (Entity) list.get(i);
if (!entity.dead) {
2011-09-15 02:23:52 +02:00
this.j(entity);
2011-01-29 22:50:29 +01:00
}
}
}
}
}
2011-09-15 02:23:52 +02:00
private void j(Entity entity) {
entity.a_(this);
2011-01-29 22:50:29 +01:00
}
2011-09-15 02:23:52 +02:00
public void die(DamageSource damagesource) {
super.die(damagesource);
2011-03-31 22:40:00 +02:00
this.b(0.2F, 0.2F);
this.setPosition(this.locX, this.locY, this.locZ);
2011-01-29 22:50:29 +01:00
this.motY = 0.10000000149011612D;
if (this.name.equals("Notch")) {
this.a(new ItemStack(Item.APPLE, 1), true);
}
2011-09-15 02:23:52 +02:00
this.inventory.j();
if (damagesource != null) {
this.motX = (double) (-MathHelper.cos((this.ar + this.yaw) * 3.1415927F / 180.0F) * 0.1F);
this.motZ = (double) (-MathHelper.sin((this.ar + this.yaw) * 3.1415927F / 180.0F) * 0.1F);
2011-01-29 22:50:29 +01:00
} else {
this.motX = this.motZ = 0.0D;
}
this.height = 0.1F;
2011-04-20 22:47:26 +02:00
this.a(StatisticList.y, 1);
2011-01-29 22:50:29 +01:00
}
2011-09-15 02:23:52 +02:00
public void b(Entity entity, int i) {
this.p += i;
2011-03-31 22:40:00 +02:00
if (entity instanceof EntityHuman) {
2011-04-20 22:47:26 +02:00
this.a(StatisticList.A, 1);
2011-03-31 22:40:00 +02:00
} else {
2011-04-20 22:47:26 +02:00
this.a(StatisticList.z, 1);
2011-03-31 22:40:00 +02:00
}
2011-01-29 22:50:29 +01:00
}
2011-09-15 02:23:52 +02:00
public void J() {
this.a(this.inventory.splitStack(this.inventory.itemInHandIndex, 1), false);
2011-01-29 22:50:29 +01:00
}
public void b(ItemStack itemstack) {
this.a(itemstack, false);
}
public void a(ItemStack itemstack, boolean flag) {
if (itemstack != null) {
2011-06-30 00:02:25 +02:00
EntityItem entityitem = new EntityItem(this.world, this.locX, this.locY - 0.30000001192092896D + (double) this.t(), this.locZ, itemstack);
2011-01-29 22:50:29 +01:00
entityitem.pickupDelay = 40;
2011-01-29 22:50:29 +01:00
float f = 0.1F;
float f1;
if (flag) {
f1 = this.random.nextFloat() * 0.5F;
float f2 = this.random.nextFloat() * 3.1415927F * 2.0F;
entityitem.motX = (double) (-MathHelper.sin(f2) * f1);
entityitem.motZ = (double) (MathHelper.cos(f2) * f1);
2011-01-29 22:50:29 +01:00
entityitem.motY = 0.20000000298023224D;
} else {
f = 0.3F;
entityitem.motX = (double) (-MathHelper.sin(this.yaw / 180.0F * 3.1415927F) * MathHelper.cos(this.pitch / 180.0F * 3.1415927F) * f);
entityitem.motZ = (double) (MathHelper.cos(this.yaw / 180.0F * 3.1415927F) * MathHelper.cos(this.pitch / 180.0F * 3.1415927F) * f);
entityitem.motY = (double) (-MathHelper.sin(this.pitch / 180.0F * 3.1415927F) * f + 0.1F);
2011-01-29 22:50:29 +01:00
f = 0.02F;
f1 = this.random.nextFloat() * 3.1415927F * 2.0F;
f *= this.random.nextFloat();
entityitem.motX += Math.cos((double) f1) * (double) f;
entityitem.motY += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F);
entityitem.motZ += Math.sin((double) f1) * (double) f;
}
2011-02-11 22:49:51 +01:00
// CraftBukkit start
2011-02-23 13:56:36 +01:00
Player player = (Player) this.getBukkitEntity();
CraftItem drop = new CraftItem(this.world.getServer(), entityitem);
2011-02-23 13:56:36 +01:00
2011-02-11 22:49:51 +01:00
PlayerDropItemEvent event = new PlayerDropItemEvent(player, drop);
this.world.getServer().getPluginManager().callEvent(event);
2011-02-11 22:49:51 +01:00
if (event.isCancelled()) {
2011-08-23 20:38:49 +02:00
player.getInventory().addItem(drop.getItemStack());
2011-02-11 22:49:51 +01:00
return;
}
// CraftBukkit end
2011-01-29 22:50:29 +01:00
this.a(entityitem);
2011-04-20 22:47:26 +02:00
this.a(StatisticList.v, 1);
2011-01-29 22:50:29 +01:00
}
}
protected void a(EntityItem entityitem) {
this.world.addEntity(entityitem);
2011-01-29 22:50:29 +01:00
}
public float a(Block block) {
float f = this.inventory.a(block);
if (this.a(Material.WATER)) {
f /= 5.0F;
}
if (!this.onGround) {
f /= 5.0F;
}
2011-09-15 02:23:52 +02:00
if (this.a(MobEffectList.e)) {
f *= 1.0F + (float) (this.b(MobEffectList.e).c() + 1) * 0.2F;
}
if (this.a(MobEffectList.f)) {
f *= 1.0F - (float) (this.b(MobEffectList.f).c() + 1) * 0.2F;
}
2011-01-29 22:50:29 +01:00
return f;
}
public boolean b(Block block) {
return this.inventory.b(block);
}
2011-04-20 22:47:26 +02:00
public void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound);
2011-02-23 03:37:56 +01:00
NBTTagList nbttaglist = nbttagcompound.l("Inventory");
2011-01-29 22:50:29 +01:00
this.inventory.b(nbttaglist);
2011-02-23 03:37:56 +01:00
this.dimension = nbttagcompound.e("Dimension");
this.sleeping = nbttagcompound.m("Sleeping");
this.sleepTicks = nbttagcompound.d("SleepTimer");
2011-09-15 02:23:52 +02:00
this.exp = nbttagcompound.e("Xp");
this.expLevel = nbttagcompound.e("XpLevel");
this.expTotal = nbttagcompound.e("XpTotal");
2011-02-23 03:37:56 +01:00
if (this.sleeping) {
2011-09-15 02:23:52 +02:00
this.E = new ChunkCoordinates(MathHelper.floor(this.locX), MathHelper.floor(this.locY), MathHelper.floor(this.locZ));
2011-03-31 22:40:00 +02:00
this.a(true, true, false);
}
// CraftBukkit start
this.spawnWorld = nbttagcompound.getString("SpawnWorld");
if (this.spawnWorld == "") {
this.spawnWorld = this.world.getServer().getWorlds().get(0).getName();
}
// CraftBukkit end
2011-06-08 19:40:40 +02:00
if (nbttagcompound.hasKey("SpawnX") && nbttagcompound.hasKey("SpawnY") && nbttagcompound.hasKey("SpawnZ")) {
2011-05-28 22:50:08 +02:00
this.b = new ChunkCoordinates(nbttagcompound.e("SpawnX"), nbttagcompound.e("SpawnY"), nbttagcompound.e("SpawnZ"));
2011-02-23 03:37:56 +01:00
}
2011-09-15 02:23:52 +02:00
2011-09-15 18:36:27 +02:00
this.foodData.a(nbttagcompound);
2011-01-29 22:50:29 +01:00
}
2011-04-20 22:47:26 +02:00
public void b(NBTTagCompound nbttagcompound) {
super.b(nbttagcompound);
2011-01-29 22:50:29 +01:00
nbttagcompound.a("Inventory", (NBTBase) this.inventory.a(new NBTTagList()));
nbttagcompound.a("Dimension", this.dimension);
2011-02-23 03:37:56 +01:00
nbttagcompound.a("Sleeping", this.sleeping);
nbttagcompound.a("SleepTimer", (short) this.sleepTicks);
2011-09-15 02:23:52 +02:00
nbttagcompound.a("Xp", this.exp);
nbttagcompound.a("XpLevel", this.expLevel);
nbttagcompound.a("XpTotal", this.expTotal);
2011-05-28 22:50:08 +02:00
if (this.b != null) {
nbttagcompound.a("SpawnX", this.b.x);
nbttagcompound.a("SpawnY", this.b.y);
nbttagcompound.a("SpawnZ", this.b.z);
2011-03-31 22:40:00 +02:00
}
2011-09-15 02:23:52 +02:00
2011-09-15 18:36:27 +02:00
this.foodData.b(nbttagcompound);
2011-01-29 22:50:29 +01:00
}
public void a(IInventory iinventory) {}
2011-02-23 03:37:56 +01:00
public void b(int i, int j, int k) {}
2011-01-29 22:50:29 +01:00
public void receive(Entity entity, int i) {}
2011-01-29 22:50:29 +01:00
2011-06-30 00:02:25 +02:00
public float t() {
2011-01-29 22:50:29 +01:00
return 0.12F;
}
2011-09-15 02:23:52 +02:00
protected void m_() {
2011-02-23 03:37:56 +01:00
this.height = 1.62F;
}
2011-09-15 02:23:52 +02:00
public boolean damageEntity(DamageSource damagesource, int i) {
2011-09-15 18:36:27 +02:00
if (this.abilities.isInvulnerable && !damagesource.ignoresInvulnerability()) {
2011-01-29 22:50:29 +01:00
return false;
} else {
2011-09-15 02:23:52 +02:00
this.aO = 0;
if (this.health <= 0) {
return false;
} else {
if (this.isSleeping() && !this.world.isStatic) {
this.a(true, true, false);
2011-01-29 22:50:29 +01:00
}
2011-09-15 18:36:27 +02:00
Entity entity = damagesource.getEntity();
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
if (entity instanceof EntityMonster || entity instanceof EntityArrow) {
if (this.world.spawnMonsters == 0) {
i = 0;
}
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
if (this.world.spawnMonsters == 1) {
i = i / 3 + 1;
}
2011-09-15 02:23:52 +02:00
if (this.world.spawnMonsters == 3) {
i = i * 3 / 2;
}
2011-05-26 14:48:22 +02:00
}
2011-09-15 02:23:52 +02:00
if (i == 0) {
return false;
} else {
Entity entity1 = entity;
2011-09-15 02:23:52 +02:00
if (entity instanceof EntityArrow && ((EntityArrow) entity).shooter != null) {
entity1 = ((EntityArrow) entity).shooter;
}
2011-03-31 22:40:00 +02:00
2011-09-15 02:23:52 +02:00
if (entity1 instanceof EntityLiving) {
// CraftBukkit start - this is here instead of EntityMonster because EntityLiving(s) that aren't monsters
// also damage the player in this way. For example, EntitySlime.
// We handle projectiles in their individual classes!
if (!(entity.getBukkitEntity() instanceof Projectile)) {
org.bukkit.entity.Entity damager = ((Entity) entity1).getBukkitEntity();
org.bukkit.entity.Entity damagee = this.getBukkitEntity();
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK, i);
this.world.getServer().getPluginManager().callEvent(event);
2011-09-15 02:23:52 +02:00
if (event.isCancelled() || event.getDamage() == 0) {
return false;
}
i = event.getDamage();
}
2011-09-15 02:23:52 +02:00
// CraftBukkit end
2011-03-31 22:40:00 +02:00
2011-09-15 02:23:52 +02:00
this.a((EntityLiving) entity1, false);
}
2011-03-31 22:40:00 +02:00
2011-09-15 02:23:52 +02:00
this.a(StatisticList.x, i);
return super.damageEntity(damagesource, i);
2011-03-31 22:40:00 +02:00
}
}
}
}
2011-09-15 02:23:52 +02:00
protected boolean n_() {
2011-04-20 22:47:26 +02:00
return false;
}
2011-03-31 22:40:00 +02:00
protected void a(EntityLiving entityliving, boolean flag) {
if (!(entityliving instanceof EntityCreeper) && !(entityliving instanceof EntityGhast)) {
if (entityliving instanceof EntityWolf) {
EntityWolf entitywolf = (EntityWolf) entityliving;
if (entitywolf.isTamed() && this.name.equals(entitywolf.getOwnerName())) {
2011-03-31 22:40:00 +02:00
return;
}
}
2011-09-15 02:23:52 +02:00
if (!(entityliving instanceof EntityHuman) || this.n_()) {
2011-04-20 22:47:26 +02:00
List list = this.world.a(EntityWolf.class, AxisAlignedBB.b(this.locX, this.locY, this.locZ, this.locX + 1.0D, this.locY + 1.0D, this.locZ + 1.0D).b(16.0D, 4.0D, 16.0D));
Iterator iterator = list.iterator();
2011-03-31 22:40:00 +02:00
2011-04-20 22:47:26 +02:00
while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next();
EntityWolf entitywolf1 = (EntityWolf) entity;
2011-03-31 22:40:00 +02:00
2011-09-15 02:23:52 +02:00
if (entitywolf1.isTamed() && entitywolf1.C() == null && this.name.equals(entitywolf1.getOwnerName()) && (!flag || !entitywolf1.isSitting())) {
// CraftBukkit start
org.bukkit.entity.Entity bukkitTarget = entity == null ? null : entityliving.getBukkitEntity();
EntityTargetEvent event;
if (flag) {
event = new EntityTargetEvent(entitywolf1.getBukkitEntity(), bukkitTarget, EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET);
} else {
event = new EntityTargetEvent(entitywolf1.getBukkitEntity(), bukkitTarget, EntityTargetEvent.TargetReason.TARGET_ATTACKED_OWNER);
}
this.world.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
continue;
}
// CraftBukkit end
entitywolf1.setSitting(false);
entitywolf1.setTarget(entityliving);
2011-04-20 22:47:26 +02:00
}
2011-03-31 22:40:00 +02:00
}
}
2011-01-29 22:50:29 +01:00
}
}
2011-09-15 02:23:52 +02:00
protected void b(DamageSource damagesource, int i) {
2011-09-15 18:36:27 +02:00
if (!damagesource.ignoresArmor() && this.G()) {
2011-09-15 02:23:52 +02:00
i = 1 + i >> 1;
}
2011-09-15 18:36:27 +02:00
if (!damagesource.ignoresArmor()) {
2011-09-15 02:23:52 +02:00
int j = 25 - this.inventory.i();
int k = i * j + this.f;
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
this.inventory.d(i);
i = k / 25;
this.f = k % 25;
}
this.b(damagesource.c());
super.b(damagesource, i);
2011-01-29 22:50:29 +01:00
}
public void a(TileEntityFurnace tileentityfurnace) {}
public void a(TileEntityDispenser tileentitydispenser) {}
public void a(TileEntitySign tileentitysign) {}
2011-02-23 03:37:56 +01:00
public void c(Entity entity) {
2011-09-15 02:23:52 +02:00
if (!entity.b(this)) {
ItemStack itemstack = this.K();
2011-01-29 22:50:29 +01:00
if (itemstack != null && entity instanceof EntityLiving) {
2011-03-31 22:40:00 +02:00
itemstack.a((EntityLiving) entity);
// CraftBukkit - bypass infinite items; <= 0 -> == 0
if (itemstack.count == 0) {
2011-01-29 22:50:29 +01:00
itemstack.a(this);
2011-09-15 02:23:52 +02:00
this.L();
2011-01-29 22:50:29 +01:00
}
}
}
}
2011-09-15 02:23:52 +02:00
public ItemStack K() {
return this.inventory.getItemInHand();
2011-01-29 22:50:29 +01:00
}
2011-09-15 02:23:52 +02:00
public void L() {
this.inventory.setItem(this.inventory.itemInHandIndex, (ItemStack) null);
2011-01-29 22:50:29 +01:00
}
2011-09-15 02:23:52 +02:00
public double M() {
2011-01-29 22:50:29 +01:00
return (double) (this.height - 0.5F);
}
2011-09-15 02:23:52 +02:00
public void v() {
if (!this.s || this.t >= this.o() / 2 || this.t < 0) {
this.t = -1;
this.s = true;
}
2011-01-29 22:50:29 +01:00
}
2011-02-23 03:37:56 +01:00
public void d(Entity entity) {
2011-01-29 22:50:29 +01:00
int i = this.inventory.a(entity);
if (i > 0) {
2011-09-15 02:23:52 +02:00
boolean flag = this.motY < 0.0D && !this.onGround && !this.p() && !this.ao();
if (flag) {
i = i * 3 / 2 + 1;
2011-04-20 22:47:26 +02:00
}
// CraftBukkit start - Don't call the event when the entity is human since it will be called with damageEntity
if (entity instanceof EntityLiving && !(entity instanceof EntityHuman)) {
2011-01-29 22:50:29 +01:00
org.bukkit.entity.Entity damager = this.getBukkitEntity();
org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity();
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK, i);
this.world.getServer().getPluginManager().callEvent(event);
2011-01-29 22:50:29 +01:00
2011-03-31 22:40:00 +02:00
if (event.isCancelled() || event.getDamage() == 0) {
2011-01-29 22:50:29 +01:00
return;
}
2011-02-23 13:56:36 +01:00
i = event.getDamage();
2011-01-29 22:50:29 +01:00
}
// CraftBukkit end
2011-09-15 18:36:27 +02:00
boolean flag1 = entity.damageEntity(DamageSource.playerAttack(this), i);
2011-09-15 02:23:52 +02:00
// CraftBukkit start - Return when the damage fails so that the item will not lose durability
2011-09-15 02:23:52 +02:00
if (!flag1) {
return;
}
// CraftBukkit end
2011-09-15 02:23:52 +02:00
if (flag1) {
if (this.at()) {
entity.b((double) (-MathHelper.sin(this.yaw * 3.1415927F / 180.0F) * 1.0F), 0.1D, (double) (MathHelper.cos(this.yaw * 3.1415927F / 180.0F) * 1.0F));
this.motX *= 0.6D;
this.motZ *= 0.6D;
this.g(false);
}
if (flag) {
this.e(entity);
}
}
ItemStack itemstack = this.K();
2011-01-29 22:50:29 +01:00
if (itemstack != null && entity instanceof EntityLiving) {
2011-03-31 22:40:00 +02:00
itemstack.a((EntityLiving) entity, this);
// CraftBukkit - bypass infinite items; <= 0 -> == 0
if (itemstack.count == 0) {
2011-01-29 22:50:29 +01:00
itemstack.a(this);
2011-09-15 02:23:52 +02:00
this.L();
2011-03-31 22:40:00 +02:00
}
}
if (entity instanceof EntityLiving) {
2011-09-15 02:23:52 +02:00
if (entity.ac()) {
2011-03-31 22:40:00 +02:00
this.a((EntityLiving) entity, true);
2011-01-29 22:50:29 +01:00
}
2011-03-31 22:40:00 +02:00
2011-04-20 22:47:26 +02:00
this.a(StatisticList.w, i);
2011-01-29 22:50:29 +01:00
}
2011-09-15 02:23:52 +02:00
this.b(0.3F);
2011-01-29 22:50:29 +01:00
}
}
2011-09-15 02:23:52 +02:00
public void e(Entity entity) {}
2011-01-29 22:50:29 +01:00
public void a(ItemStack itemstack) {}
public void die() {
super.die();
2011-01-29 22:50:29 +01:00
this.defaultContainer.a(this);
if (this.activeContainer != null) {
this.activeContainer.a(this);
}
}
2011-02-23 03:37:56 +01:00
2011-09-15 02:23:52 +02:00
public boolean O() {
return !this.sleeping && super.O();
2011-02-23 03:37:56 +01:00
}
2011-03-31 22:40:00 +02:00
public EnumBedError a(int i, int j, int k) {
2011-05-31 15:55:45 +02:00
if (!this.world.isStatic) {
2011-09-15 02:23:52 +02:00
if (this.isSleeping() || !this.ac()) {
2011-05-31 15:55:45 +02:00
return EnumBedError.OTHER_PROBLEM;
}
if (this.world.worldProvider.c) {
2011-03-31 22:40:00 +02:00
return EnumBedError.NOT_POSSIBLE_HERE;
2011-05-31 15:55:45 +02:00
}
if (this.world.d()) {
2011-03-31 22:40:00 +02:00
return EnumBedError.NOT_POSSIBLE_NOW;
2011-05-31 15:55:45 +02:00
}
2011-05-31 15:55:45 +02:00
if (Math.abs(this.locX - (double) i) > 3.0D || Math.abs(this.locY - (double) j) > 2.0D || Math.abs(this.locZ - (double) k) > 3.0D) {
return EnumBedError.TOO_FAR_AWAY;
}
}
2011-02-23 03:37:56 +01:00
2011-05-31 15:55:45 +02:00
// CraftBukkit start
if (this.getBukkitEntity() instanceof Player) {
Player player = (Player) this.getBukkitEntity();
org.bukkit.block.Block bed = this.world.getWorld().getBlockAt(i, j, k);
2011-06-12 00:02:58 +02:00
2011-05-31 15:55:45 +02:00
PlayerBedEnterEvent event = new PlayerBedEnterEvent(player, bed);
this.world.getServer().getPluginManager().callEvent(event);
2011-02-23 03:37:56 +01:00
2011-05-31 15:55:45 +02:00
if (event.isCancelled()) {
return EnumBedError.OTHER_PROBLEM;
}
}
// CraftBukkit end
2011-02-23 03:37:56 +01:00
2011-05-31 15:55:45 +02:00
this.b(0.2F, 0.2F);
this.height = 0.2F;
if (this.world.isLoaded(i, j, k)) {
int l = this.world.getData(i, j, k);
int i1 = BlockBed.c(l);
float f = 0.5F;
float f1 = 0.5F;
switch (i1) {
case 0:
f1 = 0.9F;
break;
case 1:
f = 0.1F;
break;
case 2:
f1 = 0.1F;
break;
case 3:
f = 0.9F;
2011-02-23 03:37:56 +01:00
}
2011-05-31 15:55:45 +02:00
2011-09-15 02:23:52 +02:00
this.b(i1);
2011-05-31 15:55:45 +02:00
this.setPosition((double) ((float) i + f), (double) ((float) j + 0.9375F), (double) ((float) k + f1));
2011-02-23 03:37:56 +01:00
} else {
2011-05-31 15:55:45 +02:00
this.setPosition((double) ((float) i + 0.5F), (double) ((float) j + 0.9375F), (double) ((float) k + 0.5F));
2011-02-23 03:37:56 +01:00
}
2011-05-31 15:55:45 +02:00
this.sleeping = true;
this.sleepTicks = 0;
2011-09-15 02:23:52 +02:00
this.E = new ChunkCoordinates(i, j, k);
2011-05-31 15:55:45 +02:00
this.motX = this.motZ = this.motY = 0.0D;
if (!this.world.isStatic) {
this.world.everyoneSleeping();
}
return EnumBedError.OK;
2011-02-23 03:37:56 +01:00
}
2011-09-15 02:23:52 +02:00
private void b(int i) {
this.F = 0.0F;
this.G = 0.0F;
2011-02-23 03:37:56 +01:00
switch (i) {
case 0:
2011-09-15 02:23:52 +02:00
this.G = -1.8F;
2011-02-23 03:37:56 +01:00
break;
case 1:
2011-09-15 02:23:52 +02:00
this.F = 1.8F;
2011-02-23 03:37:56 +01:00
break;
case 2:
2011-09-15 02:23:52 +02:00
this.G = 1.8F;
2011-02-23 03:37:56 +01:00
break;
case 3:
2011-09-15 02:23:52 +02:00
this.F = -1.8F;
2011-02-23 03:37:56 +01:00
}
}
2011-03-31 22:40:00 +02:00
public void a(boolean flag, boolean flag1, boolean flag2) {
if (this.fauxSleeping) return; // CraftBukkit - Can't leave bed if not in one!
2011-03-31 22:40:00 +02:00
this.b(0.6F, 1.8F);
2011-09-15 02:23:52 +02:00
this.m_();
ChunkCoordinates chunkcoordinates = this.E;
ChunkCoordinates chunkcoordinates1 = this.E;
2011-02-23 03:37:56 +01:00
if (chunkcoordinates != null && this.world.getTypeId(chunkcoordinates.x, chunkcoordinates.y, chunkcoordinates.z) == Block.BED.id) {
BlockBed.a(this.world, chunkcoordinates.x, chunkcoordinates.y, chunkcoordinates.z, false);
2011-06-30 00:02:25 +02:00
chunkcoordinates1 = BlockBed.f(this.world, chunkcoordinates.x, chunkcoordinates.y, chunkcoordinates.z, 0);
2011-03-31 22:40:00 +02:00
if (chunkcoordinates1 == null) {
chunkcoordinates1 = new ChunkCoordinates(chunkcoordinates.x, chunkcoordinates.y + 1, chunkcoordinates.z);
2011-03-31 22:40:00 +02:00
}
2011-02-23 03:37:56 +01:00
this.setPosition((double) ((float) chunkcoordinates1.x + 0.5F), (double) ((float) chunkcoordinates1.y + this.height + 0.1F), (double) ((float) chunkcoordinates1.z + 0.5F));
2011-02-23 03:37:56 +01:00
}
this.sleeping = false;
if (!this.world.isStatic && flag1) {
this.world.everyoneSleeping();
2011-02-23 03:37:56 +01:00
}
2011-04-07 20:26:51 +02:00
// CraftBukkit start
if (this.getBukkitEntity() instanceof Player) {
Player player = (Player) this.getBukkitEntity();
2011-05-14 16:29:42 +02:00
org.bukkit.block.Block bed;
if (chunkcoordinates != null) {
bed = this.world.getWorld().getBlockAt(chunkcoordinates.x, chunkcoordinates.y, chunkcoordinates.z);
} else {
bed = this.world.getWorld().getBlockAt(player.getLocation());
}
2011-05-14 16:29:42 +02:00
2011-04-07 20:26:51 +02:00
PlayerBedLeaveEvent event = new PlayerBedLeaveEvent(player, bed);
this.world.getServer().getPluginManager().callEvent(event);
2011-04-07 20:26:51 +02:00
}
// CraftBukkit end
2011-02-23 03:37:56 +01:00
if (flag) {
this.sleepTicks = 0;
} else {
this.sleepTicks = 100;
}
2011-03-31 22:40:00 +02:00
if (flag2) {
2011-09-15 02:23:52 +02:00
this.a(this.E);
2011-03-31 22:40:00 +02:00
}
2011-02-23 03:37:56 +01:00
}
2011-09-15 02:23:52 +02:00
private boolean w() {
return this.world.getTypeId(this.E.x, this.E.y, this.E.z) == Block.BED.id;
2011-02-23 03:37:56 +01:00
}
public static ChunkCoordinates getBed(World world, ChunkCoordinates chunkcoordinates) {
2011-09-15 02:23:52 +02:00
IChunkProvider ichunkprovider = world.n();
2011-03-31 22:40:00 +02:00
ichunkprovider.getChunkAt(chunkcoordinates.x - 3 >> 4, chunkcoordinates.z - 3 >> 4);
ichunkprovider.getChunkAt(chunkcoordinates.x + 3 >> 4, chunkcoordinates.z - 3 >> 4);
ichunkprovider.getChunkAt(chunkcoordinates.x - 3 >> 4, chunkcoordinates.z + 3 >> 4);
ichunkprovider.getChunkAt(chunkcoordinates.x + 3 >> 4, chunkcoordinates.z + 3 >> 4);
if (world.getTypeId(chunkcoordinates.x, chunkcoordinates.y, chunkcoordinates.z) != Block.BED.id) {
2011-03-31 22:40:00 +02:00
return null;
} else {
2011-06-30 00:02:25 +02:00
ChunkCoordinates chunkcoordinates1 = BlockBed.f(world, chunkcoordinates.x, chunkcoordinates.y, chunkcoordinates.z, 0);
2011-03-31 22:40:00 +02:00
return chunkcoordinates1;
}
2011-02-23 03:37:56 +01:00
}
public boolean isSleeping() {
2011-03-31 22:40:00 +02:00
return this.sleeping;
}
public boolean isDeeplySleeping() {
2011-02-23 03:37:56 +01:00
return this.sleeping && this.sleepTicks >= 100;
}
public void a(String s) {}
2011-03-31 22:40:00 +02:00
public ChunkCoordinates getBed() {
2011-05-28 22:50:08 +02:00
return this.b;
2011-03-31 22:40:00 +02:00
}
public void a(ChunkCoordinates chunkcoordinates) {
if (chunkcoordinates != null) {
2011-05-28 22:50:08 +02:00
this.b = new ChunkCoordinates(chunkcoordinates);
this.spawnWorld = this.world.worldData.name; // CraftBukkit
2011-03-31 22:40:00 +02:00
} else {
2011-05-28 22:50:08 +02:00
this.b = null;
2011-03-31 22:40:00 +02:00
}
}
2011-04-20 22:47:26 +02:00
public void a(Statistic statistic) {
this.a(statistic, 1);
}
2011-03-31 22:40:00 +02:00
public void a(Statistic statistic, int i) {}
2011-09-15 02:23:52 +02:00
protected void S() {
super.S();
2011-04-20 22:47:26 +02:00
this.a(StatisticList.u, 1);
2011-09-15 02:23:52 +02:00
if (this.at()) {
this.b(0.8F);
} else {
this.b(0.2F);
}
2011-03-31 22:40:00 +02:00
}
public void a(float f, float f1) {
double d0 = this.locX;
double d1 = this.locY;
double d2 = this.locZ;
2011-09-15 18:36:27 +02:00
if (this.abilities.isFlying) {
2011-09-15 02:23:52 +02:00
double d3 = this.motY;
float f2 = this.ak;
this.ak = 0.05F;
super.a(f, f1);
this.motY = d3 * 0.6D;
this.ak = f2;
} else {
super.a(f, f1);
}
this.a(this.locX - d0, this.locY - d1, this.locZ - d2);
2011-03-31 22:40:00 +02:00
}
2011-09-15 02:23:52 +02:00
public void a(double d0, double d1, double d2) {
2011-04-20 22:47:26 +02:00
if (this.vehicle == null) {
int i;
2011-03-31 22:40:00 +02:00
2011-04-20 22:47:26 +02:00
if (this.a(Material.WATER)) {
i = Math.round(MathHelper.a(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F);
if (i > 0) {
this.a(StatisticList.q, i);
2011-09-15 02:23:52 +02:00
this.b(0.015F * (float) i * 0.01F);
2011-04-20 22:47:26 +02:00
}
2011-09-15 02:23:52 +02:00
} else if (this.ao()) {
2011-04-20 22:47:26 +02:00
i = Math.round(MathHelper.a(d0 * d0 + d2 * d2) * 100.0F);
if (i > 0) {
this.a(StatisticList.m, i);
2011-09-15 02:23:52 +02:00
this.b(0.015F * (float) i * 0.01F);
2011-04-20 22:47:26 +02:00
}
} else if (this.p()) {
if (d1 > 0.0D) {
this.a(StatisticList.o, (int) Math.round(d1 * 100.0D));
}
} else if (this.onGround) {
i = Math.round(MathHelper.a(d0 * d0 + d2 * d2) * 100.0F);
if (i > 0) {
this.a(StatisticList.l, i);
2011-09-15 02:23:52 +02:00
if (this.at()) {
this.b(0.099999994F * (float) i * 0.01F);
} else {
this.b(0.01F * (float) i * 0.01F);
}
2011-04-20 22:47:26 +02:00
}
} else {
i = Math.round(MathHelper.a(d0 * d0 + d2 * d2) * 100.0F);
if (i > 25) {
this.a(StatisticList.p, i);
}
2011-03-31 22:40:00 +02:00
}
2011-04-20 22:47:26 +02:00
}
}
2011-09-15 02:23:52 +02:00
private void h(double d0, double d1, double d2) {
2011-04-20 22:47:26 +02:00
if (this.vehicle != null) {
int i = Math.round(MathHelper.a(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F);
2011-03-31 22:40:00 +02:00
if (i > 0) {
2011-04-20 22:47:26 +02:00
if (this.vehicle instanceof EntityMinecart) {
this.a(StatisticList.r, i);
2011-05-28 22:50:08 +02:00
if (this.c == null) {
this.c = new ChunkCoordinates(MathHelper.floor(this.locX), MathHelper.floor(this.locY), MathHelper.floor(this.locZ));
} else if (this.c.a(MathHelper.floor(this.locX), MathHelper.floor(this.locY), MathHelper.floor(this.locZ)) >= 1000.0D) {
2011-09-15 02:23:52 +02:00
this.a((Statistic) AchievementList.q, 1);
2011-04-20 22:47:26 +02:00
}
} else if (this.vehicle instanceof EntityBoat) {
this.a(StatisticList.s, i);
} else if (this.vehicle instanceof EntityPig) {
this.a(StatisticList.t, i);
}
2011-03-31 22:40:00 +02:00
}
}
}
protected void a(float f) {
2011-09-15 18:36:27 +02:00
if (!this.abilities.canFly) {
2011-09-15 02:23:52 +02:00
if (f >= 2.0F) {
this.a(StatisticList.n, (int) Math.round((double) f * 100.0D));
}
2011-03-31 22:40:00 +02:00
2011-09-15 02:23:52 +02:00
super.a(f);
}
2011-03-31 22:40:00 +02:00
}
2011-04-20 22:47:26 +02:00
public void a(EntityLiving entityliving) {
if (entityliving instanceof EntityMonster) {
this.a((Statistic) AchievementList.s);
}
}
2011-05-26 14:48:22 +02:00
2011-09-15 02:23:52 +02:00
public void T() {
if (this.H > 0) {
this.H = 10;
2011-05-26 14:48:22 +02:00
} else {
2011-09-15 02:23:52 +02:00
this.I = true;
}
}
public void d(int i) {
this.exp += i;
this.expTotal += i;
while (this.exp >= this.U()) {
this.exp -= this.U();
this.y();
2011-05-26 14:48:22 +02:00
}
}
2011-09-15 02:23:52 +02:00
public int U() {
return (this.expLevel + 1) * 10;
}
private void y() {
++this.expLevel;
}
public void b(float f) {
2011-09-15 18:36:27 +02:00
if (!this.abilities.isInvulnerable) {
2011-09-15 02:23:52 +02:00
if (!this.world.isStatic) {
2011-09-15 18:36:27 +02:00
this.foodData.a(f);
2011-09-15 02:23:52 +02:00
}
}
}
2011-09-15 18:36:27 +02:00
public FoodMetaData getFoodData() {
return this.foodData;
2011-09-15 02:23:52 +02:00
}
public boolean c(boolean flag) {
2011-09-15 18:36:27 +02:00
return (flag || this.foodData.b()) && !this.abilities.isInvulnerable;
2011-09-15 02:23:52 +02:00
}
public boolean W() {
return this.health > 0 && this.health < 20;
}
public void a(ItemStack itemstack, int i) {
if (itemstack != this.d) {
this.d = itemstack;
this.e = i;
if (!this.world.isStatic) {
this.h(true);
}
}
}
public boolean c(int i, int j, int k) {
return true;
}
protected int a(EntityHuman entityhuman) {
return this.expTotal >> 1;
}
protected boolean X() {
return true;
}
public String Y() {
return this.name;
}
2011-01-29 22:50:29 +01:00
}