@Override public void markDirty() { EntityPlayer player = parent.get(); TPlayerStats stats = TPlayerStats.get(player); // recalculateSkills(player, stats); recalculateHealth(player, stats); /* * if (inventory[2] == null && stats.knapsack != null) { * stats.knapsack.unequipItems(); } */ }
public void recalculateHealth(EntityPlayer player, TPlayerStats stats) { Side side = FMLCommonHandler.instance().getEffectiveSide(); if (inventory[4] != null || inventory[5] != null || inventory[6] != null) { int bonusHP = 0; for (int i = 4; i < 7; i++) { ItemStack stack = inventory[i]; if (stack != null && stack.getItem() instanceof IHealthAccessory) { bonusHP += ((IHealthAccessory) stack.getItem()).getHealthBoost(stack); } } int prevHealth = stats.bonusHealth; stats.bonusHealth = bonusHP; int healthChange = bonusHP - prevHealth; if (healthChange != 0) { IAttributeInstance attributeinstance = player.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.maxHealth); try { attributeinstance.removeModifier(attributeinstance.getModifier(globalID)); } catch (Exception e) { } attributeinstance.applyModifier( new AttributeModifier(globalID, "tconstruct.heartCanister", bonusHP, 0)); } } else if (parent != null && parent.get() != null) { int prevHealth = stats.bonusHealth; int bonusHP = 0; stats.bonusHealth = bonusHP; int healthChange = bonusHP - prevHealth; if (healthChange != 0) { IAttributeInstance attributeinstance = player.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.maxHealth); try { attributeinstance.removeModifier(attributeinstance.getModifier(globalID)); } catch (Exception e) { } } } }
@Override public void setInventorySlotContents(int slot, ItemStack itemstack) { inventory[slot] = itemstack; // TConstruct.logger.info("Changed slot " + slot + " on side " + // FMLCommonHandler.instance().getEffectiveSide()); if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) { itemstack.stackSize = getInventoryStackLimit(); } EntityPlayer player = parent.get(); TPlayerStats stats = TPlayerStats.get(player); recalculateHealth(player, stats); }
@Override public ItemStack decrStackSize(int slot, int quantity) { if (inventory[slot] != null) { // TConstruct.logger.info("Took something from slot " + slot); if (inventory[slot].stackSize <= quantity) { ItemStack stack = inventory[slot]; inventory[slot] = null; return stack; } ItemStack split = inventory[slot].splitStack(quantity); if (inventory[slot].stackSize == 0) { inventory[slot] = null; } EntityPlayer player = parent.get(); TPlayerStats stats = TPlayerStats.get(player); recalculateHealth(player, stats); return split; } else { return null; } }