1
0
Fork 0
tcr/common/src/main/java/common/entity/npc/EntityNPC.java
2025-09-07 11:51:01 +02:00

4609 lines
137 KiB
Java
Executable file

package common.entity.npc;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Predicate;
import common.ai.AIRangedAttack;
import common.ai.EntityAIAttackOnCollide;
import common.ai.EntityAIAvoidEntity;
import common.ai.EntityAIHurtByTarget;
import common.ai.EntityAILookAtTalkingPlayer;
import common.ai.EntityAINagPlayer;
import common.ai.EntityAINearestAttackableTarget;
import common.ai.EntityAINpcInteract;
import common.ai.EntityAINpcMate;
import common.ai.EntityAIOpenDoor;
import common.ai.EntityAIPlay;
import common.ai.EntityAISwimNavigate;
import common.ai.EntityAISwimming;
import common.ai.EntityAIWander;
import common.ai.EntityAIWatchClosest;
import common.ai.EntityAIWatchClosest2;
import common.block.Block;
import common.block.artificial.BlockBed;
import common.collect.Lists;
import common.collect.Maps;
import common.dimension.Dimension;
import common.dimension.Space;
import common.effect.Effect;
import common.effect.StatusEffect;
import common.enchantment.Enchantment;
import common.enchantment.EnchantmentHelper;
import common.entity.DamageSource;
import common.entity.Entity;
import common.entity.EntityType;
import common.entity.animal.EntityHorse;
import common.entity.animal.EntityPig;
import common.entity.item.EntityCart;
import common.entity.item.EntityItem;
import common.entity.projectile.EntityArrow;
import common.entity.projectile.EntityBullet;
import common.entity.projectile.EntityHook;
import common.entity.projectile.EntityPotion;
import common.entity.projectile.EntitySnowball;
import common.entity.types.EntityLiving;
import common.init.DimensionRegistry;
import common.init.ItemRegistry;
import common.init.Items;
import common.init.NameRegistry;
import common.init.SoundEvent;
import common.init.SpeciesRegistry;
import common.init.TradeRegistry;
import common.init.SpeciesRegistry.ModelType;
import common.inventory.Container;
import common.inventory.ContainerPlayer;
import common.inventory.IInventory;
import common.inventory.InventoryWarpChest;
import common.item.Item;
import common.item.ItemAction;
import common.item.ItemStack;
import common.item.consumable.ItemPotion;
import common.item.material.ItemArmor;
import common.item.tool.ItemKey;
import common.item.tool.ItemTool;
import common.item.weapon.ItemBow;
import common.item.weapon.ItemGunBase;
import common.network.IClientPlayer;
import common.network.IPlayer;
import common.packet.CPacketPlayerPosition;
import common.packet.CPacketPlayerLook;
import common.packet.CPacketPlayerPosLook;
import common.packet.CPacketAction;
import common.packet.CPacketBreak;
import common.packet.CPacketInput;
import common.packet.CPacketPlayer;
import common.packet.SPacketEntityEquipment;
import common.packet.SPacketEntityVelocity;
import common.pathfinding.PathNavigateGround;
import common.rng.Random;
import common.sound.MovingSoundMinecartRiding;
import common.tags.TagObject;
import common.util.LocalPos;
import common.util.BoundingBox;
import common.util.Clientside;
import common.util.ExtMath;
import common.util.Facing;
import common.util.Equipment;
import common.util.ParticleType;
import common.util.PortalType;
import common.util.Color;
import common.util.Vec3;
import common.util.GlobalPos;
import common.vars.Vars;
import common.village.MerchantRecipeList;
import common.world.World;
import common.world.AWorldServer;
public abstract class EntityNPC extends EntityLiving implements IInventory
{
private class AttributeInstance {
private final Map<Integer, Float> slots = Maps.<Integer, Float>newHashMap();
private boolean update = true;
private float value;
public void applyModifier(int slot, float amount) {
this.slots.put(slot, amount);
this.update = true;
}
public void removeModifier(int slot) {
if(this.slots.remove(slot) != null)
this.update = true;
}
public float getAttributeValue() {
if(this.update) {
this.value = 0.0f;
for(Float mod : this.slots.values()) {
this.value += mod;
}
this.update = false;
}
return this.value;
}
}
public static class CharacterTypeData
{
public final CharacterInfo character;
public CharacterTypeData(CharacterInfo character)
{
this.character = character;
}
}
public static class AlignmentData
{
public final Alignment alignment;
public AlignmentData(Alignment alignment)
{
this.alignment = alignment;
}
}
public static String getSkinTexture(String skin)
{
return "textures/npc/" + skin + ".png";
}
// public static String getSpeciesName(String character) {
// return (character.substring(0, 1).toUpperCase() + character.substring(1)).replace('_', ' ').replaceAll("( [a-z])", "$1");
// }
protected final EntityAIAttackOnCollide aiMelee = new EntityAIAttackOnCollide(this, EntityLiving.class, 1.0D, true, true) {
public boolean shouldExecute()
{
return !EntityNPC.this.fleeing && super.shouldExecute();
}
public boolean continueExecuting()
{
return !EntityNPC.this.fleeing && super.shouldExecute();
}
};
protected final AIRangedAttack aiRanged = new AIRangedAttack(this, 1.0D, this.getAttackSpeed(), this.getAttackSpeed() * 3, 15.0F) {
// public void startExecuting()
// {
// super.startExecuting();
// EntityNPC.this.setUsingItem(true);
// }
//
// public void resetTask()
// {
// super.resetTask();
// EntityNPC.this.setUsingItem(false);
// }
public boolean shouldExecute()
{
return !EntityNPC.this.fleeing && super.shouldExecute();
}
public boolean continueExecuting()
{
return !EntityNPC.this.fleeing && super.shouldExecute();
}
};
protected final SpeciesInfo species;
private final Map<Attribute, AttributeInstance> attributes = Maps.<Attribute, AttributeInstance>newHashMap();
private EntityNPC talkingPlayer;
private boolean isWilling;
private boolean fleeing;
private boolean playing;
protected boolean noPickup;
private ItemStack prevHeldItem;
private ItemStack mouseItem;
private final ItemStack[] armor = new ItemStack[Equipment.ARMOR_SLOTS];
private final ItemStack[] prevArmor = new ItemStack[this.armor.length];
private final ItemStack[] items = new ItemStack[Equipment.INVENTORY_SLOTS];
private final ItemStack[] prevItems = new ItemStack[this.items.length];
private int inLove;
protected Alignment alignment = Alignment.NEUTRAL;
private MerchantRecipeList trades;
private int healTimer;
private byte[] skin;
public IPlayer connection;
public IClientPlayer client;
protected boolean slave;
protected boolean dummy;
protected InventoryWarpChest warpChest;
public ContainerPlayer inventoryContainer;
public Container openContainer;
public boolean flying;
public boolean noclip;
protected int flyToggleTimer;
public float prevCameraYaw;
public float cameraYaw;
public int xpCooldown;
public double prevChasingPosX;
public double prevChasingPosY;
public double prevChasingPosZ;
public double chasingPosX;
public double chasingPosY;
public double chasingPosZ;
private GlobalPos originPos = new GlobalPos(0, 64, 0, Space.INSTANCE);
private GlobalPos spawnPos;
public int experienceLevel;
public int experienceTotal;
public float experience;
protected int enchSeed;
private ItemStack itemInUse;
private int itemInUseCount;
protected float speedInAir = 0.02F;
private int lastXPSound;
public EntityHook fishEntity;
protected int sinceLastAttack;
private int currentItem;
private boolean otherPlayerUsing;
private int otherPlayerMPPosRotationIncrements;
private double otherPlayerMPX;
private double otherPlayerMPY;
private double otherPlayerMPZ;
private double otherPlayerMPYaw;
private double otherPlayerMPPitch;
private double lastReportedPosX;
private double lastReportedPosY;
private double lastReportedPosZ;
private float lastReportedYaw;
private float lastReportedPitch;
private boolean serverSneakState;
private boolean serverSprintState;
private int positionUpdateTicks;
private boolean hasValidHealth;
protected int sprintToggleTimer;
public int sprintingTicksLeft;
public float renderArmYaw;
public float renderArmPitch;
public float prevRenderArmYaw;
public float prevRenderArmPitch;
private int horseJumpPowerCounter;
private float horseJumpPower;
private long movedDistance;
private int attackDamageBase = 2;
public EntityNPC(World worldIn)
{
super(worldIn);
for(Attribute attribute : Attribute.values()) {
this.attributes.put(attribute, new AttributeInstance());
}
this.species = SpeciesRegistry.CLASSES.get(this.getClass());
// this.setCharacter("");
if(this.species != null)
this.setSize(this.getSpeciesBaseSize() * this.species.renderer.width / this.species.renderer.height, this.getSpeciesBaseSize()); // /* 0.6F, */ 1.8F);
if(this.getNavigator() instanceof PathNavigateGround) {
((PathNavigateGround)this.getNavigator()).setBreakDoors(true);
((PathNavigateGround)this.getNavigator()).setAvoidsWater(this.canSwim());
}
if(this.canSwim())
this.tasks.addTask(0, new EntityAISwimming(this));
else
this.tasks.addTask(0, new EntityAISwimNavigate(this));
// this.tasks.addTask(1, new EntityAIAttackOnCollide(this, EntityNPC.class, 0.6D, true, true));
// this.tasks.addTask(1, new EntityAIAttackOnCollide(this, EntityLivingBase.class, 0.6D, true, true));
this.tasks.addTask(1, new EntityAINpcMate(this));
this.tasks.addTask(2, new EntityAIAvoidEntity(this, EntityLiving.class, new Predicate<EntityLiving>() {
public boolean test(EntityLiving entity) {
return entity != EntityNPC.this && EntityNPC.this.shouldFlee(entity);
}
}, 8.0F, 1.1D, 1.1D) {
{
this.setMutexBits(0);
}
public void startExecuting() {
EntityNPC.this.setAttackTarget(null);
EntityNPC.this.fleeing = true;
}
public boolean continueExecuting() {
return false;
}
public void updateTask()
{
}
// public void resetTask() {
// super.resetTask();
// EntityNPC.this.isFleeing = false;
// }
});
this.tasks.addTask(3, new EntityAIAvoidEntity(this, EntityLiving.class, new Predicate<EntityLiving>() {
public boolean test(EntityLiving entity) {
return entity != EntityNPC.this && EntityNPC.this.shouldFlee(entity);
}
}, 8.0F, 1.1D, 1.1D) {
public void startExecuting() {
super.startExecuting();
EntityNPC.this.setAttackTarget(null);
EntityNPC.this.fleeing = true;
}
public void resetTask() {
super.resetTask();
EntityNPC.this.fleeing = false;
}
});
// this.tasks.addTask(2, new EntityAITempt(this, 1.0D, Items.golden_apple, false));
this.tasks.addTask(4, new EntityAIOpenDoor(this, true));
this.tasks.addTask(5, new EntityAINagPlayer(this));
this.tasks.addTask(5, new EntityAILookAtTalkingPlayer(this));
this.tasks.addTask(6, new EntityAIWatchClosest2(this, null, 3.0F, 1.0F) {
private int sneakTime;
public void updateTask()
{
super.updateTask();
boolean flag = this.closestEntity.isPlayer() && this.closestEntity.isSneaking();
if(this.sneakTime > 0) {
if(--this.sneakTime == 0) {
EntityNPC.this.setSneaking(false);
}
}
else if(EntityNPC.this.getAttackTarget() == null && EntityNPC.this.rand.chance(flag ? 5 : 200)) {
EntityNPC.this.setSneaking(true);
this.sneakTime = EntityNPC.this.rand.range(60, flag ? 160 : 120);
}
else if(EntityNPC.this.getAttackTarget() != null) {
EntityNPC.this.setSneaking(false);
this.sneakTime = 0;
}
}
public void resetTask()
{
super.resetTask();
EntityNPC.this.setSneaking(false);
}
});
this.tasks.addTask(7, new EntityAINpcInteract(this));
this.tasks.addTask(8, new EntityAIWander(this, 1.0D));
this.tasks.addTask(8, new EntityAIPlay(this, 1.1D));
this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityLiving.class, 8.0F));
this.targets.addTask(1, new EntityAIHurtByTarget(this, false) {
protected boolean isSuitableTarget(EntityLiving entity) {
if(entity != null && entity != EntityNPC.this && EntityNPC.this.shouldFlee(entity)) {
EntityNPC.this.setAttackTarget(null);
EntityNPC.this.fleeing = true;
return false;
}
return entity != null && entity != EntityNPC.this && (!(entity.isPlayer()) || EntityNPC.this.rand.chance(entity.getAttackedBy() == EntityNPC.this ? 2 : 4))
&& EntityNPC.this.canCounter(entity) && super.isSuitableTarget(entity);
}
});
this.targets.addTask(2, new EntityAINearestAttackableTarget(this, EntityLiving.class, 10, true, false, new Predicate<EntityLiving>() {
public boolean test(EntityLiving entity) {
if(entity != null && entity != EntityNPC.this && EntityNPC.this.shouldFlee(entity)) {
EntityNPC.this.setAttackTarget(null);
EntityNPC.this.fleeing = true;
return false;
}
return entity != null && entity != EntityNPC.this && !EntityNPC.this.fleeing && EntityNPC.this.canAmbush(entity) && EntityNPC.this.canAttack(entity);
}
}));
// this.setCanPickUpLoot(true);
if (worldIn != null && !worldIn.client)
{
this.setCombatTask();
}
}
private void initPlayer() {
this.warpChest = new InventoryWarpChest();
// this.setHeight(1.8f);
this.inventoryContainer = new ContainerPlayer(this);
this.openContainer = this.inventoryContainer;
this.setLocationAndAngles(0.5D, 1.0D, 0.5D, 0.0F, 0.0F);
this.fireResistance = 20;
this.noPickup = true;
// this.getEntityAttribute(Attributes.ATTACK_DAMAGE).setBaseValue(1.0D);
// this.getEntityAttribute(Attribute.MOVEMENT_SPEED).setBaseValue(this.getEntityAttribute(Attribute.MOVEMENT_SPEED).getBaseValue() / 3.0); // 0.10000000149011612D);
}
public final void setServerPlayer(IPlayer connection) {
this.initPlayer();
this.connection = connection;
this.stepHeight = 0.0F;
}
public final void setClientPlayer(IClientPlayer connection) {
this.initPlayer();
this.slave = true;
this.client = connection;
}
public final void setOtherPlayer() {
this.initPlayer();
this.slave = true;
this.stepHeight = 0.0F;
this.noClip = true;
this.renderDistWeight = 10.0D;
}
public final void setPlayerDummy(TagObject tag) {
this.dummy = true;
this.readTags(tag);
}
public final boolean isPlayer() {
return this.connection != null || this.slave;
}
public final boolean canInfight(Alignment align) {
return this.alignment.chaotic || (!this.alignment.lawful &&
((this.alignment.good && align.evil) || (this.alignment.evil && align.good)));
}
public final boolean canMurder(Alignment align) {
return this.alignment.chaotic && ((this.alignment.good && align.evil) || (this.alignment.evil && align.good));
}
public boolean canCounter(EntityLiving entity) {
return !(entity instanceof EntityNPC) ||
(this.getClass() == entity.getClass() ? this.canInfight(((EntityNPC)entity).alignment) :
!this.isPeaceful(((EntityNPC)entity).getClass()));
}
public boolean canAttack(EntityLiving entity) {
return entity instanceof EntityNPC && (this.getClass() == entity.getClass() ? this.canMurder(((EntityNPC)entity).alignment) :
this.isAggressive(((EntityNPC)entity).getClass()));
}
public boolean canAmbush(EntityLiving entity) {
return true;
}
public boolean shouldFlee(EntityLiving entity) {
return (this.getHealth() <= (this.getMaxHealth() / 4) || !this.canCounter(entity)) &&
((entity instanceof EntityNPC && ((((EntityNPC)entity).canAttack(this)) ||
(entity == this.getAttackedBy() && ((EntityNPC)entity).canCounter(this)))));
}
// public void setCombatTask()
// {
// }
public boolean isRangedWeapon(ItemStack stack) {
return stack != null && (stack.getItem() == Items.bow || stack.getItem() instanceof ItemGunBase ||
stack.getItem() == Items.snowball || (stack.getItem() instanceof ItemPotion potion));
}
// public boolean isSneaking()
// {
// return true;
// }
protected int getAttackSpeed() {
return 20;
}
public boolean canSwim() {
return true;
}
public float getVisionBrightness() {
return 0.1f;
}
// public void setScaleForAge()
// {
// }
// public float getRenderScale()
// {
// return ;
// }
public boolean isAttacking()
{
return this.getFlag(3);
}
public void setAttacking(boolean atk)
{
this.setFlag(3, atk);
}
// public boolean isUsingItem()
// {
// return ;
// }
public void setUsingItem(boolean use)
{
this.setFlag(4, use);
}
public boolean isMating()
{
return this.getFlag(5);
}
public void setMating(boolean mating)
{
this.setFlag(5, mating);
}
public boolean hasArmsRaised()
{
return false;
}
public boolean hasPowerRods() {
return false;
}
public boolean hasDualWings() {
return false;
}
public boolean hasSlimArms() {
return false;
}
public String getCape() {
return null;
}
public boolean isCharged()
{
return false;
}
// protected boolean getNpcFlag(int flag)
// {
// return (this.dataWatcher.getWatchableObjectByte(20) & 1 << flag) != 0;
// }
//
// protected void setNpcFlag(int flag, boolean set)
// {
// byte b0 = this.dataWatcher.getWatchableObjectByte(20);
//
// if (set)
// {
// this.dataWatcher.updateObject(20, Byte.valueOf((byte)(b0 | 1 << flag)));
// }
// else
// {
// this.dataWatcher.updateObject(20, Byte.valueOf((byte)(b0 & ~(1 << flag))));
// }
// }
protected void applyEntityAttributes()
{
super.applyEntityAttributes();
this.setSpeedBase(0.3f);
this.setMaxHealth(this.getBaseHealth(this.rand));
if(this.canUseMagic())
this.setMaxMana(20);
}
public int getPathingRange() {
return 20;
}
public boolean isPotionApplicable(Effect potion, int amplifier) {
return true;
}
// protected int getExperiencePoints(EntityNPC player)
// {
// return ;
// }
// protected boolean canDropLoot()
// {
// return true;
// }
// protected float getSoundPitch()
// {
// return (this.rand.floatv() - this.rand.floatv()) * 0.2F + 1.0F;
// }
protected void updateAITasks()
{
if (this.getGrowingAge() != 0)
{
this.setMating(false);
}
super.updateAITasks();
}
private void onNpcUpdate()
{
super.onLivingUpdate();
if(!this.worldObj.client && /* this.canPickUpLoot() && */ !this.noPickup && Vars.mobGrief) {
for(EntityItem entityitem : this.worldObj.getEntitiesWithinAABB(EntityItem.class, this.getEntityBoundingBox().expand(1.0D, 0.0D, 1.0D))) {
if(!entityitem.dead && entityitem.getEntityItem() != null && !entityitem.cannotPickup()) {
this.updateEquipmentIfNeeded(entityitem);
}
}
}
if (this.getGrowingAge() != 0)
{
this.setMating(false);
}
if(this.worldObj.client) {
if (this.isMating())
{
++this.inLove;
if (this.inLove == 10)
{
this.inLove = 0;
this.worldObj.clientParticle(ParticleType.HEART, this.posX + (double)(this.rand.floatv() * this.width * 2.0F) - (double)this.width, this.posY + 0.5D + (double)(this.rand.floatv() * this.height), this.posZ + (double)(this.rand.floatv() * this.width * 2.0F) - (double)this.width);
}
}
else {
this.inLove = 0;
}
}
}
public boolean interact(EntityNPC player)
{
ItemStack stack = player.getHeldItem();
boolean flag = stack != null && !(stack.getItem() instanceof ItemTool);
if (stack != null && !this.isPlayer() && this.isBreedingItem(stack) && this.getGrowingAge() == 0 && !this.isMating())
{
if(stack.decrSize())
player.clearHeldItem();
if (!this.worldObj.client)
{
this.setIsWillingToMate(true);
this.setMating(true);
this.worldObj.setEntityState(this, (byte)12);
}
return true;
}
else if (stack != null && !this.isPlayer() && this.isBreedingItem(stack) && this.getGrowingAge() < 0)
{
if(stack.decrSize())
player.clearHeldItem();
if (!this.worldObj.client)
{
this.grow(this.rand.range(200, 250));
}
// else if (this.particleTimer == 0) {
// this.particleTimer = 40;
// }
return true;
}
else if (!flag && !this.isPlayer() && this.isEntityAlive() && !this.isTalking())
{
if (!this.worldObj.client && this.canTrade() && this.getAttackTarget() == null)
{
this.setTalking(player);
player.connection.show(this);
}
// player.triggerAchievement(StatRegistry.timesTalkedToNpcStat);
return true;
}
else
{
return super.interact(player);
}
}
// public boolean attackEntityFrom(DamageSource source, int amount)
// {
// }
public boolean attackEntityAsMob(Entity entityIn)
{
if(!this.worldObj.client && !Vars.damageMobs)
return false;
int i = 0;
if (entityIn instanceof EntityLiving)
{
i += EnchantmentHelper.getKnockbackModifier(this);
}
boolean flag = entityIn.attackEntityFrom(DamageSource.causeMobDamage(this), this.getAttackDamage());
if (flag)
{
if (i > 0)
{
entityIn.addKnockback((double)(-ExtMath.sin(this.rotYaw * (float)Math.PI / 180.0F) * (float)i * 0.5F), 0.1D, (double)(ExtMath.cos(this.rotYaw * (float)Math.PI / 180.0F) * (float)i * 0.5F));
this.motionX *= 0.6D;
this.motionZ *= 0.6D;
}
int j = EnchantmentHelper.getFireAspectModifier(this);
if (j > 0)
{
entityIn.setFire(j * 4);
}
this.applyEnchantments(this, entityIn);
}
return flag;
}
public void attackEntityWithRangedAttack(EntityLiving target, float range)
{
ItemStack stack = this.getHeldItem();
if(stack == null)
return;
if(stack.getItem() == Items.bow) {
EntityArrow entityarrow = new EntityArrow(this.worldObj, this, target, 1.6F, 2.0f);
int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.POWER, this.getHeldItem());
int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.PUNCH, this.getHeldItem());
entityarrow.setDamage((double)(range * 2.0F) + this.rand.gaussian() * 0.25D + (double)(/* (float)this.worldObj.getDifficulty().getId() */ 3.0f * 0.11F));
if (i > 0)
{
entityarrow.setDamage(entityarrow.getDamage() + (double)i * 0.5D + 0.5D);
}
if (j > 0)
{
entityarrow.setKnockbackStrength(j);
}
if (EnchantmentHelper.getEnchantmentLevel(Enchantment.FLAME, this.getHeldItem()) > 0)
{
entityarrow.setFire(100);
}
this.playSound(SoundEvent.THROW, 1.0F);
this.worldObj.spawnEntityInWorld(entityarrow);
}
else if(stack.getItem() instanceof ItemGunBase gun) {
EntityBullet bullet = gun.createBulletFor(this.worldObj, this, target);
int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.POWER, this.getHeldItem());
bullet.setDamage(((ItemGunBase)stack.getItem()).getAmmo().getDamage(stack));
if (i > 0)
{
bullet.setDamage(bullet.getDamage() + i);
}
this.playSound(gun.getLaunchSound(), 1.0f);
this.worldObj.spawnEntityInWorld(bullet);
}
else if(stack.getItem() == Items.snowball) {
EntitySnowball entitysnowball = new EntitySnowball(this.worldObj, this);
double d0 = target.posY + (double)target.getEyeHeight() - 1.100000023841858D;
double d1 = target.posX - this.posX;
double d2 = d0 - entitysnowball.posY;
double d3 = target.posZ - this.posZ;
float f = ExtMath.sqrtd(d1 * d1 + d3 * d3) * 0.2F;
entitysnowball.setThrowableHeading(d1, d2 + (double)f, d3, 1.6F, 12.0F);
this.playSound(SoundEvent.THROW, 1.0F);
this.worldObj.spawnEntityInWorld(entitysnowball);
}
else if(stack.getItem() instanceof ItemPotion potion) {
EntityPotion entitypotion = new EntityPotion(this.worldObj, this, potion);
double d0 = target.posY + (double)target.getEyeHeight() - 1.100000023841858D;
entitypotion.rotPitch -= -20.0F;
double d1 = target.posX + target.motionX - this.posX;
double d2 = d0 - this.posY;
double d3 = target.posZ + target.motionZ - this.posZ;
float f = ExtMath.sqrtd(d1 * d1 + d3 * d3);
entitypotion.setThrowableHeading(d1, d2 + (double)(f * 0.2F), d3, 1.5F, 0.5F);
this.worldObj.spawnEntityInWorld(entitypotion);
}
}
public void setChar(String character)
{
this.dataWatcher.updateObject(9, character);
}
public String getChar()
{
return this.dataWatcher.getWatchableObjectString(9);
}
public void setNpcClass(Enum type)
{
this.dataWatcher.updateObject(10, (byte)(type == null ? -1 : type.ordinal()));
}
public Enum getNpcClass()
{
byte n = this.dataWatcher.getWatchableObjectByte(10);
return n < 0 || this.species == null || this.species.classEnum == null ? null :
this.species.classEnum.getEnumConstants()[n % this.species.classEnum.getEnumConstants().length];
}
public void setAlignment(Alignment align)
{
this.alignment = align;
this.dataWatcher.updateObject(8, (byte)align.ordinal());
}
public Alignment getAlignment()
{
return Alignment.values()[this.dataWatcher.getWatchableObjectByte(8) % Alignment.values().length];
}
public void setHeight(float height)
{
this.dataWatcher.updateObject(11, ExtMath.clampf(height, 0.2f, 10.0f));
}
public float getHeight()
{
return this.dataWatcher.getWatchableObjectFloat(11);
}
public SpeciesInfo getSpecies() {
return this.species;
}
public void setAttackedBy(EntityLiving livingBase)
{
if(livingBase != null && /* livingBase.isPlayer() && */ this.isEntityAlive() && /* !this.isPeaceful() && */ this.getAttackedBy() != livingBase &&
Vars.mobAttacks && !this.isPlayer()) {
this.worldObj.setEntityState(this, (byte)13);
}
super.setAttackedBy(livingBase);
}
// public void onDeath(DamageSource cause)
// {
//
// super.onDeath(cause);
// }
// protected void dropEquipment()
// {
// }
public void setTalking(EntityNPC player)
{
this.talkingPlayer = player;
}
public EntityNPC getTalking()
{
return this.talkingPlayer;
}
public boolean isTalking()
{
return this.talkingPlayer != null;
}
public boolean canMate()
{
return false;
}
public boolean getIsWillingToMate(boolean update)
{
if (!this.isWilling && update && this.canMate())
{
this.isWilling = true;
}
return this.isWilling;
}
public void setIsWillingToMate(boolean willing)
{
this.isWilling = willing;
if(!this.isWilling) {
this.setMating(false);
}
}
public String getPrefix() {
Enum cls = this.species.prefix ? this.getNpcClass() : null;
return cls == null ? null : cls.toString();
}
// public String getName()
// {
// }
// public String formatStats() {
// return super.formatStats();
// }
// public float getEyeHeight()
// {
//// float f = 1.62F;
////
//// if (this.isChild())
//// {
//// f = (float)((double)f - 0.81D);
//// }
//
// }
// public void handleStatusUpdate(byte id)
// {
// }
// public Object onInitialSpawn(Object livingdata)
// {
// }
public boolean isPropogatingSpawnData(boolean newGroup) {
return true;
}
protected ItemStack pickItem() {
return null;
}
protected ItemStack pickArmor(Equipment slot) {
return null;
}
protected ItemStack pickLoot(int slot) {
return null;
}
protected int pickItemAmount() {
return this.rand.zrange(4);
}
// public EntityNPC createChild(EntityLiving ageable)
// {
// }
// public void onStruckByLightning(EntityLightning lightningBolt)
// {
// if (!this.worldObj.client && !this.isDead)
// {
//
// }
//
// super.onStruckByLightning(lightningBolt);
// }
// protected void updateEquipmentIfNeeded(EntityItem itemEntity)
// {
// super.updateEquipmentIfNeeded(itemEntity);
// if(!itemEntity.dead) {
// ItemStack stack = itemEntity.getEntityItem();
// Item item = stack.getItem();
//
// if (this.canPickUpExtraItem(item))
// {
// ItemStack remain = this.extraInventory.addStack(stack);
//
// if (remain == null)
// {
// itemEntity.setDead();
// }
// else
// {
// stack.stackSize = remain.stackSize;
// }
// }
// }
// }
private boolean canPickUpExtraItem(Item itemIn)
{
return itemIn == Items.golden_apple || itemIn == Items.sugar;
}
// public LayerExtra getExtrasLayer()
// {
// return ;
// }
// public String getLocationSkin()
// {
// return ;
// }
// protected boolean hasSlimSkin()
// {
// return this.getChar().startsWith("~");
// }
// public boolean canRenderExtras()
// {
// return true;
// }
// public boolean isWearing(ModelPart part)
// {
// return ;
// }
public int getLeashColor() {
return 0x202020;
}
public int getManaPoints() {
return this.dataWatcher.getWatchableObjectInt(14);
}
public void setManaPoints(int pts) {
this.dataWatcher.updateObject(14, pts);
}
// public final boolean isAggressive() {
// return this.alignment.evil;
// }
//
// public final boolean isPeaceful() {
// return this.alignment.good;
// }
public boolean isAggressive(Class<? extends EntityNPC> clazz) {
return false;
}
public boolean isPeaceful(Class<? extends EntityNPC> clazz) {
return false;
}
public boolean canUseMagic() {
return false;
}
// public abstract int getBaseHealth(Random rand);
// public final int getBaseEnergy(Random rand) {
// return 0;
// }
public final float getHeightDeviation(Random rand) {
return this.getHeightDeviationMin() == this.getHeightDeviationMax() ? this.getHeightDeviationMin() : this.rand.frange(this.getHeightDeviationMin(), this.getHeightDeviationMax());
}
public float getHeightDeviationMin() {
return 0.0f;
}
public float getHeightDeviationMax() {
return 0.0f;
}
public abstract float getSpeciesBaseSize();
public float getEntityBaseSize() {
return this.getSpeciesBaseSize();
}
public boolean isVisibleTo(EntityNPC player)
{
return this.connection == null || !this.connection.isInEditor();
}
// public abstract Alignment getNaturalAlign();
// public float getBaseSize(Random rand) {
// return ;
// }
public boolean isBreedingItem(ItemStack stack)
{
return false;
}
public boolean canTrade()
{
return false;
}
public NameRegistry getNameType()
{
return NameRegistry.FANTASY;
}
public String pickRandomName()
{
return this.getNameType().generate(this.rand, this.rand.chance(40) ? (this.rand.chance(15) ? 5 : 4) : (this.rand.chance() ? 3 : 2));
}
// public int getColor() {
// return ;
// }
public void setPlaying(boolean playing) {
this.playing = playing;
}
public boolean isPlaying() {
return this.playing;
}
public boolean isFleeing() {
return this.fleeing;
}
// public boolean canPlay() {
// return ;
// }
// public boolean isChild() {
// return false;
// }
// protected int decreaseAirSupply(int air) {
// return air;
// }
public final int getMaxMana() {
return this.dataWatcher.getWatchableObjectInt(13);
}
public final void setMaxMana(int mana) {
this.dataWatcher.updateObject(13, mana);
}
public void healMana(int amount) {
if(this.client == null)
this.setManaPoints(ExtMath.clampi(this.getManaPoints() + amount, 0, this.getMaxMana()));
}
public String formatStats() {
return super.formatStats() + (this.getManaPoints() == 0 ? "" : Color.GRAY + " [" + Color.MIDNIGHT + this.getManaPoints() + Color.GRAY + "]");
}
public String getInfo(EntityNPC player) {
return super.getInfo(player) + (this.getManaPoints() == 0 ? "" : Color.DARK_GRAY + " | " + Color.BLUE + this.getManaPoints() + Color.MIDNIGHT + " Mana");
}
public MerchantRecipeList getTrades(EntityNPC player) {
if(this.trades == null) {
this.trades = new MerchantRecipeList();
int n = this.rand.range(5, 25);
for(int z = 0; z < n; z++) {
this.rand.pick(TradeRegistry.TRADES).modifyMerchantRecipeList(this.trades, this.rand);
}
}
return this.trades;
}
// public boolean isNotColliding() {
// return this.canSpawnInLiquid() ?
// (this.worldObj.checkNoEntityCollision(this.getEntityBoundingBox(), this) &&
// this.worldObj.getCollidingBoundingBoxes(this, this.getEntityBoundingBox()).isEmpty()
// /* && !this.worldObj.isAnyLiquid(this.getEntityBoundingBox()) */) : super.isNotColliding();
// }
protected int applyPotionDamageCalculations(DamageSource source, int damage) {
damage = super.applyPotionDamageCalculations(source, damage);
if(damage > 0) {
int k = EnchantmentHelper.getEnchantmentModifierDamage(this.getArmor(), source);
if (k > 20)
{
k = 20;
}
if (k > 0 && k <= 20)
{
int l = 25 - k;
float f1 = (float)damage * (float)l;
damage = (int)(f1 / 25.0F);
}
}
if(this.canUseMagic() && source.isMagicDamage())
damage = source.getEntity() == this ? 0 : (int)((double)damage * 0.15D);
return damage;
}
protected boolean teleportRandomly() {
double x = this.posX + (this.rand.doublev() - 0.5D) * 64.0D;
double y = this.posY + (double)(this.rand.excl(-32, 32));
double z = this.posZ + (this.rand.doublev() - 0.5D) * 64.0D;
return this.teleportTo(x, y, z);
}
protected boolean teleportToEntity(Entity entity) {
Vec3 vec3 = new Vec3(this.posX - entity.posX,
this.getEntityBoundingBox().minY + (double)(this.height / 2.0F) - entity.posY + (double)entity.getEyeHeight(),
this.posZ - entity.posZ);
vec3 = vec3.normalize();
double dist = 16.0D;
double x = this.posX + (this.rand.doublev() - 0.5D) * 8.0D - vec3.x * dist;
double y = this.posY + (double)(this.rand.excl(-8, 8)) - vec3.y * dist;
double z = this.posZ + (this.rand.doublev() - 0.5D) * 8.0D - vec3.z * dist;
return this.teleportTo(x, y, z);
}
protected boolean teleportTo(double x, double y, double z) {
double ox = this.posX;
double oy = this.posY;
double oz = this.posZ;
this.posX = x;
this.posY = y;
this.posZ = z;
boolean done = false;
LocalPos pos = new LocalPos(this.posX, this.posY, this.posZ);
if(this.worldObj.isBlockLoaded(pos)) {
boolean ground = false;
while(!ground && pos.getY() > 0) {
LocalPos down = pos.down();
Block block = this.worldObj.getState(down).getBlock();
if(block.getMaterial().blocksMovement()) {
ground = true;
}
else {
--this.posY;
pos = down;
}
}
if(ground) {
super.setPositionAndUpdate(this.posX, this.posY, this.posZ);
if(this.worldObj.getCollidingBoundingBoxes(this, this.getEntityBoundingBox()).isEmpty()
&& !this.worldObj.isAnyLiquid(this.getEntityBoundingBox())) {
done = true;
}
}
}
if(!done) {
this.setPosition(ox, oy, oz);
return false;
}
else {
this.worldObj.playEffect(1013, new LocalPos(ox, oy, oz), 0);
for(int n = 0; n < 8; n++) {
((AWorldServer)this.worldObj).spawnParticles(ParticleType.TELEPORT,
ox + (this.rand.doublev() - 0.5D) * (double)this.width * 2.0D,
oy + this.rand.doublev() * (double)this.height,
oz + (this.rand.doublev() - 0.5D) * (double)this.width * 2.0D);
}
this.worldObj.playEffect(1005, this.getPosition(), 0);
for(int n = 0; n < 8; n++) {
((AWorldServer)this.worldObj).spawnParticles(ParticleType.TELEPORT,
this.posX + (this.rand.doublev() - 0.5D) * (double)this.width * 2.0D,
this.posY + this.rand.doublev() * (double)this.height,
this.posZ + (this.rand.doublev() - 0.5D) * (double)this.width * 2.0D);
}
return true;
}
}
protected void updateEquipmentIfNeeded(EntityItem itemEntity) {
ItemStack stack = itemEntity.getEntityItem();
if(stack.getItem().getRadiation(stack) > 0.0f)
return;
Equipment[] slots = stack.getItem() instanceof ItemArmor armor ? armor.getArmorType().getPossibleSlots(this) : new Equipment[] {null};
for(Equipment slot : slots) {
boolean accept = true;
ItemStack old = slot == null ? this.getHeldItem() : this.getArmor(slot);
if(old != null) {
if(slot == null) {
if(stack.getItem() instanceof ItemTool t1 && t1.getToolType().isWeapon() && !(old.getItem() instanceof ItemTool t2 && t2.getToolType().isWeapon())) {
accept = true;
}
else if(stack.getItem() instanceof ItemTool itemsword && itemsword.getToolType().isWeapon() && old.getItem() instanceof ItemTool itemsword1 && itemsword1.getToolType().isWeapon()) {
if(itemsword.getAttackDamageBonus(stack) != itemsword1.getAttackDamageBonus(old)) {
accept = itemsword.getAttackDamageBonus(stack) > itemsword1.getAttackDamageBonus(old);
}
else {
accept = stack.getItemDamage() > old.getItemDamage() || stack.isItemEnchanted() && !old.isItemEnchanted();
}
}
else if(stack.getItem() instanceof ItemBow && old.getItem() instanceof ItemBow) {
accept = stack.isItemEnchanted() && !old.isItemEnchanted();
}
else if(stack.getItem() instanceof ItemGunBase && !(old.getItem() instanceof ItemBow)) {
accept = true;
}
else if(stack.getItem() instanceof ItemBow && !(old.getItem() instanceof ItemBow) && !(old.getItem() instanceof ItemTool tool && tool.getToolType().isWeapon())) {
accept = true;
}
else {
accept = false;
}
}
else if(stack.getItem() instanceof ItemArmor && !(old.getItem() instanceof ItemArmor)) {
accept = true;
}
else if(stack.getItem() instanceof ItemArmor && old.getItem() instanceof ItemArmor) {
ItemArmor itemarmor = (ItemArmor)stack.getItem();
ItemArmor itemarmor1 = (ItemArmor)old.getItem();
if(itemarmor.getArmorValue() != itemarmor1.getArmorValue()) {
accept = itemarmor.getArmorValue() > itemarmor1.getArmorValue();
}
else {
accept = stack.getItemDamage() > old.getItemDamage() || stack.isItemEnchanted() && !old.isItemEnchanted();
}
}
else {
accept = false;
}
}
if(accept) {
if(old != null)
this.entityDropItem(old, 0.0F);
if(slot == null)
this.setHeldItem(stack);
else
this.setArmor(slot, stack);
this.onItemPickup(itemEntity, 1);
itemEntity.setDead();
break;
}
}
if(!itemEntity.dead) {
stack = itemEntity.getEntityItem();
Item item = stack.getItem();
if (this.canPickUpExtraItem(item))
{
ItemStack remain = this.addStack(stack);
if (remain == null)
{
itemEntity.setDead();
}
else
{
stack.setSize(remain.getSize());
}
}
}
}
public boolean useMana(int pts) {
int mana = this.getManaPoints();
if(mana >= pts)
this.setManaPoints(mana - pts);
return mana >= pts;
}
public float getAttribute(Attribute attribute) {
return this.attributes.get(attribute).getAttributeValue();
}
private void removeModifiers(Map<Attribute, Float> modifiers, int slot) {
for(Entry<Attribute, Float> entry : modifiers.entrySet()) {
this.attributes.get(entry.getKey()).removeModifier(slot);
}
}
private void addModifiers(Map<Attribute, Float> modifiers, int slot, int amount) {
for(Entry<Attribute, Float> entry : modifiers.entrySet()) {
this.attributes.get(entry.getKey()).applyModifier(slot, entry.getValue() * (float)amount);
}
}
private void updateNpc()
{
if(!this.worldObj.client) {
ItemStack prevHeld = this.prevHeldItem;
ItemStack held = this.getHeldItem();
if (!ItemStack.allEquals(held, prevHeld))
{
((AWorldServer)this.worldObj).sendToAllTrackingEntity(this, new SPacketEntityEquipment(this.getId(), 0, held));
if(!this.isPlayer()) {
if (!ItemStack.allEquals(held, prevHeld))
{
if (prevHeld != null)
{
this.removeModifiers(prevHeld.getAttributeModifiers(), 0);
}
if (held != null)
{
this.addModifiers(held.getAttributeModifiers(), 0, held.getSize());
}
}
}
this.prevHeldItem = held == null ? null : held.copy();
}
for (int index = 0; index < Equipment.INVENTORY_SLOTS; index++)
{
ItemStack last = this.prevItems[index];
ItemStack current = this.getStackInSlot(index);
if (!ItemStack.allEquals(current, last))
{
if (last != null)
{
this.removeModifiers(last.getAttributeModifiers(), index + 1);
}
if (current != null)
{
this.addModifiers(current.getAttributeModifiers(), index + 1, current.getSize());
}
this.prevItems[index] = current == null ? null : current.copy();
}
}
for (Equipment slot : Equipment.ARMOR)
{
ItemStack last = this.prevArmor[slot.getIndex()];
ItemStack current = this.getArmor(slot);
if (!ItemStack.allEquals(current, last))
{
((AWorldServer)this.worldObj).sendToAllTrackingEntity(this, new SPacketEntityEquipment(this.getId(), slot.getIndex() + 1, current));
if (last != null)
{
this.removeModifiers(last.getArmorModifiers(this, slot), -1 - slot.getIndex());
}
if (current != null)
{
this.addModifiers(current.getArmorModifiers(this, slot), -1 - slot.getIndex(), current.getSize());
}
this.prevArmor[slot.getIndex()] = current == null ? null : current.copy();
}
}
}
super.onUpdate();
if(!this.worldObj.client && Vars.regeneration && this.shouldHeal()) {
++this.healTimer;
if(this.healTimer >= 80) {
this.heal(1);
this.healTimer = 0;
}
}
}
protected boolean shouldHeal() {
return this.canRegenerateHealth() && Vars.healChance > 0 && this.getHealth() > 0 && this.getHealth() < this.getMaxHealth()
&& this.rand.chance(Vars.healChance);
}
public byte[] getSkin() {
return this.skin;
}
public void setSkin(byte[] skin) {
this.skin = skin;
}
// START SP
public boolean attackEntityFrom(DamageSource source, int amount)
{
if(this.slave)
return this.client == null;
// if(this.isEntityInvulnerable(source))
// return false;
if(this.connection != null) {
if(this.getHealth() <= 0)
return false;
// Entity entity = source.getEntity();
// if(entity instanceof EntityArrow && ((EntityArrow)entity).shootingEntity != null)
// entity = ((EntityArrow)entity).shootingEntity;
// return super.attackEntityFrom(source, amount);
}
else {
this.setIsWillingToMate(false);
this.setMating(false);
}
return super.attackEntityFrom(source, amount);
}
/**
* Heal living entity (param: amount of half-hearts)
*/
public void heal(int healAmount)
{
if(this.client == null)
super.heal(healAmount);
}
/**
* Called when a player mounts an entity. e.g. mounts a pig, mounts a boat.
*/
public void mountEntity(Entity entityIn)
{
Entity entity = this.vehicle;
super.mountEntity(entityIn);
if(this.connection != null && entityIn != entity)
this.connection.mountEntity(entityIn);
// super.mountEntity(entityIn);
if (this.client != null && entityIn instanceof EntityCart)
{
this.client.playSound(new MovingSoundMinecartRiding(this, (EntityCart)entityIn));
}
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
if(this.client != null) {
if (this.worldObj.isBlockLoaded(new LocalPos(this.posX, 0.0D, this.posZ)))
{
// super.onUpdate();
this.updatePlayer();
if(this.client.isRenderViewEntity(this)) {
if (this.isRiding())
{
this.client.addToSendQueue(new CPacketPlayerLook(this.rotYaw, this.rotPitch, this.onGround));
this.client.addToSendQueue(new CPacketInput(this.moveStrafe, this.moveForward, this.client.isJumping(), this.client.isSneaking(), false));
}
else
{
this.syncMovement();
}
}
else if (this.vehicle == null)
{
this.client.addToSendQueue(new CPacketPlayer(this.onGround));
}
else
{
this.client.addToSendQueue(new CPacketPlayerPosLook(this.motionX, -99999999.0D, this.motionZ, this.rotYaw, this.rotPitch, this.onGround));
}
}
return;
}
if(this.connection != null) {
this.connection.updateEntity();
return;
}
if(this.slave) {
// this.renderOffsetY = 0.0F;
// super.onUpdate();
this.updatePlayer();
this.prevLswingAmount = this.lswingAmount;
double d0 = this.posX - this.prevX;
double d1 = this.posZ - this.prevZ;
float f = ExtMath.sqrtd(d0 * d0 + d1 * d1) * 4.0F;
if (f > 1.0F)
{
f = 1.0F;
}
this.lswingAmount += (f - this.lswingAmount) * 0.4F;
this.limbSwing += this.lswingAmount;
if (!this.otherPlayerUsing && this.isUsingItem() && this.getHeldItem() != null)
{
ItemStack itemstack = this.getHeldItem();
this.setItemInUse(itemstack, itemstack.getItem().getMaxItemUseDuration(itemstack));
this.otherPlayerUsing = true;
}
else if (this.otherPlayerUsing && !this.isUsingItem())
{
this.clearItemInUse();
this.otherPlayerUsing = false;
}
return;
}
this.updateNpc();
// this.updatePlayer();
}
private void updatePlayer() {
this.noClip = this.noclip;
if (this.noclip)
{
this.onGround = false;
}
if (this.itemInUse != null)
{
ItemStack itemstack = this.getHeldItem();
if (itemstack == this.itemInUse)
{
if (this.itemInUseCount <= 25 && this.itemInUseCount % 4 == 0)
{
this.updateItemUse(itemstack, 5);
}
if (--this.itemInUseCount == 0 && !this.worldObj.client)
{
this.onItemUseFinish();
}
}
else
{
this.clearItemInUse();
}
}
if (this.xpCooldown > 0)
{
--this.xpCooldown;
}
this.updateNpc();
// super.onUpdate();
if (!this.worldObj.client && this.openContainer != null && !this.openContainer.canInteractWith(this))
{
this.connection.show(null);
}
this.prevChasingPosX = this.chasingPosX;
this.prevChasingPosY = this.chasingPosY;
this.prevChasingPosZ = this.chasingPosZ;
double d5 = this.posX - this.chasingPosX;
double d0 = this.posY - this.chasingPosY;
double d1 = this.posZ - this.chasingPosZ;
double d2 = 10.0D;
if (d5 > d2)
{
this.prevChasingPosX = this.chasingPosX = this.posX;
}
if (d1 > d2)
{
this.prevChasingPosZ = this.chasingPosZ = this.posZ;
}
if (d0 > d2)
{
this.prevChasingPosY = this.chasingPosY = this.posY;
}
if (d5 < -d2)
{
this.prevChasingPosX = this.chasingPosX = this.posX;
}
if (d1 < -d2)
{
this.prevChasingPosZ = this.chasingPosZ = this.posZ;
}
if (d0 < -d2)
{
this.prevChasingPosY = this.chasingPosY = this.posY;
}
this.chasingPosX += d5 * 0.25D;
this.chasingPosZ += d1 * 0.25D;
this.chasingPosY += d0 * 0.25D;
// if (this.vehicle == null)
// {
// this.startMinecartRidingCoordinate = null;
// }
// if (!this.worldObj.client)
// {
// this.triggerAchievement(StatRegistry.minutesPlayedStat);
// if (this.isEntityAlive())
// {
// this.triggerAchievement(StatRegistry.timeSinceDeathStat);
// }
// }
double d3 = ExtMath.clampd(this.posX, -World.MAX_SIZE + 1, World.MAX_SIZE - 1);
double d4 = ExtMath.clampd(this.posZ, -World.MAX_SIZE + 1, World.MAX_SIZE - 1);
if (d3 != this.posX || d4 != this.posZ)
{
this.setPosition(d3, this.posY, d4);
}
}
/**
* Called when player presses the drop item key
*/
public EntityItem dropOneItem(boolean dropAll)
{
if(this.getSelectedIndex() < 0)
return null;
if(this.client != null) {
CPacketBreak.Action c07packetplayerdigging$action = dropAll ? CPacketBreak.Action.DROP_ALL_ITEMS : CPacketBreak.Action.DROP_ITEM;
this.client.addToSendQueue(new CPacketBreak(c07packetplayerdigging$action, LocalPos.ORIGIN, Facing.DOWN));
return null;
}
return this.dropItem(this.decrStackSize(this.getSelectedIndex(), dropAll && this.getHeldItem() != null ? this.getHeldItem().getSize() : 1), false, true);
}
protected void changeSize(float width, float height) {
super.changeSize(width, height);
if(this.client != null)
this.stepHeight = height / 3.0f;
}
/**
* Swings the item the player is holding.
*/
public void swingItem()
{
super.swingItem();
if(this.client != null)
this.client.addToSendQueue(new CPacketAction(CPacketAction.Action.SWING_ARM));
}
/**
* Deals damage to the entity. If its a EntityNPC then will take damage from the armor first and then health
* second with the reduced value. Args: damageAmount
*/
protected void damageEntity(DamageSource damageSrc, int damageAmount)
{
if(this.client != null) {
// if(!this.isEntityInvulnerable(damageSrc))
this.setHealth(this.getHealth() - damageAmount);
return;
}
if(!this.isPlayer()) {
super.damageEntity(damageSrc, damageAmount);
return;
}
// if (!this.isEntityInvulnerable(damageSrc))
// {
if (!damageSrc.isUnblockable() && this.isBlocking() && damageAmount > 0)
{
damageAmount = (1 + damageAmount) / 2;
}
damageAmount = this.applyArmorCalculations(damageSrc, damageAmount);
damageAmount = this.applyPotionDamageCalculations(damageSrc, damageAmount);
int f = damageAmount;
damageAmount = Math.max(damageAmount - this.getAbsorptionAmount(), 0);
this.setAbsorptionAmount(this.getAbsorptionAmount() - (f - damageAmount));
if (damageAmount != 0)
{
// float f1 = this.getHealth();
this.setHealth(this.getHealth() - damageAmount);
this.trackDamage(damageSrc, damageAmount);
// if ((float)damageAmount < 3.4028235E37F)
// {
// if(damageAmount < Integer.MAX_VALUE)
// this.addStat(StatRegistry.damageTakenStat, damageAmount);
// }
}
// }
}
protected boolean pushOutOfBlocks(double x, double y, double z)
{
if(this.client == null)
return super.pushOutOfBlocks(x, y, z);
if (this.noClip)
{
return false;
}
else
{
LocalPos blockpos = new LocalPos(x, y, z);
double d0 = x - (double)blockpos.getX();
double d1 = z - (double)blockpos.getZ();
if (!this.isOpenBlockSpace(blockpos))
{
int i = -1;
double d2 = 9999.0D;
if (this.isOpenBlockSpace(blockpos.west()) && d0 < d2)
{
d2 = d0;
i = 0;
}
if (this.isOpenBlockSpace(blockpos.east()) && 1.0D - d0 < d2)
{
d2 = 1.0D - d0;
i = 1;
}
if (this.isOpenBlockSpace(blockpos.north()) && d1 < d2)
{
d2 = d1;
i = 4;
}
if (this.isOpenBlockSpace(blockpos.south()) && 1.0D - d1 < d2)
{
d2 = 1.0D - d1;
i = 5;
}
float f = 0.1F;
if (i == 0)
{
this.motionX = (double)(-f);
}
if (i == 1)
{
this.motionX = (double)f;
}
if (i == 4)
{
this.motionZ = (double)(-f);
}
if (i == 5)
{
this.motionZ = (double)f;
}
}
return false;
}
}
/**
* Set sprinting switch for Entity.
*/
public void setSprinting(boolean sprinting)
{
super.setSprinting(sprinting);
if(this.client != null)
this.sprintingTicksLeft = sprinting ? 600 : 0;
}
public void playSound(SoundEvent name, float volume)
{
if(this.connection != null)
this.connection.playSound(name, volume);
else if(this.client != null)
this.worldObj.clientSound(name, this.posX, this.posY, this.posZ, volume);
else if(!this.slave)
super.playSound(name, volume);
}
public boolean isTicked()
{
return (!this.worldObj.client && (Vars.mobTick || this.connection != null)) || this.client != null;
}
/**
* Called when the player performs a critical hit on the Entity. Args: entity that was hit critically
*/
public void onCriticalHit(Entity entityHit)
{
if(this.connection != null)
this.connection.onCriticalHit(entityHit);
else if(this.client != null)
this.client.spawnCritParticles(entityHit);
}
/**
* Returns if this entity is sneaking.
*/
public boolean isSneaking()
{
return this.client != null && this.client.isRenderViewEntity(this) ? this.client.isSneaking() : super.isSneaking();
}
public void updateEntityActionState()
{
if(!this.isPlayer()) {
super.updateEntityActionState();
return;
}
this.updateArmSwingProgress();
this.headYaw = this.rotYaw;
// super.updateEntityActionState();
if (this.client != null)
{
if(this.client.isRenderViewEntity(this)) {
this.moveStrafe = this.client.getMoveStrafe();
this.moveForward = this.client.getMoveForward();
this.jumping = this.client.isJumping();
this.prevRenderArmYaw = this.renderArmYaw;
this.prevRenderArmPitch = this.renderArmPitch;
this.renderArmPitch = (float)((double)this.renderArmPitch + (double)(this.rotPitch - this.renderArmPitch) * 0.5D);
this.renderArmYaw = (float)((double)this.renderArmYaw + (double)(this.rotYaw - this.renderArmYaw) * 0.5D);
}
else {
this.moveStrafe = 0.0f;
this.moveForward = 0.0f;
this.jumping = false;
this.setSprinting(false);
}
}
}
/**
* Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
* use this to react to sunlight and start to burn.
*/
public void onLivingUpdate()
{
if(this.client != null) {
if (this.sprintingTicksLeft > 0)
{
--this.sprintingTicksLeft;
if (this.sprintingTicksLeft == 0)
{
this.setSprinting(false);
}
}
if (this.sprintToggleTimer > 0)
{
--this.sprintToggleTimer;
}
// this.prevNausea = this.nausea;
// if (this.inStandingPortal)
// {
// if (this.gm.openGui != null && !this.gm.openGui.doesGuiPauseGame())
// {
// this.gm.displayGuiScreen((GuiScreen)null);
// }
//
//// if (this.timeInPortal == 0.0F)
//// {
//// this.gm.getSoundHandler().playSound(new PositionedSoundRecord("portal.trigger", this.rand.floatv() * 0.4F + 0.8F));
//// }
//
//// this.timeInPortal += 0.0125F;
////
//// if (this.timeInPortal >= 1.0F)
//// {
//// this.timeInPortal = 1.0F;
//// }
//
// this.inStandingPortal = false;
// }
// if (this.hasEffect(Potion.confusion) && this.getEffect(Potion.confusion).getDuration() > 60)
// {
// this.nausea += 0.006666667F;
//
// if (this.nausea > 1.0F)
// {
// this.nausea = 1.0F;
// }
// }
// else
// {
// if (this.nausea > 0.0F)
// {
// this.nausea -= 0.05F;
// }
//
// if (this.nausea < 0.0F)
// {
// this.nausea = 0.0F;
// }
// }
// if (this.portalTimer > 0)
// {
// --this.portalTimer;
// }
boolean jump = this.client.isJumping();
boolean sneak = this.client.isSneaking();
float f = 0.8F;
boolean moving = this.client.getMoveForward() >= f;
this.client.updatePlayerMoveState();
boolean current = this.client.isRenderViewEntity(this);
if (current && this.isUsingItem() && !this.isRiding())
{
this.client.setMoveStrafe(this.client.getMoveStrafe() * 0.2F);
this.client.setMoveForward(this.client.getMoveForward() * 0.2F);
this.sprintToggleTimer = 0;
}
this.pushOutOfBlocks(this.posX - (double)this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ + (double)this.width * 0.35D);
this.pushOutOfBlocks(this.posX - (double)this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ - (double)this.width * 0.35D);
this.pushOutOfBlocks(this.posX + (double)this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ - (double)this.width * 0.35D);
this.pushOutOfBlocks(this.posX + (double)this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ + (double)this.width * 0.35D);
boolean canSprint = true; // (float)this.getFoodStats().getFoodLevel() > 6.0F || this.allowFlying;
if (current && this.onGround && !sneak && !moving && this.client.getMoveForward() >= f && !this.isSprinting() && canSprint && !this.isUsingItem() && !this.hasEffect(Effect.BLINDNESS))
{
if (this.sprintToggleTimer <= 0 && !this.client.isSprinting())
{
this.sprintToggleTimer = 7;
}
else
{
this.setSprinting(true);
}
}
if (current && !this.isSprinting() && this.client.getMoveForward() >= f && canSprint && !this.isUsingItem() && !this.hasEffect(Effect.BLINDNESS) && this.client.isSprinting())
{
this.setSprinting(true);
}
if (current && this.isSprinting() && (this.client.getMoveForward() < f || this.collidedHorizontally || !canSprint))
{
this.setSprinting(false);
}
if (this.hasEffect(Effect.FLYING) || this.noclip || this.canNaturallyFly())
{
if (this.noclip)
{
if (!this.flying)
{
this.flying = true;
this.client.addToSendQueue(new CPacketAction(CPacketAction.Action.START_FLYING));
}
}
else if (current && !jump && this.client.isJumping())
{
if (this.flyToggleTimer == 0)
{
this.flyToggleTimer = 7;
}
else
{
this.flying = !this.flying;
this.client.addToSendQueue(new CPacketAction(this.flying ?
CPacketAction.Action.START_FLYING : CPacketAction.Action.STOP_FLYING));
this.flyToggleTimer = 0;
}
}
}
else { // if(!this.firstEffectUpdate) {
this.flying = false;
}
// this.firstEffectUpdate = false;
if (current && this.isFlying())
{
if (this.client.isSneaking())
{
this.motionY -= (double)(
this.landMovement * 0.5f * (this.canFlyFullSpeed() ? 3.0F : 1.0F));
}
if (this.client.isJumping())
{
this.motionY += (double)(
this.landMovement * 0.5f * (this.canFlyFullSpeed() ? 3.0F : 1.0F));
}
}
if (current && this.isRidingHorse())
{
if (this.horseJumpPowerCounter < 0)
{
++this.horseJumpPowerCounter;
if (this.horseJumpPowerCounter == 0)
{
this.horseJumpPower = 0.0F;
}
}
if (jump && !this.client.isJumping())
{
this.horseJumpPowerCounter = -10;
this.sendHorseJump();
}
else if (!jump && this.client.isJumping())
{
this.horseJumpPowerCounter = 0;
this.horseJumpPower = 0.0F;
}
else if (jump)
{
++this.horseJumpPowerCounter;
if (this.horseJumpPowerCounter < 10)
{
this.horseJumpPower = (float)this.horseJumpPowerCounter * 0.1F;
}
else
{
this.horseJumpPower = 0.8F + 2.0F / (float)(this.horseJumpPowerCounter - 9) * 0.1F;
}
}
}
else
{
this.horseJumpPower = 0.0F;
}
this.onPlayerUpdate();
// super.onLivingUpdate();
if (this.onGround && this.flying && !this.noclip)
{
this.flying = false;
this.client.addToSendQueue(new CPacketAction(CPacketAction.Action.STOP_FLYING));
}
return;
}
if(this.slave) {
if (this.otherPlayerMPPosRotationIncrements > 0)
{
double d0 = this.posX + (this.otherPlayerMPX - this.posX) / (double)this.otherPlayerMPPosRotationIncrements;
double d1 = this.posY + (this.otherPlayerMPY - this.posY) / (double)this.otherPlayerMPPosRotationIncrements;
double d2 = this.posZ + (this.otherPlayerMPZ - this.posZ) / (double)this.otherPlayerMPPosRotationIncrements;
double d3;
for (d3 = this.otherPlayerMPYaw - (double)this.rotYaw; d3 < -180.0D; d3 += 360.0D)
{
;
}
while (d3 >= 180.0D)
{
d3 -= 360.0D;
}
this.rotYaw = (float)((double)this.rotYaw + d3 / (double)this.otherPlayerMPPosRotationIncrements);
this.rotPitch = (float)((double)this.rotPitch + (this.otherPlayerMPPitch - (double)this.rotPitch) / (double)this.otherPlayerMPPosRotationIncrements);
--this.otherPlayerMPPosRotationIncrements;
this.setPosition(d0, d1, d2);
this.setRotation(this.rotYaw, this.rotPitch);
}
this.prevCameraYaw = this.cameraYaw;
this.updateArmSwingProgress();
float f1 = ExtMath.sqrtd(this.motionX * this.motionX + this.motionZ * this.motionZ);
float f = (float)Math.atan(-this.motionY * 0.20000000298023224D) * 15.0F;
if (f1 > 0.1F)
{
f1 = 0.1F;
}
if (!this.onGround || this.getHealth() <= 0)
{
f1 = 0.0F;
}
if (this.onGround || this.getHealth() <= 0)
{
f = 0.0F;
}
this.cameraYaw += (f1 - this.cameraYaw) * 0.4F;
this.camPitch += (f - this.camPitch) * 0.8F;
return;
}
if(this.connection != null) {
this.onPlayerUpdate();
}
else {
// if(!(this.isPlayer()))
this.updateArmSwingProgress();
this.onNpcUpdate();
}
}
private void onPlayerUpdate() {
if (this.flyToggleTimer > 0)
{
--this.flyToggleTimer;
}
if (!this.worldObj.client && this.sinceLastAttack < Integer.MAX_VALUE)
{
++this.sinceLastAttack;
}
// this.inventory.decrementAnimations();
this.prevCameraYaw = this.cameraYaw;
// super.onLivingUpdate();
this.onNpcUpdate();
this.jumpMovement = this.speedInAir;
if (this.isSprinting())
{
this.jumpMovement = (float)((double)this.jumpMovement + (double)this.speedInAir * 0.3D);
}
this.setAIMoveSpeed(this.getMovementSpeed() / 3.0f);
float f = ExtMath.sqrtd(this.motionX * this.motionX + this.motionZ * this.motionZ);
float f1 = (float)(Math.atan(-this.motionY * 0.20000000298023224D) * 15.0D);
if (f > 0.1F)
{
f = 0.1F;
}
if (!this.onGround || this.getHealth() <= 0)
{
f = 0.0F;
}
if (this.onGround || this.getHealth() <= 0)
{
f1 = 0.0F;
}
this.cameraYaw += (f - this.cameraYaw) * 0.4F;
this.camPitch += (f1 - this.camPitch) * 0.8F;
if (this.getHealth() > 0 && !this.noclip)
{
BoundingBox axisalignedbb = null;
if (this.vehicle != null && !this.vehicle.dead)
{
axisalignedbb = this.getEntityBoundingBox().union(this.vehicle.getEntityBoundingBox()).expand(1.0D, 0.0D, 1.0D);
}
else
{
axisalignedbb = this.getEntityBoundingBox().expand(1.0D, 0.5D, 1.0D);
}
List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, axisalignedbb);
for (int i = 0; i < list.size(); ++i)
{
Entity entity = (Entity)list.get(i);
if (!entity.dead)
{
this.collideWithPlayer(entity);
}
}
}
}
// END SP
// START SP SPEC
/**
* called every tick when the player is on foot. Performs all the things that normally happen during movement.
*/
public void syncMovement()
{
boolean flag = this.isSprinting();
if (flag != this.serverSprintState)
{
if (flag)
{
this.client.addToSendQueue(new CPacketAction(CPacketAction.Action.START_SPRINTING));
}
else
{
this.client.addToSendQueue(new CPacketAction(CPacketAction.Action.STOP_SPRINTING));
}
this.serverSprintState = flag;
}
boolean flag1 = this.isSneaking();
if (flag1 != this.serverSneakState)
{
if (flag1)
{
this.client.addToSendQueue(new CPacketAction(CPacketAction.Action.START_SNEAKING));
}
else
{
this.client.addToSendQueue(new CPacketAction(CPacketAction.Action.STOP_SNEAKING));
}
this.serverSneakState = flag1;
}
double d0 = this.posX - this.lastReportedPosX;
double d1 = this.getEntityBoundingBox().minY - this.lastReportedPosY;
double d2 = this.posZ - this.lastReportedPosZ;
double d3 = (double)(this.rotYaw - this.lastReportedYaw);
double d4 = (double)(this.rotPitch - this.lastReportedPitch);
boolean flag2 = d0 * d0 + d1 * d1 + d2 * d2 > 9.0E-4D || this.positionUpdateTicks >= 20;
boolean flag3 = d3 != 0.0D || d4 != 0.0D;
if (this.vehicle == null)
{
if (flag2 && flag3)
{
this.client.addToSendQueue(new CPacketPlayerPosLook(this.posX, this.getEntityBoundingBox().minY, this.posZ, this.rotYaw, this.rotPitch, this.onGround));
}
else if (flag2)
{
this.client.addToSendQueue(new CPacketPlayerPosition(this.posX, this.getEntityBoundingBox().minY, this.posZ, this.onGround));
}
else if (flag3)
{
this.client.addToSendQueue(new CPacketPlayerLook(this.rotYaw, this.rotPitch, this.onGround));
}
else
{
this.client.addToSendQueue(new CPacketPlayer(this.onGround));
}
}
else
{
this.client.addToSendQueue(new CPacketPlayerPosLook(this.motionX, -99999999.0D, this.motionZ, this.rotYaw, this.rotPitch, this.onGround));
flag2 = false;
}
++this.positionUpdateTicks;
if (flag2)
{
this.lastReportedPosX = this.posX;
this.lastReportedPosY = this.getEntityBoundingBox().minY;
this.lastReportedPosZ = this.posZ;
this.positionUpdateTicks = 0;
}
if (flag3)
{
this.lastReportedYaw = this.rotYaw;
this.lastReportedPitch = this.rotPitch;
}
}
public void respawnPlayer()
{
this.client.addToSendQueue(new CPacketAction(CPacketAction.Action.PERFORM_RESPAWN));
}
public void setPlayerSPHealth(int health)
{
if (this.hasValidHealth)
{
int f = this.getHealth() - health;
if (f <= 0)
{
this.setHealth(health);
if (f < 0)
{
this.hurtResistance = this.hurtCooldown / 2;
}
}
else
{
this.lastDamage = f;
this.setHealth(this.getHealth());
this.hurtResistance = this.hurtCooldown;
this.damageEntity(DamageSource.generic, f);
this.hurtTime = this.maxHurtTime = 10;
}
}
else
{
this.setHealth(health);
this.hasValidHealth = true;
}
}
protected void sendHorseJump()
{
this.client.addToSendQueue(new CPacketAction(CPacketAction.Action.RIDING_JUMP, (int)(this.getHorseJumpPower() * 100.0F)));
}
public void sendHorseInventory()
{
this.client.addToSendQueue(new CPacketAction(CPacketAction.Action.OPEN_INVENTORY));
}
/**
* Returns true if the block at the given BlockPos and the block above it are NOT full cubes.
*/
private boolean isOpenBlockSpace(LocalPos pos)
{
return !this.worldObj.getState(pos).getBlock().isNormalCube() && (this.height <= 1.0f || !this.worldObj.getState(pos.up()).getBlock().isNormalCube());
}
public void setXPStats(float currentXP, int maxXP, int level)
{
this.experience = currentXP;
this.experienceTotal = maxXP;
this.experienceLevel = level;
}
public boolean isRidingHorse()
{
return this.vehicle != null && this.vehicle instanceof EntityHorse && ((EntityHorse)this.vehicle).isHorseSaddled();
}
public float getHorseJumpPower()
{
return this.horseJumpPower;
}
// END SP SPEC
// START OTHER
public void setClientPosition(double x, double y, double z, float yaw, float pitch, boolean teleport)
{
if(this.slave && this.client == null) {
this.otherPlayerMPX = x;
this.otherPlayerMPY = y;
this.otherPlayerMPZ = z;
this.otherPlayerMPYaw = (double)yaw;
this.otherPlayerMPPitch = (double)pitch;
this.otherPlayerMPPosRotationIncrements = 3;
}
else {
super.setClientPosition(x, y, z, yaw, pitch, teleport);
}
}
public int getHotbarSize() {
return Equipment.INVENTORY_SLOTS;
}
public int getSelectedIndex() {
return this.currentItem;
}
public void setSelectedIndex(int index) {
this.currentItem = index;
}
public ItemStack getHeldItem()
{
return this.getSelectedIndex() < this.getHotbarSize() && this.getSelectedIndex() >= 0 ? this.getStackInSlot(this.getSelectedIndex()) : null;
}
public ItemStack[] getArmor()
{
return this.armor;
}
public ItemStack[] getInventory()
{
return this.items;
}
public ItemStack getArmor(Equipment slot)
{
return this.getArmor()[slot.getIndex()];
}
public void setHeldItem(ItemStack stack)
{
if(!this.isPlayer() && !this.dummy)
this.setSelectedIndex(0);
if(this.getSelectedIndex() >= 0)
this.setInventorySlotContents(this.getSelectedIndex(), stack);
if(!this.isPlayer() && !this.dummy && !this.worldObj.client)
this.setCombatTask();
}
public final void clearHeldItem()
{
this.setHeldItem(null);
}
public void setArmor(Equipment slot, ItemStack stack)
{
this.getArmor()[slot.getIndex()] = stack;
}
public void setHeldNoUpdate(ItemStack stack)
{
if(!this.isPlayer() && !this.dummy) {
this.setSelectedIndex(0);
this.setInventorySlotContents(this.getSelectedIndex(), stack);
}
}
public void setMouseItem(ItemStack stack)
{
this.mouseItem = stack;
}
public ItemStack getMouseItem()
{
return this.mouseItem;
}
public int getInventorySlotContainItem(Item itemIn)
{
for (int i = 0; i < Equipment.INVENTORY_SLOTS; ++i)
{
if (this.getInventory()[i] != null && this.getInventory()[i].getItem() == itemIn)
{
return i;
}
}
return -1;
}
private int storeItemStack(ItemStack itemStackIn)
{
for (int i = 0; i < Equipment.INVENTORY_SLOTS; ++i)
{
if (this.getInventory()[i] != null && this.getInventory()[i].getItem() == itemStackIn.getItem() && this.getInventory()[i].isStackable() && !this.getInventory()[i].isFull() && ItemStack.dataEquals(this.getInventory()[i], itemStackIn))
{
return i;
}
}
return -1;
}
public int getFirstEmptyStack()
{
for (int i = 0; i < Equipment.INVENTORY_SLOTS; ++i)
{
if (this.getInventory()[i] == null)
{
return i;
}
}
return -1;
}
private int storePartialItemStack(ItemStack itemStackIn)
{
Item item = itemStackIn.getItem();
int i = itemStackIn.getSize();
int j = this.storeItemStack(itemStackIn);
if (j < 0)
{
j = this.getFirstEmptyStack();
}
if (j < 0)
{
return i;
}
else
{
if (this.getInventory()[j] == null)
{
this.getInventory()[j] = new ItemStack(item, 0);
this.getInventory()[j].copyData(itemStackIn);
}
int k = i;
if (i > this.getInventory()[j].getMaxStackSize() - this.getInventory()[j].getSize())
{
k = this.getInventory()[j].getMaxStackSize() - this.getInventory()[j].getSize();
}
if (k == 0)
{
return i;
}
else
{
i = i - k;
this.getInventory()[j].incrSize(k);
return i;
}
}
}
public boolean consumeInventoryItem(Item itemIn)
{
int i = this.getInventorySlotContainItem(itemIn);
if (i < 0)
{
return false;
}
else
{
if (this.getInventory()[i].decrSize())
{
this.getInventory()[i] = null;
}
return true;
}
}
public boolean hasItem(Item itemIn)
{
int i = this.getInventorySlotContainItem(itemIn);
return i >= 0;
}
public boolean addItemStackToInventory(final ItemStack itemStackIn)
{
if (itemStackIn != null && !itemStackIn.isEmpty() && itemStackIn.getItem() != null)
{
if (itemStackIn.isItemDamaged())
{
int j = this.getFirstEmptyStack();
if (j >= 0)
{
this.getInventory()[j] = ItemStack.copy(itemStackIn);
itemStackIn.setSize(0);
return true;
}
else
{
return false;
}
}
else
{
int i;
while (true)
{
i = itemStackIn.getSize();
itemStackIn.setSize(this.storePartialItemStack(itemStackIn));
if (itemStackIn.isEmpty() || itemStackIn.getSize() >= i)
{
break;
}
}
return itemStackIn.getSize() < i;
}
}
else
{
return false;
}
}
public ItemStack addStack(ItemStack stack)
{
ItemStack itemstack = stack.copy();
for (int i = 0; i < Equipment.INVENTORY_SLOTS; ++i)
{
ItemStack itemstack1 = this.getInventory()[i];
if (itemstack1 == null)
{
this.getInventory()[i] = itemstack;
return null;
}
if (ItemStack.itemEquals(itemstack1, itemstack))
{
int j = itemstack1.getMaxStackSize();
int k = Math.min(itemstack.getSize(), j - itemstack1.getSize());
if (k > 0)
{
itemstack1.incrSize(k);
if (itemstack.decrSize(k))
{
return null;
}
}
}
}
return itemstack;
}
public boolean hasItemStack(ItemStack itemStackIn)
{
for (ItemStack stack : this.getArmor())
{
if (stack != null && stack.itemEquals(itemStackIn))
{
return true;
}
}
for (int j = 0; j < Equipment.INVENTORY_SLOTS; ++j)
{
if (this.getInventory()[j] != null && this.getInventory()[j].itemEquals(itemStackIn))
{
return true;
}
}
return false;
}
public int getInventoryCapacity() {
return 36;
}
public boolean hasArmorSlot(Equipment slot) {
return true;
}
// END OTHER
// START MP
private void addExperienceLevel(int levels) {
this.experienceLevel += levels;
if (this.experienceLevel < 0)
{
this.experienceLevel = 0;
this.experience = 0.0F;
this.experienceTotal = 0;
}
if (levels > 0 && this.experienceLevel % 5 == 0 && (float)this.lastXPSound < (float)this.ticksExisted - 100.0F)
{
float f = this.experienceLevel > 30 ? 1.0F : (float)this.experienceLevel / 30.0F;
this.worldObj.playSoundAtEntity(this, SoundEvent.LEVELUP, f * 0.75F);
this.lastXPSound = this.ticksExisted;
}
// super.addExperienceLevel(levels);
if(this.connection != null)
this.connection.resetLastExperience();
}
public void updateEnchSeed() {
this.enchSeed = this.rand.intv();
}
public void onDeath(DamageSource cause) {
if(this.connection != null) {
this.connection.onEntityDeath();
return;
}
if(!this.isPlayer()) {
super.onDeath(cause);
return;
}
this.noPickup = true;
super.onDeath(cause);
if(this.slave) {
this.changeSize(0.2F, 0.2F);
this.setPosition(this.posX, this.posY, this.posZ);
this.motionY = 0.10000000149011612D;
if (this.worldObj.client || (!Vars.keepInventory && Vars.playerDrop))
{
this.clear();
}
if (cause != null)
{
this.motionX = (double)(-ExtMath.cos((this.attackedYaw + this.rotYaw) * (float)Math.PI / 180.0F) * 0.1F);
this.motionZ = (double)(-ExtMath.sin((this.attackedYaw + this.rotYaw) * (float)Math.PI / 180.0F) * 0.1F);
}
else
{
this.motionX = this.motionZ = 0.0D;
}
// this.triggerAchievement(StatRegistry.deathsStat);
// this.removeStat(StatRegistry.timeSinceDeathStat);
}
}
public Entity travelToDimension(Dimension dimensionId, LocalPos pos, float yaw, float pitch, PortalType portal) {
if(this.connection != null)
this.connection.travelToDimension(dimensionId, pos, yaw, pitch, portal);
return this.isPlayer() ? this : super.travelToDimension(dimensionId, pos, yaw, pitch, portal);
}
public void teleport(double x, double y, double z, float yaw, float pitch, Dimension dimension) {
if(this.connection != null)
this.connection.teleport(x, y, z, yaw, pitch, dimension);
else if(!this.isPlayer())
super.teleport(x, y, z, yaw, pitch, dimension);
}
public void onItemPickup(Entity entity, int amount) {
super.onItemPickup(entity, amount);
if(this.connection != null)
this.connection.onItemPickup(entity, amount);
}
protected void updateFallState(double y, boolean onGroundIn, Block blockIn, LocalPos pos) {
if(this.connection == null)
super.updateFallState(y, onGroundIn, blockIn, pos);
}
public void addMoved(int amount) {
this.movedDistance += (long)amount;
}
public long getMovedDistance() {
return this.movedDistance;
}
protected void onItemUseFinish() {
if(this.connection != null)
this.connection.onItemUseFinish();
// super.onItemUseFinish();
if (this.itemInUse != null)
{
this.updateItemUse(this.itemInUse, 16);
int i = this.itemInUse.getSize();
ItemStack itemstack = this.itemInUse.getItem().onItemUseFinish(this.itemInUse, this.worldObj, this);
if (itemstack != this.itemInUse || itemstack != null && itemstack.getSize() != i)
{
this.setHeldItem(itemstack);
if (itemstack.isEmpty())
{
this.clearHeldItem();
}
}
this.clearItemInUse();
}
}
protected void onNewEffect(StatusEffect id) {
super.onNewEffect(id);
if(this.connection != null)
this.connection.onNewEffect(id);
}
protected void onChangedEffect(StatusEffect id, boolean added) {
super.onChangedEffect(id, added);
if(this.connection != null)
this.connection.onChangedEffect(id, added);
}
protected void onFinishedEffect(StatusEffect effect) {
super.onFinishedEffect(effect);
if(this.isPlayer() && effect.getPotion() == Effect.FLYING && !this.noclip && !this.canNaturallyFly())
this.flying = false;
// super.onFinishedEffect(effect);
if(this.connection != null)
this.connection.onFinishedEffect(effect);
}
public void setPositionAndUpdate(double x, double y, double z) {
if(this.connection != null)
this.connection.setPositionAndUpdate(x, y, z);
else
super.setPositionAndUpdate(x, y, z);
}
public void updateEffectMeta() {
super.updateEffectMeta();
if(this.connection != null)
this.connection.updateEffectMeta();
}
public final AWorldServer getServerWorld() {
return (AWorldServer)this.worldObj;
}
public void onUpdateEntity() {
// super.onUpdate();
this.updatePlayer();
}
public void updateEntityFall(double y, boolean onGroundIn, Block blockIn, LocalPos pos) {
super.updateFallState(y, onGroundIn, blockIn, pos);
}
// END MP
// START PLAYER
public boolean isOnLadder()
{
return (!this.isPlayer() || !this.noclip) && super.isOnLadder();
}
// protected void applyEntityAttributes()
// {
// super.applyEntityAttributes();
// }
protected void entityInit()
{
super.entityInit();
this.dataWatcher.addObject(8, (byte)Alignment.NEUTRAL.ordinal()); // alignment
this.dataWatcher.addObject(9, ""); // character
this.dataWatcher.addObject(10, (byte)-1); // class
this.dataWatcher.addObject(11, 1.0f); // height
this.dataWatcher.addObject(12, 0); // absorption
this.dataWatcher.addObject(13, 0); // max mana
this.dataWatcher.addObject(14, 0); // mana
this.dataWatcher.addObject(15, 0.7f);
}
/**
* returns the ItemStack containing the itemInUse
*/
public ItemStack getItemInUse()
{
return this.itemInUse;
}
/**
* Returns the item in use count
*/
public int getItemInUseCount()
{
return this.itemInUseCount;
}
/**
* Checks if the entity is currently using an item (e.g., bow, food, sword) by holding down the useItemButton
*/
public boolean isUsingItem()
{
return this.isPlayer() ? this.itemInUse != null : this.getFlag(4);
}
/**
* gets the duration for how long the current itemInUse has been in use
*/
public int getItemInUseDuration()
{
return this.isUsingItem() ? this.itemInUse.getMaxItemUseDuration() - this.itemInUseCount : 0;
}
public void stopUsingItem()
{
if (this.itemInUse != null)
{
this.itemInUse.getItem().onPlayerStoppedUsing(this.itemInUse, this.worldObj, this, this.itemInUseCount);
}
this.clearItemInUse();
}
public void clearItemInUse()
{
this.itemInUse = null;
this.itemInUseCount = 0;
if (!this.worldObj.client)
{
this.setUsingItem(false);
}
}
public boolean isBlocking()
{
return this.isUsingItem() && this.itemInUse.getItem().getItemUseAction() == ItemAction.BLOCK;
}
/**
* Plays sounds and makes particles for item in use state
*/
protected void updateItemUse(ItemStack itemStackIn, int p_71010_2_)
{
if (itemStackIn.getItemUseAction() == ItemAction.DRINK)
{
this.playSound(SoundEvent.DRINK, 0.5F);
}
if (itemStackIn.getItemUseAction() == ItemAction.EAT)
{
this.playSound(SoundEvent.EAT, 0.5F + 0.5F * (float)this.rand.zrange(2));
}
}
@Clientside
public void handleStatusUpdate(byte id)
{
if (this.isPlayer() && id == 9)
{
this.onItemUseFinish();
}
else if (id == 12)
{
this.spawnParticles(ParticleType.HEART);
}
else if (id == 13)
{
this.spawnParticles(ParticleType.SMOKE);
}
else
{
super.handleStatusUpdate(id);
}
}
// /**
// * Dead and sleeping entities cannot move
// */
// protected boolean isMovementBlocked()
// {
// return this.getHealth() <= 0; // || this.isPlayerSleeping();
// }
/**
* Handles updating while being ridden by an entity
*/
public void updateRidden()
{
if(!this.isPlayer()) {
super.updateRidden();
return;
}
if (!this.worldObj.client && this.isSneaking())
{
this.mountEntity((Entity)null);
this.setSneaking(false);
}
else
{
double d0 = this.posX;
double d1 = this.posY;
double d2 = this.posZ;
float f = this.rotYaw;
float f1 = this.rotPitch;
super.updateRidden();
this.prevCameraYaw = this.cameraYaw;
this.cameraYaw = 0.0F;
this.addMountedMovement(this.posX - d0, this.posY - d1, this.posZ - d2);
if (this.vehicle instanceof EntityPig)
{
this.rotPitch = f1;
this.rotYaw = f;
this.yawOffset = ((EntityPig)this.vehicle).yawOffset;
}
}
}
/**
* Keeps moving the entity up so it isn't colliding with blocks and other requirements for this entity to be spawned
* (only actually used on players though its also on Entity)
*/
public void preparePlayerToSpawn()
{
if(this.isPlayer()) {
this.updateSize();
super.preparePlayerToSpawn();
this.setHealth(this.getMaxHealth());
this.deathTime = 0;
}
else {
super.preparePlayerToSpawn();
}
}
public void onDataWatcherUpdate(int data) {
if(this.isPlayer() && data == 11) // (data == 29 || data == 11)) // && this.worldObj.client)
this.updateSize();
else if(data == 8 && this.worldObj.client)
this.alignment = this.getAlignment();
}
private void updateSize() {
// ModelType model = this.getModel();
// this.changeSize(this.getHeight() * this.species.renderer.width / this.species.renderer.height, this.getHeight());
this.changeSize(this.getHeight() / this.species.renderer.height * this.species.renderer.width, this.getHeight());
}
public double getReachDistance()
{
return Math.max(1.5, 5.0 * (double)this.height / 1.8);
}
public float getRenderScale()
{
return /* this.isPlayer() ? (0.9375f * this.height / this.getModel().height) : ( */ 0.9375f * this.height / this.species.renderer.height; // );
}
protected void handleJumpLava()
{
this.motionY += 0.03999999910593033D * (this.height /* this.getHeight() * 1.8f */ + 2.2f) / 4.0f;
}
protected float getJumpUpwardsMotion()
{
return 0.42F * ((this.height < 1.9f ? 1.9f : this.height) /* this.getHeight() * 1.8f */ + 2.2f) / 4.0f;
}
public void setAIMoveSpeed(float speedIn)
{
this.landMovement = speedIn;
if(!this.isPlayer())
this.setMoveForward(speedIn);
}
private void collideWithPlayer(Entity p_71044_1_)
{
p_71044_1_.onCollideWithPlayer(this);
}
public final EntityItem dropItem(ItemStack itemStackIn, boolean traceItem)
{
return this.dropItem(itemStackIn, false, traceItem);
}
public EntityItem dropItem(ItemStack droppedItem, boolean dropAround, boolean traceItem)
{
if(this.worldObj.client || droppedItem == null || droppedItem.isEmpty())
return null;
if(traceItem)
this.connection.sendThrowMessage(droppedItem);
double d0 = this.posY - 0.30000001192092896D + (double)this.getEyeHeight();
EntityItem entityitem = new EntityItem(this.worldObj, this.posX, d0, this.posZ, droppedItem);
entityitem.setPickupDelay(40);
// if (traceItem)
// {
// entityitem.setThrower(this.getUser());
// }
if (dropAround)
{
float f = this.rand.floatv() * 0.5F;
float f1 = this.rand.floatv() * (float)Math.PI * 2.0F;
entityitem.motionX = (double)(-ExtMath.sin(f1) * f);
entityitem.motionZ = (double)(ExtMath.cos(f1) * f);
entityitem.motionY = 0.20000000298023224D;
}
else
{
float f2 = 0.3F;
entityitem.motionX = (double)(-ExtMath.sin(this.rotYaw / 180.0F * (float)Math.PI) * ExtMath.cos(this.rotPitch / 180.0F * (float)Math.PI) * f2);
entityitem.motionZ = (double)(ExtMath.cos(this.rotYaw / 180.0F * (float)Math.PI) * ExtMath.cos(this.rotPitch / 180.0F * (float)Math.PI) * f2);
entityitem.motionY = (double)(-ExtMath.sin(this.rotPitch / 180.0F * (float)Math.PI) * f2 + 0.1F);
float f3 = this.rand.floatv() * (float)Math.PI * 2.0F;
f2 = 0.02F * this.rand.floatv();
entityitem.motionX += Math.cos((double)f3) * (double)f2;
entityitem.motionY += (double)((this.rand.floatv() - this.rand.floatv()) * 0.1F);
entityitem.motionZ += Math.sin((double)f3) * (double)f2;
}
this.worldObj.spawnEntityInWorld(entityitem);
// if (traceItem)
// {
// this.triggerAchievement(StatRegistry.dropStat);
// }
return entityitem;
}
/**
* Block hardness will be further counted in game/block/Block.getPlayerRelativeBlockHardness
*/
public float getToolDigEfficiency(Block block)
{
float f = this.getHeldItem() != null && this.getHeldItem().getItem() instanceof ItemTool tool && block.getMiningTool() == tool.getToolType() ? tool.getToolEfficiency() : 1.0f;
if (f > 1.0F)
{
int i = EnchantmentHelper.getEfficiencyModifier(this);
ItemStack itemstack = this.getHeldItem();
if (i > 0 && itemstack != null)
{
f += (float)(i * i + 1);
}
}
if (this.hasEffect(Effect.HASTE))
{
int speed = this.getEffect(Effect.HASTE).getAmplifier();
if(speed >= 255)
return 1000000.0f;
f *= 1.0F + (float)(speed + 1) * 0.2F;
}
if (this.hasEffect(Effect.FATIGUE))
{
float f1 = 1.0F;
switch (this.getEffect(Effect.FATIGUE).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;
}
return f;
}
public boolean canHarvestBlock(Block block)
{
if(!block.getMaterial().isToolRequired())
return true;
return this.getHeldItem() != null && this.getHeldItem().getItem() instanceof ItemTool tool && block.getMiningTool() == tool.getToolType() && (!tool.getToolType().isLevelled() || tool.getToolLevel() >= block.getMiningLevel());
}
public int getAttackDamage() {
int damage = this.attackDamageBase + (this.getHeldItem() != null && this.getHeldItem().getItem() instanceof ItemTool tool ? tool.getAttackDamageBonus(this.getHeldItem()) : 0);
return Math.max(0, damage + (this.hasEffect(Effect.STRENGTH) ? (damage / 2) * (this.getEffect(Effect.STRENGTH).getAmplifier() + 1) : 0) - (this.hasEffect(Effect.WEAKNESS) ? (damage / 5) * (this.getEffect(Effect.WEAKNESS).getAmplifier() + 1) : 0));
}
public int getAttackDamageBase() {
return this.attackDamageBase;
}
public void setAttackDamageBase(int value) {
this.attackDamageBase = value;
}
public void readEntity(TagObject tag)
{
super.readEntity(tag);
// if(tagCompund.hasBoolean("CanPickUpLoot")) {
// this.setCanPickUpLoot(tagCompund.getBoolean("CanPickUpLoot"));
// }
List<TagObject> list = tag.getList("items");
this.clear();
for(int z = 0; z < list.size() && z < Equipment.INVENTORY_SLOTS; z++) {
TagObject item = list.get(z);
ItemStack stack = ItemStack.readFromTag(item);
if(stack != null)
this.setInventorySlotContents(z, stack);
}
this.setSelectedIndex(this.isPlayer() || this.dummy ? tag.getInt("selected") : 0);
for(Equipment slot : Equipment.ARMOR) {
this.setArmor(slot, ItemStack.readFromTag(tag.getObject(slot.getName())));
}
// this.setSpecies(tagCompund.getString("Species"));
this.setChar(tag.getString("Char"));
this.isWilling = tag.getBool("Willing");
this.setMating(tag.getBool("Mating"));
Alignment // align;
// try {
align = Alignment.getByName(tag.getString("Align"));
// }
// catch(IllegalArgumentException e) {
// align = this.getNaturalAlign(this.rand);
// }
this.setAlignment(align);
this.setMaxMana(Math.max(0, tag.getInt("MaxMana")));
this.setManaPoints(tag.getInt("Mana"));
this.attackDamageBase = tag.getInt("AttackDmg");
Enum type = null;
if(tag.hasString("ClassType") && this.species != null && this.species.classEnum != null) {
type = this.species.classnames.get(tag.getString("ClassType"));
// try {
// type = Enum.valueOf(this.species.classEnum, tagCompund.getString("ClassType").toUpperCase());
// }
// catch(IllegalArgumentException e) {
// type = null;
// }
}
this.setNpcClass(type);
this.setHeight(tag.hasFloat("Height") ? tag.getFloat("Height") : this.getBaseSize());
if(tag.hasList("Offers")) {
this.trades = new MerchantRecipeList();
this.trades.fromTags(tag.getList("Offers"));
}
this.healTimer = tag.getInt("healTimer");
if(tag.hasByteArray("Skin"))
this.skin = tag.getByteArray("Skin");
// this.setCanPickUpLoot(true);
this.setCombatTask();
if(this.isPlayer() || this.dummy) {
// this.entityUniqueID = getOfflineUUID(this.user);
// this.sleeping = tagCompund.getBoolean("Sleeping");
// this.sleepTimer = tagCompund.getShort("SleepTimer");
this.experience = tag.getFloat("XpP");
this.experienceLevel = tag.getInt("XpLevel");
this.experienceTotal = tag.getInt("XpTotal");
this.enchSeed = tag.getInt("EnchSeed");
if (this.enchSeed == 0)
{
this.enchSeed = this.rand.intv();
}
// this.setScore(tagCompund.getInteger("Score"));
// this.setManaPoints(tagCompund.getInteger("Mana"));
// if (this.sleeping)
// {
// this.playerLocation = new BlockPos(this);
// this.wakeUpPlayer();
// }
if (tag.hasInt("SpawnX") && tag.hasInt("SpawnY") && tag.hasInt("SpawnZ") && tag.hasString("SpawnDim"))
{
Dimension dim = DimensionRegistry.getDimension(tag.getString("SpawnDim"));
this.spawnPos = dim == null ? null : new GlobalPos(tag.getInt("SpawnX"), tag.getInt("SpawnY"),
tag.getInt("SpawnZ"), dim);
// this.spawnForced = tagCompund.getBoolean("SpawnForced");
}
if (tag.hasInt("OriginX") && tag.hasInt("OriginY") && tag.hasInt("OriginZ") && tag.hasString("OriginDim"))
{
Dimension dim = DimensionRegistry.getDimension(tag.getString("OriginDim"));
this.originPos = dim == null ? new GlobalPos(0, 64, 0, Space.INSTANCE) : new GlobalPos(tag.getInt("OriginX"), tag.getInt("OriginY"),
tag.getInt("OriginZ"), dim);
}
this.flying = tag.getBool("flying") && (this.hasEffect(Effect.FLYING) || this.canNaturallyFly());
// if(tagCompund.hasKey("speed", 99))
// this.speed = tagCompund.getFloat("speed");
// this.disableDamagePersist = tagCompund.getBoolean("alwaysInvulnerable");
// this.disableTargetPersist = tagCompund.getBoolean("neverTarget");
// this.allowFlyingPersist = tagCompund.getBoolean("alwaysFly");
this.noclip = tag.getBool("noClip");
if (tag.hasList("WarpItems"))
{
List<TagObject> nbttaglist1 = tag.getList("WarpItems");
this.warpChest.readTags(nbttaglist1);
}
this.movedDistance = tag.getLong("MovedDist");
// ModelType // model;
// try {
// model = ModelType.getByName(tagCompund.getString("Model"));
// }
// catch(IllegalArgumentException e) {
// model = ModelType.HUMANOID;
// }
// this.setModel(model);
// this.setModelParts(tagCompund.hasInt("PartFlags") ? tagCompund.getInteger("PartFlags") : ~ModelPart.ARMS_SLIM.getMask());
// if(tagCompund.hasFloat("PlayerScale"))
// this.setPlayerHeight(tagCompund.getFloat("PlayerScale"));
}
}
public void writeEntity(TagObject tag)
{
super.writeEntity(tag);
// tagCompound.setBoolean("CanPickUpLoot", this.canPickUpLoot());
List<TagObject> list = Lists.newArrayList();
for(int z = 0; z < Equipment.INVENTORY_SLOTS; z++) {
if(this.getStackInSlot(z) != null) {
TagObject item = new TagObject();
this.getStackInSlot(z).writeTags(item);
list.add(item);
}
}
tag.setList("items", list);
if(this.isPlayer() || this.dummy)
tag.setInt("selected", this.getSelectedIndex());
for(Equipment slot : Equipment.ARMOR) {
TagObject item = new TagObject();
if(this.getArmor(slot) != null)
this.getArmor(slot).writeTags(item);
tag.setObject(slot.getName(), item);
}
// tagCompound.setString("Species", this.getSpecies());
tag.setString("Char", this.getChar());
tag.setBool("Willing", this.isWilling);
tag.setBool("Mating", this.isMating());
tag.setString("Align", this.alignment.name);
tag.setFloat("Height", this.getHeight());
tag.setInt("MaxMana", this.getMaxMana());
tag.setInt("Mana", this.getManaPoints());
tag.setInt("AttackDmg", this.attackDamageBase);
Enum type = this.getNpcClass();
if(type != null)
tag.setString("ClassType", this.species.classnames.inverse().get(type));
if(this.trades != null)
tag.setList("Offers", this.trades.toTags());
tag.setInt("healTimer", this.healTimer);
if(this.skin != null)
tag.setByteArray("Skin", this.skin);
if(this.isPlayer() || this.dummy) {
// tagCompound.setBoolean("Sleeping", this.sleeping);
// tagCompound.setShort("SleepTimer", (short)this.sleepTimer);
tag.setFloat("XpP", this.experience);
tag.setInt("XpLevel", this.experienceLevel);
tag.setInt("XpTotal", this.experienceTotal);
tag.setInt("EnchSeed", this.enchSeed);
// tagCompound.setInteger("Score", this.getScore());
// tagCompound.setInteger("Mana", this.getManaPoints());
if (this.spawnPos != null)
{
Dimension dim = this.spawnPos.getDimension();
if(dim != null) {
tag.setInt("SpawnX", this.spawnPos.getX());
tag.setInt("SpawnY", this.spawnPos.getY());
tag.setInt("SpawnZ", this.spawnPos.getZ());
tag.setString("SpawnDim", DimensionRegistry.getName(dim));
}
// tagCompound.setBoolean("SpawnForced", this.spawnForced);
}
if (this.originPos != null)
{
Dimension dim = this.originPos.getDimension();
if(dim != null) {
tag.setInt("OriginX", this.originPos.getX());
tag.setInt("OriginY", this.originPos.getY());
tag.setInt("OriginZ", this.originPos.getZ());
tag.setString("OriginDim", DimensionRegistry.getName(dim));
}
}
tag.setBool("flying", this.flying);
// tagCompound.setFloat("speed", this.speed);
// tagCompound.setBoolean("alwaysInvulnerable", this.disableDamagePersist);
// tagCompound.setBoolean("neverTarget", this.disableTargetPersist);
// tagCompound.setBoolean("alwaysFly", this.allowFlyingPersist);
tag.setBool("noClip", this.noclip);
tag.setList("WarpItems", this.warpChest.writeTags());
tag.setLong("MovedDist", this.movedDistance);
// tagCompound.setString("Model", this.getModel().name);
// tagCompound.setInteger("PartFlags", this.getModelParts());
// tagCompound.setFloat("PlayerScale", this.getPlayerHeight());
}
}
protected void damageArmor(int damage)
{
if(this.isPlayer() || this.dummy) {
damage = damage / 4;
if (damage < 1)
damage = 1;
for (Equipment slot : Equipment.ARMOR)
{
ItemStack stack = this.getArmor(slot);
if (stack != null && stack.getItem() instanceof ItemArmor && stack.isItemStackDamageable())
{
stack.damage(damage, this);
if (stack.isEmpty())
this.setArmor(slot, null);
}
}
}
}
public int getTotalArmorValue()
{
int value = 0;
for (ItemStack stack : this.getArmor())
{
if (stack != null && stack.getItem() instanceof ItemArmor armor)
{
value += armor.getArmorValue();
}
}
return value;
}
public boolean interactWith(Entity targetEntity)
{
// if (this.isSpectator())
// {
// if (targetEntity instanceof IInventory)
// {
// this.displayGUIChest((IInventory)targetEntity);
// }
//
// return false;
// }
// else
// {
ItemStack itemstack = this.getHeldItem();
ItemStack itemstack1 = itemstack != null ? itemstack.copy() : null;
if (!targetEntity.interactFirst(this))
{
if (itemstack != null && targetEntity instanceof EntityLiving)
{
// if (this.creative)
// {
// itemstack = itemstack1;
// }
if (itemstack.getItem().itemInteractionForEntity(itemstack, this, (EntityLiving)targetEntity))
{
if (itemstack.isEmpty()) // && !this.creative)
{
this.clearHeldItem();
}
return true;
}
}
return false;
}
else
{
if (itemstack != null && itemstack == this.getHeldItem())
{
if (itemstack.isEmpty()) // && !this.creative)
{
this.clearHeldItem();
}
// else if (itemstack.stackSize < itemstack1.stackSize && this.creative)
// {
// itemstack.stackSize = itemstack1.stackSize;
// }
}
return true;
}
// }
}
/**
* Returns the Y Offset of this entity.
*/
public double getYOffset()
{
return this.isPlayer() ? -0.35D : super.getYOffset();
}
/**
* Attacks for the player the targeted entity with the currently equipped item. The equipped item has hitEntity
* called on it. Args: targetEntity
*/
public void attackTargetEntityWithCurrentItem(Entity targetEntity)
{
if(!this.worldObj.client) {
if(/* !this.creative && */ this.sinceLastAttack < Vars.attackDelay)
return;
this.sinceLastAttack = 0;
}
if (targetEntity.canAttackWithItem())
{
if (!targetEntity.hitByEntity(this))
{
int f = this.getAttackDamage();
int i = EnchantmentHelper.getKnockbackModifier(this);
if (this.isSprinting())
{
++i;
}
if (f > 0)
{
boolean flag = this.fallDistance > 0.0F && !this.onGround && !this.isOnLadder() && !this.isInLiquid() && !this.hasEffect(Effect.BLINDNESS) && this.vehicle == null && targetEntity instanceof EntityLiving;
if (flag)
{
f = (int)((float)f * 1.5F);
}
boolean flag1 = false;
int j = EnchantmentHelper.getFireAspectModifier(this);
if (targetEntity instanceof EntityLiving && j > 0 && !targetEntity.isBurning())
{
flag1 = true;
targetEntity.setFire(1);
}
double d0 = targetEntity.motionX;
double d1 = targetEntity.motionY;
double d2 = targetEntity.motionZ;
boolean flag2 = (this.worldObj.client || Vars.attack) && targetEntity.attackEntityFrom(DamageSource.causeMobDamage(this), f);
if (flag2)
{
if (i > 0)
{
targetEntity.addKnockback((double)(-ExtMath.sin(this.rotYaw * (float)Math.PI / 180.0F) * (float)i * 0.5F), 0.1D, (double)(ExtMath.cos(this.rotYaw * (float)Math.PI / 180.0F) * (float)i * 0.5F));
this.motionX *= 0.6D;
this.motionZ *= 0.6D;
this.setSprinting(false);
}
if (!this.worldObj.client && targetEntity.isPlayer() && targetEntity.veloChanged)
{
((EntityNPC)targetEntity).connection.sendPacket(new SPacketEntityVelocity(targetEntity));
targetEntity.veloChanged = false;
targetEntity.motionX = d0;
targetEntity.motionY = d1;
targetEntity.motionZ = d2;
}
if (flag)
{
this.onCriticalHit(targetEntity);
}
this.setLastAttack(targetEntity);
if (targetEntity instanceof EntityLiving)
{
EnchantmentHelper.applyThornEnchantments((EntityLiving)targetEntity, this);
}
EnchantmentHelper.applyArthropodEnchantments(this, targetEntity);
ItemStack itemstack = this.getHeldItem();
Entity entity = targetEntity;
if (itemstack != null && entity instanceof EntityLiving)
{
itemstack.getItem().hitEntity(itemstack, (EntityLiving)entity, this);
if (itemstack.isEmpty())
{
this.clearHeldItem();
}
}
if (targetEntity instanceof EntityLiving)
{
// this.addStat(StatRegistry.damageDealtStat, f);
if (j > 0)
{
targetEntity.setFire(j * 4);
}
}
}
else if (flag1)
{
targetEntity.extinguish();
}
}
}
}
}
/**
* Will get destroyed next tick.
*/
public void setDead()
{
super.setDead();
if(this.isPlayer()) {
this.inventoryContainer.onContainerClosed(this);
if (this.openContainer != null)
{
this.openContainer.onContainerClosed(this);
}
}
}
/**
* Return null if bed is invalid
*/
public static LocalPos getBedSpawnLocation(World worldIn, LocalPos bedLocation)
{
Block block = worldIn.getState(bedLocation).getBlock();
if (!(block instanceof BlockBed))
{
return null;
}
else
{
return BlockBed.getSafeExitLocation(worldIn, bedLocation, 0);
}
}
public GlobalPos getSpawnPoint()
{
return this.spawnPos;
}
public void setSpawnPoint(GlobalPos pos)
{
this.spawnPos = pos;
}
public GlobalPos getOrigin()
{
return this.originPos;
}
public void setOrigin(GlobalPos pos)
{
this.originPos = pos;
}
// /**
// * Will trigger the specified trigger.
// */
// public void triggerAchievement(StatBase achievementIn)
// {
// this.addStat(1);
// }
// /**
// * Causes this entity to do an upwards motion (jumping).
// */
// public void jump()
// {
// super.jump();
// if(this.isPlayer())
// this.triggerAchievement(StatRegistry.jumpStat);
// }
/**
* Moves the entity based on the specified heading. Args: strafe, forward
*/
public void moveEntityWithHeading(float strafe, float forward)
{
if(!this.isPlayer()) {
super.moveEntityWithHeading(strafe, forward);
return;
}
double d0 = this.posX;
double d1 = this.posY;
double d2 = this.posZ;
if (this.isFlying() && this.vehicle == null)
{
double d3 = this.motionY;
float f = this.jumpMovement;
this.jumpMovement = this.landMovement * (this.canFlyFullSpeed() ? 0.5f : 0.2f) * (this.isSprinting() ? (this.canFlyFullSpeed() ? 2.0f : 1.3f) : 1.0f);
super.moveEntityWithHeading(strafe, forward);
this.motionY = d3 * 0.6D;
this.jumpMovement = f;
}
else
{
super.moveEntityWithHeading(strafe, forward);
}
if(!this.worldObj.client)
this.addMovement(this.posX - d0, this.posY - d1, this.posZ - d2);
}
public float getSpeedBase() {
return this.worldObj.client ? this.dataWatcher.getWatchableObjectFloat(15) : super.getSpeedBase();
}
public void setSpeedBase(float value) {
super.setSpeedBase(value);
this.dataWatcher.updateObject(15, value);
}
/**
* the movespeed used for the new AI system
*/
public float getAIMoveSpeed()
{
return this.isPlayer() ? this.getMovementSpeed() / 3.0f : super.getAIMoveSpeed();
}
public void addMovement(double x, double y, double z)
{
if (this.vehicle == null)
{
if (this.isInsideOfLiquid())
{
int i = Math.round(ExtMath.sqrtd(x * x + y * y + z * z) * 100.0F);
if (i > 0)
{
this.addMoved(i);
}
}
else if (this.isInLiquid())
{
int j = Math.round(ExtMath.sqrtd(x * x + z * z) * 100.0F);
if (j > 0)
{
this.addMoved(j);
}
}
else if (this.isOnLadder())
{
if (y > 0.0D)
{
this.addMoved((int)Math.round(y * 100.0D));
}
}
else if (this.onGround)
{
int k = Math.round(ExtMath.sqrtd(x * x + z * z) * 100.0F);
if (k > 0)
{
this.addMoved(k);
}
}
else
{
int l = Math.round(ExtMath.sqrtd(x * x + z * z) * 100.0F);
if (l > 25)
{
this.addMoved(l);
}
}
}
}
private void addMountedMovement(double x, double y, double z)
{
if (this.vehicle != null)
{
int i = Math.round(ExtMath.sqrtd(x * x + y * y + z * z) * 100.0F);
if (i > 0)
{
this.addMoved(i);
}
}
}
public void fall(float distance, float damageMultiplier)
{
if(!this.isPlayer()) {
super.fall(distance, damageMultiplier);
return;
}
if (!this.noclip && this.worldObj.getGravity(this) != 0.0)
{
if (distance >= 2.0F)
{
this.addMoved((int)Math.round((double)distance * 100.0D));
}
if(!this.hasEffect(Effect.FLYING))
super.fall(distance, damageMultiplier);
}
}
public void makeLandingParticles(LocalPos pos)
{
if (!this.isPlayer() || (!this.noclip && this.worldObj.getGravity(this) != 0.0))
{
super.makeLandingParticles(pos);
}
}
protected void onEnterLiquid()
{
if (!this.isPlayer() || !this.noclip)
{
super.onEnterLiquid();
}
}
// /**
// * This method gets called when the entity kills another one.
// */
// public void onKillEntity(EntityLiving entityLivingIn)
// {
// if(this.isPlayer()) {
// EntityEggInfo entitylist$entityegginfo = (EntityEggInfo)EntityRegistry.SPAWN_EGGS.get(EntityRegistry.getEntityString(entityLivingIn));
//
// if (entitylist$entityegginfo != null)
// {
// this.triggerAchievement(entitylist$entityegginfo.killStat);
// }
// }
// }
/**
* Sets the Entity inside a web block.
*/
public void setInWeb()
{
if (!this.isPlayer() || !this.flying)
{
super.setInWeb();
}
}
public void setExperience(int points) {
this.setXPStats(0.0f, 0, 0);
this.addExperience(points);
}
public void addExperience(int amount)
{
int i = Integer.MAX_VALUE - this.experienceTotal;
if (amount > i)
{
amount = i;
}
this.experience += (float)amount / (float)this.xpBarCap();
for (this.experienceTotal += amount; this.experience >= 1.0F; this.experience /= (float)this.xpBarCap())
{
this.experience = (this.experience - 1.0F) * (float)this.xpBarCap();
this.addExperienceLevel(1);
}
}
public int getEnchSeed()
{
return this.enchSeed;
}
public void setEnchSeed(int seed)
{
this.enchSeed = seed;
}
/**
* This method returns the cap amount of experience that the experience bar can hold. With each level, the
* experience cap on the player's experience bar is raised by 10.
*/
public int xpBarCap()
{
return this.experienceLevel >= 30 ? 112 + (this.experienceLevel - 30) * 9 : (this.experienceLevel >= 15 ? 37 + (this.experienceLevel - 15) * 5 : 7 + this.experienceLevel * 2);
}
/**
* sets the itemInUse when the use item button is clicked. Args: itemstack, int maxItemUseDuration
*/
public void setItemInUse(ItemStack stack, int duration)
{
if (stack != this.itemInUse)
{
this.itemInUse = stack;
this.itemInUseCount = duration;
if (!this.worldObj.client)
{
this.setUsingItem(true);
}
}
}
public boolean canPlayerEdit(LocalPos pos, Facing side, ItemStack stack)
{
return true;
}
/**
* Get the experience points the entity currently has.
*/
protected int getExperiencePoints(EntityNPC player)
{
return this.isPlayer() || this.dummy ? 0 : this.worldObj.rand.range(2, 5);
}
/**
* returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
* prevent them from trampling crops
*/
protected boolean canTriggerWalking()
{
return !this.isPlayer() || !this.flying;
}
/**
* Returns the InventoryWarpChest of this player.
*/
public InventoryWarpChest getWarpChest()
{
return this.warpChest;
}
public void setWarpChest(InventoryWarpChest warpChest)
{
this.warpChest = warpChest;
}
public boolean isPushedByWater()
{
return !this.isPlayer() || !this.flying;
}
public String getName()
{
String text = this.getPrefix();
if(text == null || text.isEmpty()) {
text = this.hasCustomName() ? this.getCustomNameTag() : this.getTypeName();
}
else {
if(this.hasCustomName())
text += " " + this.getCustomNameTag();
}
return this.getAlignment().color + text;
}
public float getEyeHeight()
{
if(!this.isPlayer())
return 1.62F * this.height / 1.8f;
float f = 1.62F * this.height / 1.8f; // this.getHeight(); // / 1.8f;
if (this.isSneakingVisually())
{
f -= 0.08F * this.height / 1.8f; // this.getHeight(); // / 1.8f;
}
return f;
}
public void setAbsorptionAmount(int amount)
{
if(!this.isPlayer()) {
super.setAbsorptionAmount(amount);
}
else {
if (amount < 0)
{
amount = 0;
}
this.getDataWatcher().updateObject(12, Integer.valueOf(amount));
}
}
public int getAbsorptionAmount()
{
return this.isPlayer() ? this.getDataWatcher().getWatchableObjectInt(12) : super.getAbsorptionAmount();
}
public boolean canOpen(String code)
{
ItemStack stack = this.getHeldItem();
return stack != null && stack.getItem() instanceof ItemKey &&
stack.hasDisplayName() && stack.getDisplayName().equals(code);
}
// public boolean isWearing(ModelPart part)
// {
// return this.isPlayer() ? (this.getDataWatcher().getWatchableObjectInt(10) & part.getMask()) == part.getMask()
// : (part != ModelPart.ARMS_SLIM || this.hasSlimSkin());
// }
//
// public int getModelParts()
// {
// return this.getDataWatcher().getWatchableObjectInt(10);
// }
//
// public void setModelParts(int parts)
// {
// this.getDataWatcher().updateObject(10, Integer.valueOf(parts));
// }
public int getTrackingRange() {
return this.isPlayer() ? 512 : 80;
}
public int getUpdateFrequency() {
return this.isPlayer() ? 2 : 3;
}
public boolean isSendingVeloUpdates() {
return !this.isPlayer();
}
public boolean isFlying() {
return this.flying || this.worldObj.getGravity(this) == 0.0;
}
public boolean canNaturallyFly() {
return false;
}
public boolean canFlyFullSpeed() {
return this.hasEffect(Effect.FLYING) && this.getEffect(Effect.FLYING).getAmplifier() > 0;
}
public int getEnergy(Energy type) { // TODO
return 0;
}
public boolean hasEnergyEffect(Energy type) {
return false;
}
public boolean isEnergyDrawn(Energy type) {
return false;
}
// livingbase override
protected void dropFewItems(boolean wasRecentlyHit, int lootingModifier)
{
if(!this.isPlayer()) {
if(!this.dummy)
super.dropFewItems(wasRecentlyHit, lootingModifier);
this.dropEquipment();
}
}
public Object onInitialSpawn(Object livingdata) {
return this.initializeBase(livingdata);
}
protected Object initializeBase(Object livingdata) {
livingdata = super.onInitialSpawn(livingdata);
CharacterInfo info = (livingdata instanceof CharacterTypeData) ? ((CharacterTypeData)livingdata).character :
this.species.pickCharacter(this.worldObj.rand);
AlignmentData align = livingdata instanceof AlignmentData ? ((AlignmentData)livingdata) : null;
this.setStats(info);
if(align != null)
this.setAlignment(align.alignment);
return align != null ? align : new AlignmentData(this.alignment);
}
public void setStats(NpcInfo info) {
this.setNpcClass(info.type == null ? this.pickRandomClass() : info.type);
this.setChar(info.skin != null ? info.skin : this.pickRandomTexture());
this.setCustomNameTag(info.name.isEmpty() ? this.pickRandomName() : info.name);
this.setAlignment(info.align != null ? info.align : this.getNaturalAlign());
this.setHeight(info.height > 0.0f ? info.height : this.getBaseSize());
if(!this.isPlayer()) {
if(info.items != null) {
for(ItemStack stack : info.items) {
if(stack.getItem() instanceof ItemArmor armor) {
for(Equipment slot : armor.getArmorType().getPossibleSlots(this)) {
if(this.getArmor(slot) == null) {
this.setArmor(slot, stack);
break;
}
}
}
else if(stack.getItem().getWieldType() != null) {
this.setHeldItem(stack);
}
else {
this.addStack(stack);
}
}
}
else {
this.clear();
this.setHeldItem(this.pickItem());
for(Equipment slot : Equipment.ARMOR) {
this.setArmor(slot, this.pickArmor(slot));
}
int items = this.pickItemAmount();
ItemStack stack;
for(int z = 0; z < items; z++) {
stack = this.pickLoot(z);
if(stack == null) {
break;
}
this.addStack(stack);
}
}
}
}
public String pickRandomTexture() {
return "";
}
public Enum pickRandomClass() {
return null;
}
public boolean interactFirst(EntityNPC playerIn)
{
return !this.isPlayer() && super.interactFirst(playerIn);
}
public int getMaxFallHeight()
{
return this.isPlayer() ? 3 : super.getMaxFallHeight();
}
protected void updateLeashedState() {
if(!this.isPlayer())
super.updateLeashedState();
}
public void setLeashedTo(Entity entity, boolean pkt) {
if(!this.isPlayer())
super.setLeashedTo(entity, pkt);
}
public boolean allowLeashing() {
return !this.isPlayer();
}
public void clearLeashed(boolean pkt, boolean dropLead) {
if(!this.isPlayer())
super.clearLeashed(pkt, dropLead);
}
protected float updateDistance(float p_110146_1_, float p_110146_2_)
{
if(!this.isPlayer())
return super.updateDistance(p_110146_1_, p_110146_2_);
float f = ExtMath.wrapf(p_110146_1_ - this.yawOffset);
this.yawOffset += f * 0.3F;
float f1 = ExtMath.wrapf(this.rotYaw - this.yawOffset);
boolean flag = f1 < -90.0F || f1 >= 90.0F;
if (f1 < -75.0F)
{
f1 = -75.0F;
}
if (f1 >= 75.0F)
{
f1 = 75.0F;
}
this.yawOffset = this.rotYaw - f1;
if (f1 * f1 > 2500.0F)
{
this.yawOffset += f1 * 0.2F;
}
if (flag)
{
p_110146_2_ *= -1.0F;
}
return p_110146_2_;
}
public boolean getCanSpawnHere() {
return this.isPlayer() || this.dummy || super.getCanSpawnHere();
}
// npc overrides
public void setScaleForAge() {
if(!this.isPlayer())
this.setScale((float)((int)(100.0f * (this.getHeight() / this.getSpeciesBaseSize()) * (this.getGrowingAge() < 0 ? 1.0f +
((float)Math.max(-24000, this.getGrowingAge()) / 24000.0f) * 0.6f : 1.0f))) / 100.0f);
}
protected void dropEquipment()
{
if(this.isPlayer())
return;
ItemStack itemstack1 = this.getHeldItem();
if (itemstack1 != null && !this.dummy)
{
this.entityDropItem(itemstack1, 0.0F);
}
for (int i = 0; i < this.getSizeInventory(); ++i)
{
ItemStack itemstack = this.getStackInSlot(i);
if (itemstack != null)
{
this.entityDropItem(itemstack, 0.0F);
}
}
}
public EntityNPC createChild(EntityLiving ageable)
{
// if(this.isPlayer())
// return null;
EntityNPC template = (ageable instanceof EntityNPC && this.worldObj.rand.chance() ? ((EntityNPC)ageable) : this);
EntityNPC entity;
try {
entity = template.getClass().getConstructor(World.class).newInstance(this.worldObj);
}
catch(InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
entity.onInitialSpawn(new CharacterTypeData(
template.species.pickCharacter(this.worldObj.rand)));
// EntityNPC base = ;
// entity.setSpecies(base.getSpecies());
// entity.setChar(base.getChar());
// entity.setCape(base.getCape());
// entity.setCustomNameTag(base.getCustomNameTag());
// for(int z = 0; z < 5; z++) {
// entity.setCurrentItemOrArmor(z, base.getEquipmentInSlot(z) == null ? null : base.getEquipmentInSlot(z).copy());
// }
// entity.extraInventory.clear();
return entity;
}
public void setCombatTask()
{
if(!this.isPlayer()) {
this.tasks.removeTask(this.aiMelee);
this.tasks.removeTask(this.aiRanged);
ItemStack itemstack = this.getHeldItem();
if (this.isRangedWeapon(itemstack))
{
this.tasks.addTask(3, this.aiRanged);
}
else
{
this.tasks.addTask(3, this.aiMelee);
}
}
}
public abstract int getBaseHealth(Random rand); // {
// return 20;
// }
public abstract Alignment getNaturalAlign(); // {
// return Alignment.NEUTRAL;
// }
public boolean canPlay() {
return !this.isPlayer() && this.getGrowingAge() <= -14000;
}
public final float getBaseSize() {
return this.getEntityBaseSize() + this.getHeightDeviation(this.rand);
}
public int getCurrentSize() {
return (int)(this.getHeight() * 100.0f + 0.5f);
}
public int getDefaultSize() {
return (int)(this.getEntityBaseSize() * 100.0f + 0.5f);
}
public int getMinSize() {
return (int)((this.getEntityBaseSize() + this.getHeightDeviationMin()) * 100.0f + 0.5f);
}
public int getMaxSize() {
return (int)((this.getEntityBaseSize() + this.getHeightDeviationMax()) * 100.0f + 0.5f);
}
public ModelType getModel() {
return this.species.renderer;
// return ModelType.values()[this.dataWatcher.getWatchableObjectByte(11) % ModelType.values().length];
}
//
// public void setModel(ModelType model) {
// this.dataWatcher.updateObject(11, (byte)model.ordinal());
// }
public int getColor() {
return this.isPlayer() ? 0xff00ff : 0x5000ad;
}
public void sendDeathMessage() {
this.sendDeathMessage(this.isPlayer(), true);
}
protected boolean canRegenerateHealth() {
return this.isPlayer() || this.dummy;
}
// END PLAYER
public Item getItem() {
for(int z = 0; z < this.species.chars.length; z++) {
if(this.species.chars[z].dna && this.species.chars[z].skin.equals(this.getChar())) {
return ItemRegistry.byName("dna_sample_" + this.species.chars[z].skin);
}
}
return super.getItem();
}
public boolean isHovering()
{
return false;
}
public void setHovering(boolean hover)
{
}
public float getBaseRadiation() {
return this.getAttribute(Attribute.RADIATION);
}
public float getRadiationResistance() {
return super.getRadiationResistance() + this.getAttribute(Attribute.RADIATION_RESISTANCE);
}
public EntityType getType() {
return EntityType.NPC;
}
public void setGodMode(boolean god) {
this.fallDistance = 0.0F;
if(!god) {
this.removeEffect(Effect.HASTE);
this.removeEffect(Effect.RESISTANCE);
this.removeEffect(Effect.FIRE_RESISTANCE);
this.removeEffect(Effect.FLYING);
this.removeEffect(Effect.MANA_GENERATION);
}
else {
this.extinguish();
this.setHealth(this.getMaxHealth());
this.setManaPoints(this.getMaxMana());
this.clearEffects(false);
this.addEffect(new StatusEffect(Effect.HASTE, Integer.MAX_VALUE, 255));
this.addEffect(new StatusEffect(Effect.RESISTANCE, Integer.MAX_VALUE, 255));
this.addEffect(new StatusEffect(Effect.FIRE_RESISTANCE, Integer.MAX_VALUE, 0));
this.addEffect(new StatusEffect(Effect.FLYING, Integer.MAX_VALUE, 1));
this.addEffect(new StatusEffect(Effect.MANA_GENERATION, Integer.MAX_VALUE, 255));
}
}
public void setNoclip(boolean noclip) {
if(noclip)
this.mountEntity(null);
this.noclip = noclip;
this.flying &= this.hasEffect(Effect.FLYING) || this.noclip || this.canNaturallyFly();
this.fallDistance = 0.0F;
if(this.connection != null)
this.connection.sendPlayerAbilities();
}
// Inventory
public ItemStack decrStackSize(int index, int count)
{
ItemStack[] aitemstack = this.getInventory();
if (index >= Equipment.INVENTORY_SLOTS)
{
aitemstack = this.getArmor();
index -= Equipment.INVENTORY_SLOTS;
}
if (aitemstack[index] != null)
{
if (aitemstack[index].getSize() <= count)
{
ItemStack itemstack1 = aitemstack[index];
aitemstack[index] = null;
return itemstack1;
}
else
{
ItemStack itemstack = aitemstack[index].split(count);
if (aitemstack[index].isEmpty())
{
aitemstack[index] = null;
}
return itemstack;
}
}
else
{
return null;
}
}
public ItemStack removeStackFromSlot(int index)
{
ItemStack[] aitemstack = this.getInventory();
if (index >= Equipment.INVENTORY_SLOTS)
{
aitemstack = this.getArmor();
index -= Equipment.INVENTORY_SLOTS;
}
if (aitemstack[index] != null)
{
ItemStack itemstack = aitemstack[index];
aitemstack[index] = null;
return itemstack;
}
else
{
return null;
}
}
public void setInventorySlotContents(int index, ItemStack stack)
{
ItemStack[] aitemstack = this.getInventory();
if (index >= aitemstack.length)
{
index -= aitemstack.length;
aitemstack = this.getArmor();
}
aitemstack[index] = stack;
}
public int getSizeInventory()
{
return Equipment.INVENTORY_SLOTS + this.getArmor().length;
}
public ItemStack getStackInSlot(int index)
{
ItemStack[] aitemstack = this.getInventory();
if (index >= aitemstack.length)
{
index -= aitemstack.length;
aitemstack = this.getArmor();
}
return aitemstack[index];
}
public boolean isUseableByPlayer(EntityNPC player)
{
return this.dead ? false : player.getDistanceSqToEntity(this) <= 64.0D;
}
public void clear()
{
for (int i = 0; i < Equipment.INVENTORY_SLOTS; ++i)
{
this.getInventory()[i] = null;
}
for(Equipment slot : Equipment.ARMOR) {
this.setArmor(slot, null);
}
}
}