Skip to content

Commit

Permalink
Fix the extended armor inventory being lost sometimes...
Browse files Browse the repository at this point in the history
And maybe a little cleanup in ArmorExtended...
  • Loading branch information
blue42u committed Apr 30, 2014
1 parent 801a514 commit 07c339c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/main/java/tconstruct/util/player/ArmorExtended.java
Expand Up @@ -148,9 +148,9 @@ public void recalculateHealth (EntityPlayer player, TPlayerStats stats)
if (inventory[4] != null || inventory[5] != null || inventory[6] != null)
{
int bonusHP = 0;
for (int i = 0; i < 3; i++)
for (int i = 4; i < 7; i++)
{
ItemStack stack = inventory[i + 4];
ItemStack stack = inventory[i];
if (stack != null && stack.getItem() instanceof IHealthAccessory)
{
bonusHP += ((IHealthAccessory) stack.getItem()).getHealthBoost(stack);
Expand Down Expand Up @@ -267,7 +267,7 @@ public void readFromNBT (NBTTagCompound tagCompound)
public void dropItems (ArrayList<EntityItem> drops)
{
EntityPlayer player = parent.get();
for (int i = 0; i < 4; ++i)
for (int i = 0; i < this.inventory.length; ++i)
{
if (this.inventory[i] != null)
{
Expand All @@ -290,13 +290,13 @@ public void closeInventory ()

public void writeInventoryToStream (ByteBuf os) throws IOException
{
for (int i = 0; i < 7; i++)
for (int i = 0; i < inventory.length; i++)
ByteBufUtils.writeItemStack(os, inventory[i]);
}

public void readInventoryFromStream (ByteBuf is) throws IOException
{
for (int i = 0; i < 7; i++)
for (int i = 0; i < inventory.length; i++)
inventory[i] = ByteBufUtils.readItemStack(is);
}
}
2 changes: 1 addition & 1 deletion src/main/java/tconstruct/util/player/TPlayerHandler.java
Expand Up @@ -186,7 +186,7 @@ public void onPlayerRespawn (EntityPlayer entityplayer)
TPlayerStats stats = TPlayerStats.get(entityplayer);
if (playerData != null)
{
stats = playerData;
stats.copyFrom(playerData, true);
}

stats.player = new WeakReference<EntityPlayer>(entityplayer);
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/tconstruct/util/player/TPlayerStats.java
Expand Up @@ -70,6 +70,23 @@ public void init (Entity entity, World world)
{
}

public void copyFrom(TPlayerStats stats, boolean copyCalc)
{
this.armor = stats.armor;
this.knapsack = stats.knapsack;
this.beginnerManual = stats.beginnerManual;
this.materialManual = stats.materialManual;
this.smelteryManual = stats.smelteryManual;
this.battlesignBonus = stats.battlesignBonus;

if (copyCalc) {
this.bonusHealth = stats.bonusHealth;
this.bonusHealthClient = stats.bonusHealthClient;
this.hunger = stats.hunger;
this.level = stats.level;
}
}

public static final void register (EntityPlayer player)
{
player.registerExtendedProperties(TPlayerStats.PROP_NAME, new TPlayerStats(player));
Expand Down

0 comments on commit 07c339c

Please sign in to comment.