All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.minecraft.server.EntityHuman Maven / Gradle / Ivy

package net.minecraft.server;

import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import com.mojang.authlib.GameProfile;
import org.bukkit.craftbukkit.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.entity.CraftItem;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityCombustByEntityEvent;
import org.bukkit.event.player.*;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.List;
import java.util.UUID;
// CraftBukkit end

public abstract class EntityHuman extends EntityLiving {
	
	private final GameProfile bH;
	private final boolean bI = false;
	public PlayerInventory inventory = new PlayerInventory(this);
	public Container defaultContainer;
	public Container activeContainer;
	public float bn;
	public float bo;
	public int bp;
	public double bq;
	public double br;
	public double bs;
	public double bt;
	public double bu;
	public double bv;
	public boolean sleeping;
	public BlockPosition bx;
	public int sleepTicks;
	public float by;
	public float bz;
	public PlayerAbilities abilities = new PlayerAbilities();
	public int expLevel;
	public int expTotal;
	public float exp;
	public EntityFishingHook hookedFish;
	// CraftBukkit start
	public boolean fauxSleeping;
	public String spawnWorld = "";
	public int oldLevel = -1;
	protected FoodMetaData foodData = new FoodMetaData(this); // CraftBukkit - add "this" to constructor
	protected int bm;
	protected float bE = 0.1F;
	protected float bF = 0.02F;
	private InventoryEnderChest enderChest = new InventoryEnderChest();
	private BlockPosition c;
	private boolean d;
	private BlockPosition e;
	private int f;
	private ItemStack g;
	private int h;
	private int i;
	
	public EntityHuman(World world, GameProfile gameprofile) {
		super(world);
		this.uniqueID = a(gameprofile);
		this.bH = gameprofile;
		this.defaultContainer = new ContainerPlayer(this.inventory, !world.isClientSide, this);
		this.activeContainer = this.defaultContainer;
		BlockPosition blockposition = world.getSpawn();
		
		this.setPositionRotation((double) blockposition.getX() + 0.5D, blockposition.getY() + 1, (double) blockposition.getZ() + 0.5D, 0.0F, 0.0F);
		this.unused180 = 180.0F;
		this.maxFireTicks = 20;
	}
	// CraftBukkit end
	
	public static BlockPosition getBed(World world, BlockPosition blockposition, boolean flag) {
		((ChunkProviderServer) world.chunkProvider).getChunkAt(blockposition.getX() >> 4, blockposition.getZ() >> 4); // CraftBukkit
		Block block = world.getType(blockposition).getBlock();
		
		if (block != Blocks.BED) {
			if (!flag) {
				return null;
			} else {
				boolean flag1 = block.g();
				boolean flag2 = world.getType(blockposition.up()).getBlock().g();
				
				return flag1 && flag2 ? blockposition : null;
			}
		} else {
			return BlockBed.a(world, blockposition, 0);
		}
	}
	
	public void setFoodData(FoodMetaData foodData) {
		this.foodData = foodData;
	}
	
	public static UUID a(GameProfile gameprofile) {
		UUID uuid = gameprofile.getId();
		
		if (uuid == null) {
			uuid = b(gameprofile.getName());
		}
		
		return uuid;
	}
	
	public static UUID b(String s) {
		return UUID.nameUUIDFromBytes(("OfflinePlayer:" + s).getBytes(Charsets.UTF_8));
	}
	
	@Override
	public CraftHumanEntity getBukkitEntity() {
		return (CraftHumanEntity) super.getBukkitEntity();
	}
	
	protected void initAttributes() {
		super.initAttributes();
		this.getAttributeMap().b(GenericAttributes.ATTACK_DAMAGE).setValue(1.0D);
		this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(0.10000000149011612D);
	}
	
	protected void entityInit() {
		super.entityInit();
		this.datawatcher.a(16, (byte) 0);
		this.datawatcher.a(17, 0.0F);
		this.datawatcher.a(18, 0);
		this.datawatcher.a(10, (byte) 0);
	}
	
	public boolean bS() {
		return this.g != null;
	}
	
	public void bU() {
		if (this.g != null) {
			this.g.onPlayerStoppedUsing(this.world, this, this.h);
		}
		
		this.bV();
	}
	
	public void bV() {
		this.g = null;
		this.h = 0;
		if (!this.world.isClientSide) {
			this.setEating(false);
		}
		
	}
	
	public boolean isBlocking() {
		return this.bS() && this.g.getItem().e(this.g) == EnumAnimation.BLOCK;
	}
	
	public void onUpdate() {
		this.noclip = this.isSpectator();
		if (this.isSpectator()) {
			this.onGround = false;
		}
		
		if (this.g != null) {
			ItemStack itemstack = this.inventory.getItemInHand();
			
			if (itemstack == this.g) {
				if (this.h <= 25 && this.h % 4 == 0) {
					this.b(itemstack, 5);
				}
				
				if (--this.h == 0 && !this.world.isClientSide) {
					this.s();
				}
			} else {
				this.bV();
			}
		}
		
		if (this.bp > 0) {
			--this.bp;
		}
		
		if (this.isSleeping()) {
			++this.sleepTicks;
			if (this.sleepTicks > 100) {
				this.sleepTicks = 100;
			}
			
			if (!this.world.isClientSide) {
				if (!this.p()) {
					this.a(true, true, false);
				} else if (this.world.w()) {
					this.a(false, true, true);
				}
			}
		} else if (this.sleepTicks > 0) {
			++this.sleepTicks;
			if (this.sleepTicks >= 110) {
				this.sleepTicks = 0;
			}
		}
		
		super.onUpdate();
		if (!this.world.isClientSide && this.activeContainer != null && !this.activeContainer.a(this)) {
			this.closeInventory();
			this.activeContainer = this.defaultContainer;
		}
		
		if (this.isBurning() && this.abilities.isInvulnerable) {
			this.extinguish();
		}
		
		this.bq = this.bt;
		this.br = this.bu;
		this.bs = this.bv;
		double d0 = this.locX - this.bt;
		double d1 = this.locY - this.bu;
		double d2 = this.locZ - this.bv;
		double d3 = 10.0D;
		
		if (d0 > d3) {
			this.bq = this.bt = this.locX;
		}
		
		if (d2 > d3) {
			this.bs = this.bv = this.locZ;
		}
		
		if (d1 > d3) {
			this.br = this.bu = this.locY;
		}
		
		if (d0 < -d3) {
			this.bq = this.bt = this.locX;
		}
		
		if (d2 < -d3) {
			this.bs = this.bv = this.locZ;
		}
		
		if (d1 < -d3) {
			this.br = this.bu = this.locY;
		}
		
		this.bt += d0 * 0.25D;
		this.bv += d2 * 0.25D;
		this.bu += d1 * 0.25D;
		if (this.vehicle == null) {
			this.e = null;
		}
		
		if (!this.world.isClientSide) {
			this.foodData.a(this);
			this.b(StatisticList.g);
			if (this.isAlive()) {
				this.b(StatisticList.h);
			}
		}
		
		int i = 29999999;
		double d4 = MathHelper.a(this.locX, -2.9999999E7D, 2.9999999E7D);
		double d5 = MathHelper.a(this.locZ, -2.9999999E7D, 2.9999999E7D);
		
		if (d4 != this.locX || d5 != this.locZ) {
			this.setPosition(d4, this.locY, d5);
		}
		
	}
	
	public int getMaxInPortalTime() {
		return this.abilities.isInvulnerable ? 0 : 80;
	}
	
	protected String getSwimSound() {
		return "game.player.swim";
	}
	
	protected String getSplashSound() {
		return "game.player.swim.splash";
	}
	
	public int getPortalCooldown() {
		return 10;
	}
	
	public void playSound(String s, float f, float f1) {
		this.world.a(this, s, f, f1);
	}
	
	protected void b(ItemStack itemstack, int i) {
		if (itemstack.getItemAnimation() == EnumAnimation.DRINK) {
			this.playSound("random.drink", 0.5F, this.world.random.nextFloat() * 0.1F + 0.9F);
		}
		
		if (itemstack.getItemAnimation() == EnumAnimation.EAT) {
			for (int j = 0; j < i; ++j) {
				Vec3D vec3d = new Vec3D(((double) this.random.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D);
				
				vec3d = vec3d.a(-this.pitch * 3.1415927F / 180.0F);
				vec3d = vec3d.b(-this.yaw * 3.1415927F / 180.0F);
				double d0 = (double) (-this.random.nextFloat()) * 0.6D - 0.3D;
				Vec3D vec3d1 = new Vec3D(((double) this.random.nextFloat() - 0.5D) * 0.3D, d0, 0.6D);
				
				vec3d1 = vec3d1.a(-this.pitch * 3.1415927F / 180.0F);
				vec3d1 = vec3d1.b(-this.yaw * 3.1415927F / 180.0F);
				vec3d1 = vec3d1.add(this.locX, this.locY + (double) this.getHeadHeight(), this.locZ);
				if (itemstack.getHasSubtypes()) {
					this.world.addParticle(EnumParticle.ITEM_CRACK, vec3d1.a, vec3d1.b, vec3d1.c, vec3d.a, vec3d.b + 0.05D, vec3d.c, Item.getId(itemstack.getItem()), itemstack.getData());
				} else {
					this.world.addParticle(EnumParticle.ITEM_CRACK, vec3d1.a, vec3d1.b, vec3d1.c, vec3d.a, vec3d.b + 0.05D, vec3d.c, Item.getId(itemstack.getItem()));
				}
			}
			
			this.playSound("random.eat", 0.5F + 0.5F * (float) this.random.nextInt(2), (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
		}
		
	}
	
	protected void s() {
		if (this.g != null) {
			this.b(this.g, 16);
			int i = this.g.count;
			
			// CraftBukkit start - fire PlayerItemConsumeEvent
			org.bukkit.inventory.ItemStack craftItem = CraftItemStack.asBukkitCopy(this.g);
			PlayerItemConsumeEvent event = new PlayerItemConsumeEvent((Player) this.getBukkitEntity(), craftItem);
			world.getServer().getPluginManager().callEvent(event);
			
			if (event.isCancelled()) {
				// Update client
				if (this instanceof EntityPlayer) {
					((EntityPlayer) this).playerConnection.sendPacket(new PacketPlayOutSetSlot((byte) 0, activeContainer.getSlot(this.inventory, this.inventory.itemInHandIndex).index, this.g));
					// Spigot Start
					((EntityPlayer) this).getBukkitEntity().updateInventory();
					((EntityPlayer) this).getBukkitEntity().updateScaledHealth();
					// Spigot End
				}
				return;
			}
			
			// Plugin modified the item, process it but don't remove it
			if (!craftItem.equals(event.getItem())) {
				CraftItemStack.asNMSCopy(event.getItem()).onItemUseFinish(this.world, this);
				
				// Update client
				if (this instanceof EntityPlayer) {
					((EntityPlayer) this).playerConnection.sendPacket(new PacketPlayOutSetSlot((byte) 0, activeContainer.getSlot(this.inventory, this.inventory.itemInHandIndex).index, this.g));
				}
				return;
			}
			// CraftBukkit end
			
			ItemStack itemstack = this.g.onItemUseFinish(this.world, this);
			
			if (itemstack != this.g || itemstack != null && itemstack.count != i) {
				this.inventory.items[this.inventory.itemInHandIndex] = itemstack;
				if (itemstack.count == 0) {
					this.inventory.items[this.inventory.itemInHandIndex] = null;
				}
			}
			
			this.bV();
		}
		
	}
	
	protected boolean isMovementBlocked() {
		return this.getHealth() <= 0.0F || this.isSleeping();
	}
	
	public void closeInventory() {
		this.activeContainer = this.defaultContainer;
	}
	
	public void updateRidden() {
		if (!this.world.isClientSide && this.isSneaking()) {
			this.mount(null);
			this.setSneaking(false);
		} else {
			double d0 = this.locX;
			double d1 = this.locY;
			double d2 = this.locZ;
			float f = this.yaw;
			float f1 = this.pitch;
			
			super.updateRidden();
			this.bn = this.bo;
			this.bo = 0.0F;
			this.l(this.locX - d0, this.locY - d1, this.locZ - d2);
			if (this.vehicle instanceof EntityPig) {
				this.pitch = f1;
				this.yaw = f;
				this.renderYawOffset = ((EntityPig) this.vehicle).renderYawOffset;
			}
			
		}
	}
	
	protected void doTick() {
		super.doTick();
		this.updateArmSwingProgress();
		this.rotationYawHead = this.yaw;
	}
	
	public void onLivingUpdate() {
		if (this.bm > 0) {
			--this.bm;
		}
		
		if (this.world.getDifficulty() == EnumDifficulty.PEACEFUL && this.world.getGameRules().getBoolean("naturalRegeneration")) {
			if (this.getHealth() < this.getMaxHealth() && this.ticksLived % 20 == 0) {
				// CraftBukkit - added regain reason of "REGEN" for filtering purposes.
				this.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.REGEN);
			}
			
			if (this.foodData.c() && this.ticksLived % 10 == 0) {
				this.foodData.a(this.foodData.getFoodLevel() + 1);
			}
		}
		
		this.inventory.k();
		this.bn = this.bo;
		super.onLivingUpdate();
		AttributeInstance attributeinstance = this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED);
		
		if (!this.world.isClientSide) {
			attributeinstance.setValue(this.abilities.b());
		}
		
		this.jumpMovementFactor = this.bF;
		if (this.isSprinting()) {
			this.jumpMovementFactor = (float) ((double) this.jumpMovementFactor + (double) this.bF * 0.3D);
		}
		
		this.setAIMoveSpeed((float) attributeinstance.getValue());
		float f = MathHelper.sqrt(this.motX * this.motX + this.motZ * this.motZ);
		float f1 = (float) (org.bukkit.craftbukkit.TrigMath.atan(-this.motY * 0.20000000298023224D) * 15.0D); // CraftBukkit
		
		if (f > 0.1F) {
			f = 0.1F;
		}
		
		if (!this.onGround || this.getHealth() <= 0.0F) {
			f = 0.0F;
		}
		
		if (this.onGround || this.getHealth() <= 0.0F) {
			f1 = 0.0F;
		}
		
		this.bo += (f - this.bo) * 0.4F;
		this.cameraPitch += (f1 - this.cameraPitch) * 0.8F;
		if (this.getHealth() > 0.0F && !this.isSpectator()) {
			AxisAlignedBB axisalignedbb;
			
			if (this.vehicle != null && !this.vehicle.dead) {
				axisalignedbb = this.getBoundingBox().a(this.vehicle.getBoundingBox()).grow(1.0D, 0.0D, 1.0D);
			} else {
				axisalignedbb = this.getBoundingBox().grow(1.0D, 0.5D, 1.0D);
			}
			
			if (this.canBePushed()) { // Spigot: Add this.ae() condition (second !this.isDead near bottom of EntityLiving)
				List list = this.world.getEntities(this, axisalignedbb);
				
				for (Entity o : list) {
					
					if (!o.dead) {
						this.d(o);
					}
				}
			} // Spigot
		}
		
	}
	
	private void d(Entity entity) {
		entity.onCollideWithPlayer(this);
	}
	
	public int getScore() {
		return this.datawatcher.getInt(18);
	}
	
	public void setScore(int i) {
		this.datawatcher.watch(18, i);
	}
	
	public void addScore(int i) {
		int j = this.getScore();
		
		this.datawatcher.watch(18, j + i);
	}
	
	public void onDeath(DamageSource cause) {
		super.onDeath(cause);
		this.setSize(0.2F, 0.2F);
		this.setPosition(this.locX, this.locY, this.locZ);
		this.motY = 0.10000000149011612D;
		if (this.getName().equals("Notch")) {
			this.a(new ItemStack(Items.APPLE, 1), true, false);
		}
		
		if (!this.world.getGameRules().getBoolean("keepInventory")) {
			this.inventory.n();
		}
		
		if (cause != null) {
			this.motX = -MathHelper.cos((this.attackedAtYaw + this.yaw) * 3.1415927F / 180.0F) * 0.1F;
			this.motZ = -MathHelper.sin((this.attackedAtYaw + this.yaw) * 3.1415927F / 180.0F) * 0.1F;
		} else {
			this.motX = this.motZ = 0.0D;
		}
		
		this.b(StatisticList.y);
		this.a(StatisticList.h);
	}
	
	protected String getHurtSound() {
		return "game.player.hurt";
	}
	
	protected String getDeathSound() {
		return "game.player.die";
	}
	
	public void addToPlayerScore(Entity entity, int i) {
		this.addScore(i);
		// CraftBukkit - Get our scores instead
		Collection collection = this.world.getServer().getScoreboardManager().getScoreboardScores(IScoreboardCriteria.f, this.getName(), new java.util.ArrayList());
		
		if (entity instanceof EntityHuman) {
			this.b(StatisticList.B);
			// CraftBukkit - Get our scores instead
			this.world.getServer().getScoreboardManager().getScoreboardScores(IScoreboardCriteria.e, this.getName(), collection);
			collection.addAll(this.e(entity));
		} else {
			this.b(StatisticList.z);
		}
		
		// CraftBukkit - Use our scores instead
		for (ScoreboardScore scoreboardscore : collection) {
			scoreboardscore.incrementScore();
		}
		
	}
	
	private Collection e(Entity entity) { // CraftBukkit - TODO: Check me?
		ScoreboardTeam scoreboardteam = this.getScoreboard().getPlayerTeam(this.getName());
		
		if (scoreboardteam != null) {
			int i = scoreboardteam.l().b();
			
			if (i >= 0 && i < IScoreboardCriteria.i.length) {
				
				for (ScoreboardObjective scoreboardobjective : this.getScoreboard().getObjectivesForCriteria(IScoreboardCriteria.i[i])) {
					ScoreboardScore scoreboardscore = this.getScoreboard().getPlayerScoreForObjective(entity.getName(), scoreboardobjective);
					
					scoreboardscore.incrementScore();
				}
			}
		}
		
		ScoreboardTeam scoreboardteam1 = this.getScoreboard().getPlayerTeam(entity.getName());
		
		if (scoreboardteam1 != null) {
			int j = scoreboardteam1.l().b();
			
			if (j >= 0 && j < IScoreboardCriteria.h.length) {
				return this.getScoreboard().getObjectivesForCriteria(IScoreboardCriteria.h[j]);
			}
		}
		
		return Lists.newArrayList();
	}
	
	public EntityItem a(boolean flag) {
		// Called only when dropped by Q or CTRL-Q
		return this.a(this.inventory.splitStack(this.inventory.itemInHandIndex, flag && this.inventory.getItemInHand() != null ? this.inventory.getItemInHand().count : 1), false, true);
	}
	
	public EntityItem drop(ItemStack itemstack, boolean flag) {
		return this.a(itemstack, false, false);
	}
	
	public EntityItem a(ItemStack itemstack, boolean flag, boolean flag1) {
		if (itemstack == null) {
			return null;
		} else if (itemstack.count == 0) {
			return null;
		} else {
			double d0 = this.locY - 0.30000001192092896D + (double) this.getHeadHeight();
			EntityItem entityitem = new EntityItem(this.world, this.locX, d0, this.locZ, itemstack);
			
			entityitem.a(40);
			if (flag1) {
				entityitem.c(this.getName());
			}
			
			float f;
			float f1;
			
			if (flag) {
				f = this.random.nextFloat() * 0.5F;
				f1 = this.random.nextFloat() * 3.1415927F * 2.0F;
				entityitem.motX = -MathHelper.sin(f1) * f;
				entityitem.motZ = MathHelper.cos(f1) * f;
				entityitem.motY = 0.20000000298023224D;
			} else {
				f = 0.3F;
				entityitem.motX = -MathHelper.sin(this.yaw / 180.0F * 3.1415927F) * MathHelper.cos(this.pitch / 180.0F * 3.1415927F) * f;
				entityitem.motZ = MathHelper.cos(this.yaw / 180.0F * 3.1415927F) * MathHelper.cos(this.pitch / 180.0F * 3.1415927F) * f;
				entityitem.motY = -MathHelper.sin(this.pitch / 180.0F * 3.1415927F) * f + 0.1F;
				f1 = this.random.nextFloat() * 3.1415927F * 2.0F;
				f = 0.02F * this.random.nextFloat();
				entityitem.motX += Math.cos(f1) * (double) f;
				entityitem.motY += (this.random.nextFloat() - this.random.nextFloat()) * 0.1F;
				entityitem.motZ += Math.sin(f1) * (double) f;
			}
			
			// CraftBukkit start - fire PlayerDropItemEvent
			Player player = (Player) this.getBukkitEntity();
			CraftItem drop = new CraftItem(this.world.getServer(), entityitem);
			
			PlayerDropItemEvent event = new PlayerDropItemEvent(player, drop);
			this.world.getServer().getPluginManager().callEvent(event);
			
			if (event.isCancelled()) {
				org.bukkit.inventory.ItemStack cur = player.getInventory().getItemInHand();
				if (flag1 && (cur == null || cur.getAmount() == 0)) {
					// The complete stack was dropped
					player.getInventory().setItemInHand(drop.getItemStack());
				} else if (flag1 && cur.isSimilar(drop.getItemStack()) && drop.getItemStack().getAmount() == 1) {
					// Only one item is dropped
					cur.setAmount(cur.getAmount() + 1);
					player.getInventory().setItemInHand(cur);
				} else {
					// Fallback
					player.getInventory().addItem(drop.getItemStack());
				}
				return null;
			}
			// CraftBukkit end
			
			this.a(entityitem);
			if (flag1) {
				this.b(StatisticList.v);
			}
			
			return entityitem;
		}
	}
	
	protected void a(EntityItem entityitem) {
		this.world.addEntity(entityitem);
	}
	
	public float a(Block block) {
		return this.a(block, null);
	}
	
	public float a(Block block, BlockPosition position) {
		float f = this.inventory.a(block, position);
		
		if (f > 1.0F) {
			int i = EnchantmentManager.getDigSpeedEnchantmentLevel(this);
			ItemStack itemstack = this.inventory.getItemInHand();
			
			if (i > 0 && itemstack != null) {
				f += (float) (i * i + 1);
			}
		}
		
		if (this.hasEffect(MobEffectList.FASTER_DIG)) {
			f *= 1.0F + (float) (this.getEffect(MobEffectList.FASTER_DIG).getAmplifier() + 1) * 0.2F;
		}
		
		if (this.hasEffect(MobEffectList.SLOWER_DIG)) {
			float f1;
			
			switch (this.getEffect(MobEffectList.SLOWER_DIG).getAmplifier()) {
				case 0:
					f1 = 0.3F;
					break;
				
				case 1:
					f1 = 0.09F;
					break;
				
				case 2:
					f1 = 0.0027F;
					break;
				
				case 3:
				default:
					f1 = 8.1E-4F;
			}
			
			f *= f1;
		}
		
		if (this.isInsideOfMaterial(Material.WATER) && !EnchantmentManager.j(this)) {
			f /= 5.0F;
		}
		
		if (!this.onGround) {
			f /= 5.0F;
		}
		
		return f;
	}
	
	public boolean b(Block block) {
		return this.inventory.b(block);
	}
	
	public void loadEntityData(NBTTagCompound tag) {
		super.loadEntityData(tag);
		this.uniqueID = a(this.bH);
		NBTTagList nbttaglist = tag.getList("Inventory", 10);
		
		this.inventory.b(nbttaglist);
		this.inventory.itemInHandIndex = tag.getInt("SelectedItemSlot");
		this.sleeping = tag.getBoolean("Sleeping");
		this.sleepTicks = tag.getShort("SleepTimer");
		this.exp = tag.getFloat("XpP");
		this.expLevel = tag.getInt("XpLevel");
		this.expTotal = tag.getInt("XpTotal");
		this.f = tag.getInt("XpSeed");
		if (this.f == 0) {
			this.f = this.random.nextInt();
		}
		
		this.setScore(tag.getInt("Score"));
		if (this.sleeping) {
			this.bx = new BlockPosition(this);
			this.a(true, true, false);
		}
		
		// CraftBukkit start
		this.spawnWorld = tag.getString("SpawnWorld");
		if ("".equals(spawnWorld)) {
			this.spawnWorld = this.world.getServer().getWorlds().get(0).getName();
		}
		// CraftBukkit end
		
		if (tag.hasKeyOfType("SpawnX", 99) && tag.hasKeyOfType("SpawnY", 99) && tag.hasKeyOfType("SpawnZ", 99)) {
			this.c = new BlockPosition(tag.getInt("SpawnX"), tag.getInt("SpawnY"), tag.getInt("SpawnZ"));
			this.d = tag.getBoolean("SpawnForced");
		}
		
		this.foodData.a(tag);
		this.abilities.b(tag);
		if (tag.hasKeyOfType("EnderItems", 9)) {
			NBTTagList nbttaglist1 = tag.getList("EnderItems", 10);
			
			this.enderChest.a(nbttaglist1);
		}
		
	}
	
	public void saveEntityData(NBTTagCompound tag) {
		super.saveEntityData(tag);
		tag.set("Inventory", this.inventory.a(new NBTTagList()));
		tag.setInt("SelectedItemSlot", this.inventory.itemInHandIndex);
		tag.setBoolean("Sleeping", this.sleeping);
		tag.setShort("SleepTimer", (short) this.sleepTicks);
		tag.setFloat("XpP", this.exp);
		tag.setInt("XpLevel", this.expLevel);
		tag.setInt("XpTotal", this.expTotal);
		tag.setInt("XpSeed", this.f);
		tag.setInt("Score", this.getScore());
		if (this.c != null) {
			tag.setInt("SpawnX", this.c.getX());
			tag.setInt("SpawnY", this.c.getY());
			tag.setInt("SpawnZ", this.c.getZ());
			tag.setBoolean("SpawnForced", this.d);
		}
		
		this.foodData.b(tag);
		this.abilities.a(tag);
		tag.set("EnderItems", this.enderChest.h());
		ItemStack itemstack = this.inventory.getItemInHand();
		
		if (itemstack != null && itemstack.getItem() != null) {
			tag.set("SelectedItem", itemstack.writeToNBT(new NBTTagCompound()));
		}
		tag.setString("SpawnWorld", spawnWorld); // CraftBukkit - fixes bed spawns for multiworld worlds
		
	}
	
	public boolean damageEntity(DamageSource damagesource, float f) {
		if (this.isInvulnerable(damagesource)) {
			return false;
		} else if (this.abilities.isInvulnerable && !damagesource.ignoresInvulnerability()) {
			return false;
		} else {
			this.ticksFarFromPlayer = 0;
			if (this.getHealth() <= 0.0F) {
				return false;
			} else {
				if (this.isSleeping() && !this.world.isClientSide) {
					this.a(true, true, false);
				}
				
				if (damagesource.r()) {
					if (this.world.getDifficulty() == EnumDifficulty.PEACEFUL) {
						return false; // CraftBukkit - f = 0.0f -> return false
					}
					
					if (this.world.getDifficulty() == EnumDifficulty.EASY) {
						f = f / 2.0F + 1.0F;
					}
					
					if (this.world.getDifficulty() == EnumDifficulty.HARD) {
						f = f * 3.0F / 2.0F;
					}
				}
				
				//Entity entity = damagesource.getEntity();
				return super.damageEntity(damagesource, f);
			}
		}
	}
	
	public boolean a(EntityHuman entityhuman) {
		// CraftBukkit start - Change to check OTHER player's scoreboard team according to API
		// To summarize this method's logic, it's "Can parameter hurt this"
		org.bukkit.scoreboard.Team team;
		if (entityhuman instanceof EntityPlayer) {
			EntityPlayer thatPlayer = (EntityPlayer) entityhuman;
			team = thatPlayer.getBukkitEntity().getScoreboard().getPlayerTeam(thatPlayer.getBukkitEntity());
		} else {
			// This should never be called, but is implemented anyway
			
			// org.bukkit.OfflinePlayer thisPlayer = entityhuman.world.getServer().getOfflinePlayer(entityhuman.getName());
			org.bukkit.OfflinePlayer thisPlayer = entityhuman.world.getServer().getOfflinePlayer(entityhuman.uniqueID);
			team = entityhuman.world.getServer().getScoreboardManager().getMainScoreboard().getPlayerTeam(thisPlayer);
			
		}
		if (team == null || team.allowFriendlyFire()) {
			return true;
		}
		
		if (this instanceof EntityPlayer) {
			return !team.hasPlayer(((EntityPlayer) this).getBukkitEntity());
		}
		//return !team.hasPlayer(this.world.getServer().getOfflinePlayer(this.getName()));
     return !team.hasPlayer(this.world.getServer().getOfflinePlayer(uniqueID));
	}
	
	protected void damageArmor(float f) {
		this.inventory.a(f);
	}
	
	public int getTotalArmorValue() {
		return this.inventory.m();
	}
	
	public float bY() {
		int i = 0;
		ItemStack[] aitemstack = this.inventory.armor;
		int j = aitemstack.length;
		
		for (ItemStack itemstack : aitemstack) {
			if (itemstack != null) {
				++i;
			}
		}
		
		return (float) i / (float) this.inventory.armor.length;
	}
	
	// CraftBukkit start
	protected boolean damage(DamageSource source, float amount) { // void -> boolean
     return super.damage(source, amount);
		/*
		// CraftBukkit end
		if (!this.isInvulnerable(source)) {
			if (!source.ignoresArmor() && this.isBlocking() && amount > 0.0F) {
				amount = (1.0F + amount) * 0.5F;
			}
			
			amount = this.applyArmorModifier(source, amount);
			amount = this.applyMagicModifier(source, amount);
			float f1 = amount;
			
			amount = Math.max(amount - this.getAbsorptionHearts(), 0.0F);
			this.setAbsorptionHearts(this.getAbsorptionHearts() - (f1 - amount));
			if (amount != 0.0F) {
				this.applyExhaustion(source.getExhaustionCost());
				float f2 = this.getHealth();
				
				this.setHealth(this.getHealth() - amount);
				this.getCombatTracker().a(source, f2, amount);
				if (amount < 3.4028235E37F) {
					this.a(StatisticList.x, Math.round(amount * 10.0F));
				}
				
			}
		}
     */
  }
	
	public void openSign(TileEntitySign tileentitysign) {
	}
	
	public void a(CommandBlockListenerAbstract commandblocklistenerabstract) {
	}
	
	public void openTrade(IMerchant imerchant) {
	}
	
	public void openContainer(IInventory iinventory) {
	}
	
	public void openHorseInventory(EntityHorse entityhorse, IInventory iinventory) {
	}
	
	public void openTileEntity(ITileEntityContainer itileentitycontainer) {
	}
	
	public void openBook(ItemStack itemstack) {
	}
	
	public boolean u(Entity entity) {
		if (this.isSpectator()) {
			if (entity instanceof IInventory) {
				this.openContainer((IInventory) entity);
			}
			
			return false;
		} else {
			ItemStack itemstack = this.bZ();
			ItemStack itemstack1 = itemstack != null ? itemstack.cloneItemStack() : null;
			
			if (!entity.interactFirst(this)) {
				if (itemstack != null && entity instanceof EntityLiving) {
					if (this.abilities.canInstantlyBuild) {
						itemstack = itemstack1;
					}
					
					if (itemstack.interactWithEntity(this, (EntityLiving) entity)) {
						// CraftBukkit - bypass infinite items; <= 0 -> == 0
						if (itemstack.count == 0 && !this.abilities.canInstantlyBuild) {
							this.ca();
						}
						
						return true;
					}
				}
				
				return false;
			} else {
				if (itemstack != null && itemstack == this.bZ()) {
					if (itemstack.count <= 0 && !this.abilities.canInstantlyBuild) {
						this.ca();
					} else if (itemstack.count < itemstack1.count && this.abilities.canInstantlyBuild) {
						itemstack.count = itemstack1.count;
					}
				}
				
				return true;
			}
		}
	}
	
	public ItemStack bZ() {
		return this.inventory.getItemInHand();
	}
	
	public void ca() {
		this.inventory.setItem(this.inventory.itemInHandIndex, null);
	}
	
	public double getYOffset() {
		return -0.35D;
	}
	
	public void attack(Entity entity) {
		if (entity.canAttackWithItem()) {
			if (!entity.hitByEntity(this)) {
				float f = (float) this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).getValue();
				byte b0 = 0;
				float f1;
				
				if (entity instanceof EntityLiving) {
					f1 = EnchantmentManager.a(this.getHeldItem(), ((EntityLiving) entity).getMonsterType());
				} else {
					f1 = EnchantmentManager.a(this.getHeldItem(), EnumMonsterType.UNDEFINED);
				}
				
				long i = b0 + EnchantmentManager.a(this);
				
				if (this.isSprinting()) {
					++i;
				}
				
				if (f > 0.0F || f1 > 0.0F) {
					boolean flag = this.fallDistance > 0.0F && !this.onGround && !this.isOnLadder() && !this.isInWater() && !this.hasEffect(MobEffectList.BLINDNESS) && this.vehicle == null && entity instanceof EntityLiving;
					
					if (flag && f > 0.0F) {
						f *= 1.5F;
					}
					
					f += f1;
					boolean flag1 = false;
					int j = EnchantmentManager.getFireAspectEnchantmentLevel(this);
					
					if (entity instanceof EntityLiving && j > 0 && !entity.isBurning()) {
						// CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item
						EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), 1);
						org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
						
						if (!combustEvent.isCancelled()) {
							flag1 = true;
							entity.setOnFire(combustEvent.getDuration());
						}
						// CraftBukkit end
					}
					
					double d0 = entity.motX;
					double d1 = entity.motY;
					double d2 = entity.motZ;
					boolean flag2 = entity.damageEntity(DamageSource.playerAttack(this), f);
					
					if (flag2) {
						if (i > 0) {
							entity.addVelocity(-MathHelper.sin(this.yaw * 3.1415927F / 180.0F) * (float) i * 0.5F, 0.1D, MathHelper.cos(this.yaw * 3.1415927F / 180.0F) * (float) i * 0.5F);
							this.motX *= 0.6D;
							this.motZ *= 0.6D;
							this.setSprinting(false);
						}
						
						if (entity instanceof EntityPlayer && entity.velocityChanged) {
							// CraftBukkit start - Add Velocity Event
							boolean cancelled = false;
							Player player = (Player) entity.getBukkitEntity();
							org.bukkit.util.Vector velocity = new Vector(d0, d1, d2);
							
							PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
							world.getServer().getPluginManager().callEvent(event);
							
							if (event.isCancelled()) {
								cancelled = true;
							} else if (!velocity.equals(event.getVelocity())) {
								player.setVelocity(event.getVelocity());
							}
							
							if (!cancelled) {
								((EntityPlayer) entity).playerConnection.sendPacket(new PacketPlayOutEntityVelocity(entity));
								entity.velocityChanged = false;
								entity.motX = d0;
								entity.motY = d1;
								entity.motZ = d2;
							}
							// CraftBukkit end
						}
						
						if (flag) {
							this.b(entity);
						}
						
						if (f1 > 0.0F) {
							this.c(entity);
						}
						
						if (f >= 18.0F) {
							this.b(AchievementList.F);
						}
						
						this.setLastAttacker(entity);
						if (entity instanceof EntityLiving) {
							EnchantmentManager.a((EntityLiving) entity, this);
						}
						
						EnchantmentManager.b(this, entity);
						ItemStack itemstack = this.bZ();
						Object object = entity;
						
						if (entity instanceof EntityComplexPart) {
							IComplex icomplex = ((EntityComplexPart) entity).owner;
							
							if (icomplex instanceof EntityLiving) {
								object = icomplex;
							}
						}
						
						if (itemstack != null && object instanceof EntityLiving) {
							itemstack.hitEntity((EntityLiving) object, this);
							// CraftBukkit - bypass infinite items; <= 0 -> == 0
							if (itemstack.count == 0) {
								this.ca();
							}
						}
						
						if (entity instanceof EntityLiving) {
							this.a(StatisticList.w, Math.round(f * 10.0F));
							if (j > 0) {
								// CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item
								EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), j * 4);
								org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
								
								if (!combustEvent.isCancelled()) {
									entity.setOnFire(combustEvent.getDuration());
								}
								// CraftBukkit end
							}
						}
						
						this.applyExhaustion(world.spigotConfig.combatExhaustion); // Spigot - Change to use configurable value
					} else if (flag1) {
						entity.extinguish();
					}
				}
				
			}
		}
	}
	
	public void b(Entity entity) {
	}
	
	public void c(Entity entity) {
	}
	
	@NotNull
	@Override
	public HumanEntity getEntityBukkit() {
		return (HumanEntity) super.getEntityBukkit();
	}
	
	public void die() {
		super.die();
		this.defaultContainer.b(this);
		if (this.activeContainer != null) {
			this.activeContainer.b(this);
		}
		
	}
	
	public boolean inBlock() {
		return !this.sleeping && super.inBlock();
	}
	
	public GameProfile getProfile() {
		return this.bH;
	}
	
	public EntityHuman.EnumBedResult a(BlockPosition blockposition) {
		if (!this.world.isClientSide) {
			if (this.isSleeping() || !this.isAlive()) {
				return EntityHuman.EnumBedResult.OTHER_PROBLEM;
			}
			
			if (!this.world.worldProvider.d()) {
				return EntityHuman.EnumBedResult.NOT_POSSIBLE_HERE;
			}
			
			if (this.world.w()) {
				return EntityHuman.EnumBedResult.NOT_POSSIBLE_NOW;
			}
			
			if (Math.abs(this.locX - (double) blockposition.getX()) > 3.0D || Math.abs(this.locY - (double) blockposition.getY()) > 2.0D || Math.abs(this.locZ - (double) blockposition.getZ()) > 3.0D) {
				return EntityHuman.EnumBedResult.TOO_FAR_AWAY;
			}
			
			double d0 = 8.0D;
			double d1 = 5.0D;
			List list = this.world.a(EntityMonster.class, new AxisAlignedBB((double) blockposition.getX() - d0, (double) blockposition.getY() - d1, (double) blockposition.getZ() - d0, (double) blockposition.getX() + d0, (double) blockposition.getY() + d1, (double) blockposition.getZ() + d0));
			
			if (!list.isEmpty()) {
				return EntityHuman.EnumBedResult.NOT_SAFE;
			}
		}
		
		if (this.isRiding()) {
			this.mount(null);
		}
		
		// CraftBukkit start - fire PlayerBedEnterEvent
		if (this.getBukkitEntity() instanceof Player) {
			Player player = (Player) this.getBukkitEntity();
			org.bukkit.block.Block bed = this.world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
			
			PlayerBedEnterEvent event = new PlayerBedEnterEvent(player, bed);
			this.world.getServer().getPluginManager().callEvent(event);
			
			if (event.isCancelled()) {
				return EnumBedResult.OTHER_PROBLEM;
			}
		}
		// CraftBukkit end
		
		this.setSize(0.2F, 0.2F);
		if (this.world.isLoaded(blockposition)) {
			EnumDirection enumdirection = this.world.getType(blockposition).get(BlockDirectional.FACING);
			float f = 0.5F;
			float f1 = 0.5F;
			
			switch (EntityHuman.SyntheticClass_1.a[enumdirection.ordinal()]) {
				case 1:
					f1 = 0.9F;
					break;
				
				case 2:
					f1 = 0.1F;
					break;
				
				case 3:
					f = 0.1F;
					break;
				
				case 4:
					f = 0.9F;
			}
			
			this.a(enumdirection);
			this.setPosition((float) blockposition.getX() + f, (float) blockposition.getY() + 0.6875F, (float) blockposition.getZ() + f1);
		} else {
			this.setPosition((float) blockposition.getX() + 0.5F, (float) blockposition.getY() + 0.6875F, (float) blockposition.getZ() + 0.5F);
		}
		
		this.sleeping = true;
		this.sleepTicks = 0;
		this.bx = blockposition;
		this.motX = this.motZ = this.motY = 0.0D;
		if (!this.world.isClientSide) {
			this.world.everyoneSleeping();
		}
		
		return EntityHuman.EnumBedResult.OK;
	}
	
	private void a(EnumDirection enumdirection) {
		this.by = 0.0F;
		this.bz = 0.0F;
		switch (EntityHuman.SyntheticClass_1.a[enumdirection.ordinal()]) {
			case 1:
				this.bz = -1.8F;
				break;
			
			case 2:
				this.bz = 1.8F;
				break;
			
			case 3:
				this.by = 1.8F;
				break;
			
			case 4:
				this.by = -1.8F;
		}
		
	}
	
	public void a(boolean flag, boolean flag1, boolean flag2) {
		this.setSize(0.6F, 1.8F);
		IBlockData iblockdata = this.world.getType(this.bx);
		
		if (this.bx != null && iblockdata.getBlock() == Blocks.BED) {
			this.world.setTypeAndData(this.bx, iblockdata.set(BlockBed.OCCUPIED, false), 4);
			BlockPosition blockposition = BlockBed.a(this.world, this.bx, 0);
			
			if (blockposition == null) {
				blockposition = this.bx.up();
			}
			
			this.setPosition((float) blockposition.getX() + 0.5F, (float) blockposition.getY() + 0.1F, (float) blockposition.getZ() + 0.5F);
		}
		
		this.sleeping = false;
		if (!this.world.isClientSide && flag1) {
			this.world.everyoneSleeping();
		}
		
		// CraftBukkit start - fire PlayerBedLeaveEvent
		if (this.getBukkitEntity() instanceof Player) {
			Player player = (Player) this.getBukkitEntity();
			
			org.bukkit.block.Block bed;
			BlockPosition blockposition = this.bx;
			if (blockposition != null) {
				bed = this.world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
			} else {
				bed = this.world.getWorld().getBlockAt(player.getLocation());
			}
			
			PlayerBedLeaveEvent event = new PlayerBedLeaveEvent(player, bed);
			this.world.getServer().getPluginManager().callEvent(event);
		}
		// CraftBukkit end
		
		this.sleepTicks = flag ? 0 : 100;
		if (flag2) {
			this.setRespawnPosition(this.bx, false);
		}
		
	}
	
	private boolean p() {
		return this.world.getType(this.bx).getBlock() == Blocks.BED;
	}
	
	public boolean isSleeping() {
		return this.sleeping;
	}
	
	public boolean isDeeplySleeping() {
		return this.sleeping && this.sleepTicks >= 100;
	}
	
	public void b(IChatBaseComponent ichatbasecomponent) {
	}
	
	public BlockPosition getBed() {
		return this.c;
	}
	
	public boolean isRespawnForced() {
		return this.d;
	}
	
	public void setRespawnPosition(BlockPosition blockposition, boolean flag) {
		if (blockposition != null) {
			this.c = blockposition;
			this.d = flag;
			this.spawnWorld = this.world.worldData.getName(); // CraftBukkit
		} else {
			this.c = null;
			this.d = false;
			this.spawnWorld = ""; // CraftBukkit
		}
		
	}
	
	public void b(Statistic statistic) {
		this.a(statistic, 1);
	}
	
	public void a(Statistic statistic, int i) {
	}
	
	public void a(Statistic statistic) {
	}
	
	public void jump() {
		super.jump();
		this.b(StatisticList.u);
		if (this.isSprinting()) {
			this.applyExhaustion(world.spigotConfig.sprintExhaustion); // Spigot - Change to use configurable value
		} else {
			this.applyExhaustion(world.spigotConfig.walkExhaustion); // Spigot - Change to use configurable value
		}
		
	}
	
	public void moveEntityWithHeading(float strafe, float forward) {
		double d0 = this.locX;
		double d1 = this.locY;
		double d2 = this.locZ;
		
		if (this.abilities.isFlying && this.vehicle == null) {
			double d3 = this.motY;
			float f2 = this.jumpMovementFactor;
			
			this.jumpMovementFactor = this.abilities.a() * (float) (this.isSprinting() ? 2 : 1);
			super.moveEntityWithHeading(strafe, forward);
			this.motY = d3 * 0.6D;
			this.jumpMovementFactor = f2;
		} else {
			super.moveEntityWithHeading(strafe, forward);
		}
		
		this.checkMovement(this.locX - d0, this.locY - d1, this.locZ - d2);
	}
	
	public float getAIMoveSpeed() {
		return (float) this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getValue();
	}
	
	public void checkMovement(double d0, double d1, double d2) {
		if (this.vehicle == null) {
			int i;
			
			if (this.isInsideOfMaterial(Material.WATER)) {
				i = Math.round(MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F);
				if (i > 0) {
					this.a(StatisticList.p, i);
					this.applyExhaustion(0.015F * (float) i * 0.01F);
				}
			} else if (this.isInWater()) {
				i = Math.round(MathHelper.sqrt(d0 * d0 + d2 * d2) * 100.0F);
				if (i > 0) {
					this.a(StatisticList.l, i);
					this.applyExhaustion(0.015F * (float) i * 0.01F);
				}
			} else if (this.isOnLadder()) {
				if (d1 > 0.0D) {
					this.a(StatisticList.n, (int) Math.round(d1 * 100.0D));
				}
			} else if (this.onGround) {
				i = Math.round(MathHelper.sqrt(d0 * d0 + d2 * d2) * 100.0F);
				if (i > 0) {
					this.a(StatisticList.i, i);
					if (this.isSprinting()) {
						this.a(StatisticList.k, i);
						this.applyExhaustion(0.099999994F * (float) i * 0.01F);
					} else {
						if (this.isSneaking()) {
							this.a(StatisticList.j, i);
						}
						
						this.applyExhaustion(0.01F * (float) i * 0.01F);
					}
				}
			} else {
				i = Math.round(MathHelper.sqrt(d0 * d0 + d2 * d2) * 100.0F);
				if (i > 25) {
					this.a(StatisticList.o, i);
				}
			}
			
		}
	}
	
	private void l(double d0, double d1, double d2) {
		if (this.vehicle != null) {
			int i = Math.round(MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F);
			
			if (i > 0) {
				if (this.vehicle instanceof EntityMinecartAbstract) {
					this.a(StatisticList.q, i);
					if (this.e == null) {
						this.e = new BlockPosition(this);
					} else if (this.e.c(MathHelper.floor(this.locX), MathHelper.floor(this.locY), MathHelper.floor(this.locZ)) >= 1000000.0D) {
						this.b(AchievementList.q);
					}
				} else if (this.vehicle instanceof EntityBoat) {
					this.a(StatisticList.r, i);
				} else if (this.vehicle instanceof EntityPig) {
					this.a(StatisticList.s, i);
				} else if (this.vehicle instanceof EntityHorse) {
					this.a(StatisticList.t, i);
				}
			}
		}
		
	}
	
	public void fall(float f, float f1) {
		if (!this.abilities.canFly) {
			if (f >= 2.0F) {
				this.a(StatisticList.m, (int) Math.round((double) f * 100.0D));
			}
			
			super.fall(f, f1);
		}
	}
	
	protected void resetHeight() {
		if (!this.isSpectator()) {
			super.resetHeight();
		}
		
	}
	
	protected String getFallSoundString(int damage) {
		return damage > 4 ? "game.player.hurt.fall.big" : "game.player.hurt.fall.small";
	}
	
	public void onKillEntity(EntityLiving entity) {
		if (entity instanceof IMonster) {
			this.b(AchievementList.s);
		}
		
		EntityTypes.MonsterEggInfo entitytypes_monsteregginfo = EntityTypes.eggInfo.get(EntityTypes.a(entity));
		
		if (entitytypes_monsteregginfo != null) {
			this.b(entitytypes_monsteregginfo.killEntityStatistic);
		}
		
	}
	
	public void setInWeb() {
		if (!this.abilities.isFlying) {
			super.setInWeb();
		}
		
	}
	
	public ItemStack q(int i) {
		return this.inventory.e(i);
	}
	
	public void giveExp(int i) {
		this.addScore(i);
		int j = Integer.MAX_VALUE - this.expTotal;
		
		if (i > j) {
			i = j;
		}
		
		this.exp += (float) i / (float) this.getExpToLevel();
		
		for (this.expTotal += i; this.exp >= 1.0F; this.exp /= (float) this.getExpToLevel()) {
			this.exp = (this.exp - 1.0F) * (float) this.getExpToLevel();
			this.levelDown(1);
		}
		
	}
	
	public int cj() {
		return this.f;
	}
	
	public void enchantDone(int i) {
		this.expLevel -= i;
		if (this.expLevel < 0) {
			this.expLevel = 0;
			this.exp = 0.0F;
			this.expTotal = 0;
		}
		
		this.f = this.random.nextInt();
	}
	
	public void levelDown(int i) {
		this.expLevel += i;
		if (this.expLevel < 0) {
			this.expLevel = 0;
			this.exp = 0.0F;
			this.expTotal = 0;
		}
		
		if (i > 0 && this.expLevel % 5 == 0 && (float) this.i < (float) this.ticksLived - 100.0F) {
			float f = this.expLevel > 30 ? 1.0F : (float) this.expLevel / 30.0F;
			
			this.world.makeSound(this, "random.levelup", f * 0.75F, 1.0F);
			this.i = this.ticksLived;
		}
		
	}
	
	public int getExpToLevel() {
		return this.expLevel >= 30 ? 112 + (this.expLevel - 30) * 9 : (this.expLevel >= 15 ? 37 + (this.expLevel - 15) * 5 : 7 + this.expLevel * 2);
	}
	
	public void applyExhaustion(float f) {
		if (!this.abilities.isInvulnerable) {
			if (!this.world.isClientSide) {
				this.foodData.a(f);
			}
			
		}
	}
	
	public FoodMetaData getFoodData() {
		return this.foodData;
	}
	
	public boolean j(boolean flag) {
		return (flag || this.foodData.c()) && !this.abilities.isInvulnerable;
	}
	
	public boolean cm() {
		return this.getHealth() > 0.0F && this.getHealth() < this.getMaxHealth();
	}
	
	public void a(ItemStack itemstack, int i) {
		if (itemstack != this.g) {
			this.g = itemstack;
			this.h = i;
			if (!this.world.isClientSide) {
				this.setEating(true);
			}
			
		}
	}
	
	public boolean cn() {
		return this.abilities.mayBuild;
	}
	
	public boolean a(BlockPosition blockposition, EnumDirection enumdirection, ItemStack item) {
		if (this.abilities.mayBuild) {
			return true;
		} else if (item == null) {
			return false;
		} else {
			BlockPosition blockposition1 = blockposition.shift(enumdirection.opposite());
			
			return item.canPlaceOn(this.world.getType(blockposition1).getBlock())
				|| item.canEditBlocks()
				|| item.canPlaceBlock((Player) getEntityBukkit(), world.world.getBlockAt(blockposition1));
		}
	}
	
	protected int getExpValue(EntityHuman entityhuman) {
		if (this.world.getGameRules().getBoolean("keepInventory")) {
			return 0;
		} else {
			int i = this.expLevel * 7;
			
			return Math.min(i, 100);
		}
	}
	
	protected boolean alwaysGivesExp() {
		return true;
	}
	
	public void copyTo(EntityHuman entityhuman, boolean flag) {
		if (flag) {
			this.inventory.b(entityhuman.inventory);
			this.setHealth(entityhuman.getHealth());
			this.foodData = entityhuman.foodData;
			this.expLevel = entityhuman.expLevel;
			this.expTotal = entityhuman.expTotal;
			this.exp = entityhuman.exp;
			this.setScore(entityhuman.getScore());
			this.lastPortalPos = entityhuman.lastPortalPos;
			this.lastPortalVec = entityhuman.lastPortalVec;
			this.teleportDirection = entityhuman.teleportDirection;
		} else if (this.world.getGameRules().getBoolean("keepInventory")) {
			this.inventory.b(entityhuman.inventory);
			this.expLevel = entityhuman.expLevel;
			this.expTotal = entityhuman.expTotal;
			this.exp = entityhuman.exp;
			this.setScore(entityhuman.getScore());
		}
		
		this.f = entityhuman.f;
		this.enderChest = entityhuman.enderChest;
		this.getDataWatcher().watch(10, entityhuman.getDataWatcher().getByte(10));
	}
	
	protected boolean canTriggerWalking() {
		return !this.abilities.isFlying;
	}
	
	public void updateAbilities() {
	}
	
	public void a(WorldSettings.EnumGamemode worldsettings_enumgamemode) {
	}
	
	public String getName() {
		return this.bH.getName();
	}
	
	public InventoryEnderChest getEnderChest() {
		return this.enderChest;
	}
	
	public ItemStack getEquipment(int i) {
		return i == 0 ? this.inventory.getItemInHand() : this.inventory.armor[i - 1];
	}
	
	public ItemStack getHeldItem() {
		return this.inventory.getItemInHand();
	}
	
	public void setEquipment(int i, ItemStack item) {
		this.inventory.armor[i] = item;
	}
	
	public abstract boolean isSpectator();
	
	public ItemStack[] getInventory() {
		return this.inventory.armor;
	}
	
	public boolean isPushedByWater() {
		return !this.abilities.isFlying;
	}
	
	public Scoreboard getScoreboard() {
		return this.world.getScoreboard();
	}
	
	public ScoreboardTeamBase getScoreboardTeam() {
		return this.getScoreboard().getPlayerTeam(this.getName());
	}
	
	public IChatBaseComponent getScoreboardDisplayName() {
		// CraftBukkit - todo: fun
		ChatComponentText chatcomponenttext = new ChatComponentText(ScoreboardTeam.getPlayerDisplayName(this.getScoreboardTeam(), this.getName()));
		
		chatcomponenttext.getChatModifier().setChatClickable(new ChatClickable(ChatClickable.EnumClickAction.SUGGEST_COMMAND, "/msg " + this.getName() + " "));
		chatcomponenttext.getChatModifier().setChatHoverable(this.getHoverEvent());
		chatcomponenttext.getChatModifier().setInsertion(this.getName());
		return chatcomponenttext;
	}
	
	public float getHeadHeight() {
		float f = 1.62F;
		
		if (this.isSleeping()) {
			f = 0.2F;
		}
		
		if (this.isSneaking()) {
			f -= 0.08F;
		}
		
		return f;
	}
	
	public float getAbsorptionHearts() {
		return this.getDataWatcher().getFloat(17);
	}
	
	public void setAbsorptionHearts(float f) {
		if (f < 0.0F) {
			f = 0.0F;
		}
		
		this.getDataWatcher().watch(17, f);
	}
	
	public boolean a(ChestLock chestlock) {
		if (chestlock.a()) {
			return true;
		} else {
			ItemStack itemstack = this.bZ();
			
			return itemstack != null && itemstack.hasName() && itemstack.getName().equals(chestlock.b());
		}
	}
	
	public boolean getSendCommandFeedback() {
		return MinecraftServer.getServer().worldServer[0].getGameRules().getBoolean("sendCommandFeedback");
	}
	
	public boolean replaceItemInInventory(int i, ItemStack item) {
		if (i >= 0 && i < this.inventory.items.length) {
			this.inventory.setItem(i, item);
			return true;
		} else {
			int j = i - 100;
			int k;
			
			if (j >= 0 && j < this.inventory.armor.length) {
				k = j + 1;
				if (item != null && item.getItem() != null) {
					if (item.getItem() instanceof ItemArmor) {
						if (EntityInsentient.c(item) != k) {
							return false;
						}
					} else if (k != 4 || item.getItem() != Items.SKULL && !(item.getItem() instanceof ItemBlock)) {
						return false;
					}
				}
				
				this.inventory.setItem(j + this.inventory.items.length, item);
				return true;
			} else {
				k = i - 200;
				if (k >= 0 && k < this.enderChest.getSize()) {
					this.enderChest.setItem(k, item);
					return true;
				} else {
					return false;
				}
			}
		}
	}
	
	public enum EnumBedResult {
		OK,
		NOT_POSSIBLE_HERE,
		NOT_POSSIBLE_NOW,
		TOO_FAR_AWAY,
		OTHER_PROBLEM,
		NOT_SAFE;
		
		EnumBedResult() {
		}
	}
	
	public enum EnumChatVisibility {
		
		FULL(0, "options.chat.visibility.full"),
		SYSTEM(1, "options.chat.visibility.system"),
		HIDDEN(2, "options.chat.visibility.hidden");
		
		private static final EntityHuman.EnumChatVisibility[] d = new EntityHuman.EnumChatVisibility[values().length];
		
		static {
			EntityHuman.EnumChatVisibility[] aentityhuman_enumchatvisibility = values();
			int i = aentityhuman_enumchatvisibility.length;
			
			for (EnumChatVisibility entityhuman_enumchatvisibility : aentityhuman_enumchatvisibility) {
				EnumChatVisibility.d[entityhuman_enumchatvisibility.e] = entityhuman_enumchatvisibility;
			}
			
		}
		
		private final int e;
		private final String f;
		
		EnumChatVisibility(int i, String s) {
			this.e = i;
			this.f = s;
		}
		
		public static EntityHuman.EnumChatVisibility a(int i) {
			return EntityHuman.EnumChatVisibility.d[i % EntityHuman.EnumChatVisibility.d.length];
		}
		
		public int a() {
			return this.e;
		}
	}
	
	static class SyntheticClass_1 {
		
		static final int[] a = new int[EnumDirection.values().length];
		
		static {
			try {
				EntityHuman.SyntheticClass_1.a[EnumDirection.SOUTH.ordinal()] = 1;
			} catch (NoSuchFieldError ignored) {
			}
			
			try {
				EntityHuman.SyntheticClass_1.a[EnumDirection.NORTH.ordinal()] = 2;
			} catch (NoSuchFieldError ignored) {
			}
			
			try {
				EntityHuman.SyntheticClass_1.a[EnumDirection.WEST.ordinal()] = 3;
			} catch (NoSuchFieldError ignored) {
			}
			
			try {
				EntityHuman.SyntheticClass_1.a[EnumDirection.EAST.ordinal()] = 4;
			} catch (NoSuchFieldError ignored) {
			}
			
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy