3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-17 21:40:08 +01:00
Paper/src/main/java/net/minecraft/server/EntityHuman.java

1276 Zeilen
40 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;
import org.bukkit.event.entity.EntityCombustByEntityEvent;
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 PlayerInventory inventory = new PlayerInventory(this);
2011-01-29 22:50:29 +01:00
public Container defaultContainer;
public Container activeContainer;
2011-09-15 18:36:27 +02:00
protected FoodMetaData foodData = new FoodMetaData();
2011-11-20 09:01:14 +01:00
protected int o = 0;
public byte p = 0;
public int q = 0;
2011-09-15 02:23:52 +02:00
public float r;
2011-11-20 09:01:14 +01:00
public float s;
public boolean t = false;
public int u = 0;
2011-01-29 22:50:29 +01:00
public String name;
public int dimension;
2011-11-20 09:01:14 +01:00
public int x = 0;
2011-02-23 03:37:56 +01:00
public double y;
2011-09-15 02:23:52 +02:00
public double z;
public double A;
public double B;
public double C;
2011-11-20 09:01:14 +01:00
public double D;
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-04-07 20:26:51 +02:00
// CraftBukkit end
2011-11-20 09:01:14 +01:00
public ChunkCoordinates F;
public int sleepTicks; // CraftBukkit private -> public
2011-09-15 02:23:52 +02:00
public float G;
2011-11-20 09:01:14 +01:00
public float H;
2011-05-28 22:50:08 +02:00
private ChunkCoordinates b;
2011-04-20 22:47:26 +02:00
private ChunkCoordinates c;
2011-11-20 09:01:14 +01:00
public int I = 20;
protected boolean J = false;
public float K;
2011-09-15 18:36:27 +02:00
public PlayerAbilities abilities = new PlayerAbilities();
public int expLevel;
2011-09-15 02:23:52 +02:00
public int expTotal;
public float exp;
2011-09-15 02:23:52 +02:00
private ItemStack d;
private int e;
2011-11-20 09:01:14 +01:00
protected float P = 0.1F;
protected float Q = 0.02F;
public EntityFishingHook hookedFish = null;
2011-01-29 22:50:29 +01:00
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-11-20 09:01:14 +01:00
this.af = "humanoid";
this.ae = 180.0F;
2011-01-29 22:50:29 +01:00
this.maxFireTicks = 20;
this.texture = "/mob/char.png";
}
2011-11-20 09:01:14 +01:00
public int getMaxHealth() {
return 20;
}
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));
}
2011-11-20 09:01:14 +01:00
public boolean H() {
2011-09-15 02:23:52 +02:00
return this.d != null;
}
2011-11-20 09:01:14 +01:00
public void I() {
2011-09-15 02:23:52 +02:00
if (this.d != null) {
this.d.a(this.world, this, this.e);
}
2011-11-20 09:01:14 +01:00
this.J();
2011-02-23 03:37:56 +01:00
}
2011-11-20 09:01:14 +01:00
public void J() {
2011-09-15 02:23:52 +02:00
this.d = null;
this.e = 0;
if (!this.world.isStatic) {
2011-11-20 09:01:14 +01:00
this.g(false);
2011-09-15 02:23:52 +02:00
}
}
2011-11-20 09:01:14 +01:00
public boolean K() {
return this.H() && Item.byId[this.d.id].d(this.d) == EnumAnimation.d;
2011-09-15 02:23:52 +02:00
}
2011-11-20 09:01:14 +01:00
public void w_() {
2011-09-15 02:23:52 +02:00
if (this.d != null) {
ItemStack itemstack = this.inventory.getItemInHand();
if (itemstack != this.d) {
2011-11-20 09:01:14 +01:00
this.J();
2011-09-15 02:23:52 +02:00
} else {
if (this.e <= 25 && this.e % 4 == 0) {
this.b(itemstack, 5);
}
if (--this.e == 0 && !this.world.isStatic) {
2011-11-20 09:01:14 +01:00
this.G();
2011-09-15 02:23:52 +02:00
}
}
}
2011-11-20 09:01:14 +01:00
if (this.x > 0) {
--this.x;
2011-09-15 02:23:52 +02:00
}
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-11-20 09:01:14 +01:00
if (!this.C()) {
2011-05-31 15:55:45 +02:00
this.a(true, true, false);
2011-11-20 09:01:14 +01:00
} else if (this.world.e()) {
2011-05-31 15:55:45 +02:00
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-11-20 09:01:14 +01:00
super.w_();
2011-01-29 22:50:29 +01:00
if (!this.world.isStatic && this.activeContainer != null && !this.activeContainer.b(this)) {
this.closeInventory();
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-11-20 09:01:14 +01:00
if (this.z() && this.abilities.isInvulnerable) {
this.extinguish();
2011-09-15 02:23:52 +02:00
}
this.y = this.B;
this.z = this.C;
2011-11-20 09:01:14 +01:00
this.A = this.D;
double d0 = this.locX - this.B;
double d1 = this.locY - this.C;
double d2 = this.locZ - this.D;
2011-01-29 22:50:29 +01:00
double d3 = 10.0D;
if (d0 > d3) {
2011-11-20 09:01:14 +01:00
this.y = this.B = this.locX;
2011-01-29 22:50:29 +01:00
}
if (d2 > d3) {
2011-11-20 09:01:14 +01:00
this.A = this.D = this.locZ;
2011-01-29 22:50:29 +01:00
}
if (d1 > d3) {
2011-11-20 09:01:14 +01:00
this.z = this.C = this.locY;
2011-01-29 22:50:29 +01:00
}
if (d0 < -d3) {
2011-11-20 09:01:14 +01:00
this.y = this.B = this.locX;
2011-01-29 22:50:29 +01:00
}
if (d2 < -d3) {
2011-11-20 09:01:14 +01:00
this.A = this.D = this.locZ;
2011-01-29 22:50:29 +01:00
}
if (d1 < -d3) {
2011-11-20 09:01:14 +01:00
this.z = this.C = this.locY;
2011-01-29 22:50:29 +01:00
}
2011-11-20 09:01:14 +01:00
this.B += d0 * 0.25D;
this.D += d2 * 0.25D;
this.C += 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) {
2011-11-20 09:01:14 +01:00
if (itemstack.m() == EnumAnimation.c) {
this.world.makeSound(this, "random.drink", 0.5F, this.world.random.nextFloat() * 0.1F + 0.9F);
}
2011-09-15 02:23:52 +02:00
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);
2011-11-20 09:01:14 +01:00
vec3d1 = vec3d1.add(this.locX, this.locY + (double) this.x(), this.locZ);
2011-09-15 02:23:52 +02:00
this.world.a("iconcrack_" + itemstack.getItem().id, vec3d1.a, vec3d1.b, vec3d1.c, vec3d.a, vec3d.b + 0.05D, vec3d.c);
}
2011-11-20 09:01:14 +01:00
this.world.makeSound(this, "random.eat", 0.5F + 0.5F * (float) this.random.nextInt(2), (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
2011-09-15 02:23:52 +02:00
}
2011-02-23 03:37:56 +01:00
}
2011-11-20 09:01:14 +01:00
protected void G() {
2011-09-15 02:23:52 +02:00
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;
}
}
2011-11-20 09:01:14 +01:00
this.J();
2011-09-15 02:23:52 +02:00
}
}
2011-11-20 09:01:14 +01:00
protected boolean L() {
return this.getHealth() <= 0 || this.isSleeping();
2011-01-29 22:50:29 +01:00
}
protected void closeInventory() {
2011-01-29 22:50:29 +01:00
this.activeContainer = this.defaultContainer;
}
2011-11-20 09:01:14 +01:00
public void M() {
2011-04-20 22:47:26 +02:00
double d0 = this.locX;
double d1 = this.locY;
double d2 = this.locZ;
2011-11-20 09:01:14 +01:00
super.M();
this.r = this.s;
this.s = 0.0F;
2011-09-15 02:23:52 +02:00
this.h(this.locX - d0, this.locY - d1, this.locZ - d2);
}
2011-11-20 09:01:14 +01:00
private int A() {
return this.hasEffect(MobEffectList.FASTER_DIG) ? 6 - (1 + this.getEffect(MobEffectList.FASTER_DIG).getAmplifier()) * 1 : (this.hasEffect(MobEffectList.SLOWER_DIG) ? 6 + (1 + this.getEffect(MobEffectList.SLOWER_DIG).getAmplifier()) * 2 : 6);
2011-01-29 22:50:29 +01:00
}
2011-11-20 09:01:14 +01:00
protected void m_() {
int i = this.A();
2011-09-15 02:23:52 +02:00
2011-11-20 09:01:14 +01:00
if (this.t) {
++this.u;
if (this.u >= i) {
this.u = 0;
this.t = false;
2011-01-29 22:50:29 +01:00
}
} else {
2011-11-20 09:01:14 +01:00
this.u = 0;
2011-01-29 22:50:29 +01:00
}
2011-11-20 09:01:14 +01:00
this.an = (float) this.u / (float) i;
2011-01-29 22:50:29 +01:00
}
2011-11-20 09:01:14 +01:00
public void d() {
if (this.o > 0) {
--this.o;
2011-09-15 02:23:52 +02:00
}
2011-11-20 09:01:14 +01:00
if (this.world.difficulty == 0 && this.getHealth() < this.getMaxHealth() && this.ticksLived % 20 * 12 == 0) {
// CraftBukkit - added regain reason of "REGEN" for filtering purposes.
2011-11-20 09:01:14 +01:00
this.d(1, RegainReason.REGEN);
2011-09-15 02:23:52 +02:00
}
2011-11-20 09:01:14 +01:00
this.inventory.i();
this.r = this.s;
super.d();
2011-09-15 02:23:52 +02:00
this.ak = this.P;
2011-11-20 09:01:14 +01:00
this.al = this.Q;
if (this.isSprinting()) {
2011-09-15 02:23:52 +02:00
this.ak = (float) ((double) this.ak + (double) this.P * 0.3D);
2011-11-20 09:01:14 +01:00
this.al = (float) ((double) this.al + (double) this.Q * 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;
}
2011-11-20 09:01:14 +01:00
if (!this.onGround || this.getHealth() <= 0) {
2011-01-29 22:50:29 +01:00
f = 0.0F;
}
2011-11-20 09:01:14 +01:00
if (this.onGround || this.getHealth() <= 0) {
2011-01-29 22:50:29 +01:00
f1 = 0.0F;
}
2011-11-20 09:01:14 +01:00
this.s += (f - this.s) * 0.4F;
this.ax += (f1 - this.ax) * 0.8F;
if (this.getHealth() > 0) {
2011-01-29 22:50:29 +01:00
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-11-20 09:01:14 +01:00
this.k(entity);
2011-01-29 22:50:29 +01:00
}
}
}
}
}
2011-11-20 09:01:14 +01:00
private void k(Entity entity) {
2011-09-15 02:23:52 +02:00
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-11-20 09:01:14 +01:00
this.inventory.k();
2011-09-15 02:23:52 +02:00
if (damagesource != null) {
2011-11-20 09:01:14 +01:00
this.motX = (double) (-MathHelper.cos((this.at + this.yaw) * 3.1415927F / 180.0F) * 0.1F);
this.motZ = (double) (-MathHelper.sin((this.at + 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) {
2011-11-20 09:01:14 +01:00
this.q += 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-11-20 09:01:14 +01:00
protected int f(int i) {
int j = EnchantmentManager.getOxygenEnchantmentLevel(this.inventory);
2011-11-20 09:01:14 +01:00
return j > 0 && this.random.nextInt(j + 1) > 0 ? i : super.f(i);
}
public void N() {
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-11-20 09:01:14 +01:00
EntityItem entityitem = new EntityItem(this.world, this.locX, this.locY - 0.30000001192092896D + (double) this.x(), 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);
2011-11-20 09:01:14 +01:00
float f1 = f;
int i = EnchantmentManager.getDigSpeedEnchantmentLevel(this.inventory);
2011-01-29 22:50:29 +01:00
2011-11-20 09:01:14 +01:00
if (i > 0 && this.inventory.b(block)) {
f1 = f + (float) (i * i + 1);
2011-01-29 22:50:29 +01:00
}
if (this.hasEffect(MobEffectList.FASTER_DIG)) {
2011-11-20 09:01:14 +01:00
f1 *= 1.0F + (float) (this.getEffect(MobEffectList.FASTER_DIG).getAmplifier() + 1) * 0.2F;
2011-09-15 02:23:52 +02:00
}
if (this.hasEffect(MobEffectList.SLOWER_DIG)) {
2011-11-20 09:01:14 +01:00
f1 *= 1.0F - (float) (this.getEffect(MobEffectList.SLOWER_DIG).getAmplifier() + 1) * 0.2F;
2011-09-15 02:23:52 +02:00
}
if (this.a(Material.WATER) && !EnchantmentManager.hasWaterWorkerEnchantment(this.inventory)) {
2011-11-20 09:01:14 +01:00
f1 /= 5.0F;
}
if (!this.onGround) {
f1 /= 5.0F;
}
return f1;
2011-01-29 22:50:29 +01:00
}
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);
NBTTagList nbttaglist = nbttagcompound.getList("Inventory");
2011-01-29 22:50:29 +01:00
this.inventory.b(nbttaglist);
this.dimension = nbttagcompound.getInt("Dimension");
this.sleeping = nbttagcompound.getBoolean("Sleeping");
this.sleepTicks = nbttagcompound.getShort("SleepTimer");
this.exp = nbttagcompound.getFloat("XpP");
this.expLevel = nbttagcompound.getInt("XpLevel");
this.expTotal = nbttagcompound.getInt("XpTotal");
2011-02-23 03:37:56 +01:00
if (this.sleeping) {
2011-11-20 09:01:14 +01:00
this.F = 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 ("".equals(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")) {
this.b = new ChunkCoordinates(nbttagcompound.getInt("SpawnX"), nbttagcompound.getInt("SpawnY"), nbttagcompound.getInt("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-11-20 09:01:14 +01:00
this.abilities.b(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);
nbttagcompound.set("Inventory", this.inventory.a(new NBTTagList()));
nbttagcompound.setInt("Dimension", this.dimension);
nbttagcompound.setBoolean("Sleeping", this.sleeping);
nbttagcompound.setShort("SleepTimer", (short) this.sleepTicks);
nbttagcompound.setFloat("XpP", this.exp);
nbttagcompound.setInt("XpLevel", this.expLevel);
nbttagcompound.setInt("XpTotal", this.expTotal);
2011-05-28 22:50:08 +02:00
if (this.b != null) {
nbttagcompound.setInt("SpawnX", this.b.x);
nbttagcompound.setInt("SpawnY", this.b.y);
nbttagcompound.setInt("SpawnZ", this.b.z);
nbttagcompound.setString("SpawnWorld", spawnWorld); // CraftBukkit - fixes bed spawns for multiworld worlds
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-11-20 09:01:14 +01:00
this.abilities.a(nbttagcompound);
2011-01-29 22:50:29 +01:00
}
public void a(IInventory iinventory) {}
2011-11-20 09:01:14 +01:00
public void c(int i, int j, int k) {}
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-11-20 09:01:14 +01:00
public float x() {
2011-01-29 22:50:29 +01:00
return 0.12F;
}
2011-11-20 09:01:14 +01:00
protected void w() {
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-11-20 09:01:14 +01:00
this.aS = 0;
if (this.getHealth() <= 0) {
2011-09-15 02:23:52 +02:00
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.difficulty == 0) {
2011-09-15 02:23:52 +02:00
i = 0;
}
2011-01-29 22:50:29 +01:00
if (this.world.difficulty == 1) {
2011-11-20 09:01:14 +01:00
i = i / 2 + 1;
2011-09-15 02:23:52 +02:00
}
if (this.world.difficulty == 3) {
2011-09-15 02:23:52 +02:00
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-11-20 09:01:14 +01:00
protected int b(DamageSource damagesource, int i) {
int j = super.b(damagesource, i);
if (j <= 0) {
return 0;
} else {
int k = EnchantmentManager.a(this.inventory, damagesource);
if (k > 20) {
k = 20;
}
if (k > 0 && k <= 20) {
int l = 25 - k;
int i1 = j * l + this.aq;
j = i1 / 25;
this.aq = i1 % 25;
}
return j;
}
}
protected boolean y() {
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-11-20 09:01:14 +01:00
if (!(entityliving instanceof EntityHuman) || this.y()) {
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-11-20 09:01:14 +01:00
if (entitywolf1.isTamed() && entitywolf1.E() == 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-11-20 09:01:14 +01:00
protected void g(int i) {
this.inventory.d(i);
}
2011-09-15 02:23:52 +02:00
2011-11-20 09:01:14 +01:00
protected int O() {
return this.inventory.j();
}
2011-01-29 22:50:29 +01:00
2011-11-20 09:01:14 +01:00
protected void c(DamageSource damagesource, int i) {
if (!damagesource.ignoresArmor() && this.K()) {
i = 1 + i >> 1;
2011-09-15 02:23:52 +02:00
}
2011-11-20 09:01:14 +01:00
i = this.d(damagesource, i);
i = this.b(damagesource, i);
this.c(damagesource.e());
super.c(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-11-20 09:01:14 +01:00
public void a(TileEntityBrewingStand tileentitybrewingstand) {}
public void e(Entity entity) {
2011-09-15 02:23:52 +02:00
if (!entity.b(this)) {
2011-11-20 09:01:14 +01:00
ItemStack itemstack = this.P();
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-11-20 09:01:14 +01:00
this.Q();
2011-01-29 22:50:29 +01:00
}
}
}
}
2011-11-20 09:01:14 +01:00
public ItemStack P() {
return this.inventory.getItemInHand();
2011-01-29 22:50:29 +01:00
}
2011-11-20 09:01:14 +01:00
public void Q() {
this.inventory.setItem(this.inventory.itemInHandIndex, (ItemStack) null);
2011-01-29 22:50:29 +01:00
}
2011-11-20 09:01:14 +01:00
public double R() {
2011-01-29 22:50:29 +01:00
return (double) (this.height - 0.5F);
}
2011-11-20 09:01:14 +01:00
public void r_() {
if (!this.t || this.u >= this.A() / 2 || this.u < 0) {
this.u = -1;
this.t = true;
2011-09-15 02:23:52 +02:00
}
2011-01-29 22:50:29 +01:00
}
2011-11-20 09:01:14 +01:00
public void f(Entity entity) {
2011-01-29 22:50:29 +01:00
int i = this.inventory.a(entity);
2011-11-20 09:01:14 +01:00
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();
}
int j = 0;
int k = 0;
if (entity instanceof EntityLiving) {
k = EnchantmentManager.a(this.inventory, (EntityLiving) entity);
j += EnchantmentManager.getKnockbackEnchantmentLevel(this.inventory, (EntityLiving) entity);
2011-11-20 09:01:14 +01:00
}
if (this.isSprinting()) {
++j;
}
if (i > 0 || k > 0) {
boolean flag = this.fallDistance > 0.0F && !this.onGround && !this.r() && !this.az() && !this.hasEffect(MobEffectList.BLINDNESS) && this.vehicle == null && entity instanceof EntityLiving;
2011-09-15 02:23:52 +02:00
if (flag) {
2011-11-20 09:01:14 +01:00
i += this.random.nextInt(i / 2 + 2);
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-11-20 09:01:14 +01:00
i += k;
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) {
2011-11-20 09:01:14 +01:00
if (j > 0) {
entity.b_((double) (-MathHelper.sin(this.yaw * 3.1415927F / 180.0F) * (float) j * 0.5F), 0.1D, (double) (MathHelper.cos(this.yaw * 3.1415927F / 180.0F) * (float) j * 0.5F));
2011-09-15 02:23:52 +02:00
this.motX *= 0.6D;
this.motZ *= 0.6D;
this.setSprinting(false);
2011-09-15 02:23:52 +02:00
}
if (flag) {
2011-11-20 09:01:14 +01:00
this.c(entity);
}
if (k > 0) {
this.d(entity);
}
if (i >= 18) {
this.a((Statistic) AchievementList.E);
2011-09-15 02:23:52 +02:00
}
}
2011-11-20 09:01:14 +01:00
ItemStack itemstack = this.P();
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-11-20 09:01:14 +01:00
this.Q();
2011-03-31 22:40:00 +02:00
}
}
if (entity instanceof EntityLiving) {
if (entity.isAlive()) {
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);
int l = EnchantmentManager.getFireAspectEnchantmentLevel(this.inventory, (EntityLiving) entity);
2011-11-20 09:01:14 +01:00
if (l > 0) {
// CraftBukkit start - raise a combust event when somebody hits with a fire enchanted item
EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), l*4);
if (!combustEvent.isCancelled()) {
entity.setOnFire(combustEvent.getDuration());
}
// CraftBukkit end
2011-11-20 09:01:14 +01:00
}
2011-01-29 22:50:29 +01:00
}
2011-09-15 02:23:52 +02:00
2011-11-20 09:01:14 +01:00
this.c(0.3F);
2011-01-29 22:50:29 +01:00
}
}
2011-11-20 09:01:14 +01:00
public void c(Entity entity) {}
public void d(Entity entity) {}
2011-09-15 02:23:52 +02:00
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-11-20 09:01:14 +01:00
public boolean T() {
return !this.sleeping && super.T();
2011-02-23 03:37:56 +01:00
}
public EnumBedResult a(int i, int j, int k) {
2011-05-31 15:55:45 +02:00
if (!this.world.isStatic) {
if (this.isSleeping() || !this.isAlive()) {
return EnumBedResult.OTHER_PROBLEM;
2011-05-31 15:55:45 +02:00
}
if (this.world.worldProvider.c) {
return EnumBedResult.NOT_POSSIBLE_HERE;
2011-05-31 15:55:45 +02:00
}
2011-11-20 09:01:14 +01:00
if (this.world.e()) {
return EnumBedResult.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 EnumBedResult.TOO_FAR_AWAY;
2011-05-31 15:55:45 +02:00
}
2011-11-20 09:01:14 +01:00
double d0 = 8.0D;
double d1 = 5.0D;
List list = this.world.a(EntityMonster.class, AxisAlignedBB.b((double) i - d0, (double) j - d1, (double) k - d0, (double) i + d0, (double) j + d1, (double) k + d0));
if (!list.isEmpty()) {
return EnumBedResult.NOT_SAFE;
2011-11-20 09:01:14 +01:00
}
2011-05-31 15:55:45 +02:00
}
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 EnumBedResult.OTHER_PROBLEM;
2011-05-31 15:55:45 +02:00
}
}
// 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);
2011-11-20 09:01:14 +01:00
int i1 = BlockBed.d(l);
2011-05-31 15:55:45 +02:00
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-11-20 09:01:14 +01:00
this.c(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-11-20 09:01:14 +01:00
this.F = 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 EnumBedResult.OK;
2011-02-23 03:37:56 +01:00
}
2011-11-20 09:01:14 +01:00
private void c(int i) {
2011-09-15 02:23:52 +02:00
this.G = 0.0F;
2011-11-20 09:01:14 +01:00
this.H = 0.0F;
2011-02-23 03:37:56 +01:00
switch (i) {
case 0:
2011-11-20 09:01:14 +01:00
this.H = -1.8F;
2011-02-23 03:37:56 +01:00
break;
case 1:
2011-11-20 09:01:14 +01:00
this.G = 1.8F;
2011-02-23 03:37:56 +01:00
break;
case 2:
2011-11-20 09:01:14 +01:00
this.H = 1.8F;
2011-02-23 03:37:56 +01:00
break;
case 3:
2011-11-20 09:01:14 +01:00
this.G = -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 && !this.sleeping) 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-11-20 09:01:14 +01:00
this.w();
ChunkCoordinates chunkcoordinates = this.F;
ChunkCoordinates chunkcoordinates1 = this.F;
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-11-20 09:01:14 +01:00
this.a(this.F);
2011-03-31 22:40:00 +02:00
}
2011-02-23 03:37:56 +01:00
}
2011-11-20 09:01:14 +01:00
private boolean C() {
return this.world.getTypeId(this.F.x, this.F.y, this.F.z) == Block.BED.id;
2011-02-23 03:37:56 +01:00
}
public static ChunkCoordinates getBed(World world, ChunkCoordinates chunkcoordinates) {
2011-11-20 09:01:14 +01:00
IChunkProvider ichunkprovider = world.p();
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-11-20 09:01:14 +01:00
protected void X() {
super.X();
2011-04-20 22:47:26 +02:00
this.a(StatisticList.u, 1);
if (this.isSprinting()) {
2011-11-20 09:01:14 +01:00
this.c(0.8F);
2011-09-15 02:23:52 +02:00
} else {
2011-11-20 09:01:14 +01:00
this.c(0.2F);
2011-09-15 02:23:52 +02:00
}
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;
2011-11-20 09:01:14 +01:00
float f2 = this.al;
2011-09-15 02:23:52 +02:00
2011-11-20 09:01:14 +01:00
this.al = 0.05F;
2011-09-15 02:23:52 +02:00
super.a(f, f1);
this.motY = d3 * 0.6D;
2011-11-20 09:01:14 +01:00
this.al = f2;
2011-09-15 02:23:52 +02:00
} else {
super.a(f, f1);
}
2011-11-20 09:01:14 +01:00
this.b(this.locX - d0, this.locY - d1, this.locZ - d2);
2011-03-31 22:40:00 +02:00
}
2011-11-20 09:01:14 +01:00
public void b(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-11-20 09:01:14 +01:00
this.c(0.015F * (float) i * 0.01F);
2011-04-20 22:47:26 +02:00
}
2011-11-20 09:01:14 +01:00
} else if (this.az()) {
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-11-20 09:01:14 +01:00
this.c(0.015F * (float) i * 0.01F);
2011-04-20 22:47:26 +02:00
}
2011-11-20 09:01:14 +01:00
} else if (this.r()) {
2011-04-20 22:47:26 +02:00
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);
if (this.isSprinting()) {
2011-11-20 09:01:14 +01:00
this.c(0.099999994F * (float) i * 0.01F);
2011-09-15 02:23:52 +02:00
} else {
2011-11-20 09:01:14 +01:00
this.c(0.01F * (float) i * 0.01F);
2011-09-15 02:23:52 +02:00
}
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
}
}
}
2011-11-20 09:01:14 +01:00
protected void b(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-11-20 09:01:14 +01:00
super.b(f);
2011-09-15 02:23:52 +02:00
}
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-11-20 09:01:14 +01:00
public void Y() {
if (this.I > 0) {
this.I = 10;
2011-05-26 14:48:22 +02:00
} else {
2011-11-20 09:01:14 +01:00
this.J = true;
2011-09-15 02:23:52 +02:00
}
}
public void giveExp(int i) {
2011-11-20 09:01:14 +01:00
this.q += i;
this.exp += (float) i / (float) this.getExpTolevel();
this.expTotal += i;
2011-09-15 02:23:52 +02:00
while (this.exp >= 1.0F) {
--this.exp;
this.levelUp();
2011-11-20 09:01:14 +01:00
}
}
public void levelDown(int i) {
this.expLevel -= i;
if (this.expLevel < 0) {
this.expLevel = 0;
2011-05-26 14:48:22 +02:00
}
}
2011-09-15 02:23:52 +02:00
public int getExpTolevel() {
return 7 + (this.expLevel * 7 >> 1);
2011-09-15 02:23:52 +02:00
}
private void levelUp() {
++this.expLevel;
2011-09-15 02:23:52 +02:00
}
2011-11-20 09:01:14 +01:00
public void c(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
}
2011-11-20 09:01:14 +01:00
public boolean b(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
}
2011-11-20 09:01:14 +01:00
public boolean ab() {
return this.getHealth() > 0 && this.getHealth() < this.getMaxHealth();
2011-09-15 02:23:52 +02:00
}
public void a(ItemStack itemstack, int i) {
if (itemstack != this.d) {
this.d = itemstack;
this.e = i;
if (!this.world.isStatic) {
2011-11-20 09:01:14 +01:00
this.g(true);
2011-09-15 02:23:52 +02:00
}
}
}
2011-11-20 09:01:14 +01:00
public boolean d(int i, int j, int k) {
2011-09-15 02:23:52 +02:00
return true;
}
protected int a(EntityHuman entityhuman) {
int i = this.expLevel * 7;
2011-11-20 09:01:14 +01:00
return i > 100 ? 100 : i;
2011-09-15 02:23:52 +02:00
}
2011-11-20 09:01:14 +01:00
protected boolean ac() {
2011-09-15 02:23:52 +02:00
return true;
}
2011-11-20 09:01:14 +01:00
public String ad() {
2011-09-15 02:23:52 +02:00
return this.name;
}
2011-11-20 09:01:14 +01:00
public void e(int i) {}
public void copyTo(EntityHuman entityhuman) {
this.inventory.a(entityhuman.inventory);
this.health = entityhuman.health;
this.foodData = entityhuman.foodData;
this.expLevel = entityhuman.expLevel;
2011-11-20 09:01:14 +01:00
this.expTotal = entityhuman.expTotal;
this.exp = entityhuman.exp;
this.q = entityhuman.q;
}
2011-01-29 22:50:29 +01:00
}