Content: Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
Background: Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
Pattern: Blank Waves Notes Sharp Wood Rockface Leather Honey Vertical Triangles
Welcome to TerraFirmaCraft Forums

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

  • Announcements

    • Dries007

      ATTENTION Forum Database Breach   03/04/2019

      There has been a breach of our database. Please make sure you change your password (use a password manager, like Lastpass).
      If you used this password anywhere else, change that too! The passwords themselves are stored hashed, but may old accounts still had old, insecure (by today's standards) hashes from back when they where created. This means they can be "cracked" more easily. Other leaked information includes: email, IP, account name.
      I'm trying my best to find out more and keep everyone up to date. Discord (http://invite.gg/TerraFirmaCraft) is the best option for up to date news and questions. I'm sorry for this, but the damage has been done. All I can do is try to make sure it doesn't happen again.
    • Claycorp

      This forum is now READ ONLY!   01/20/2020

      As of this post and forever into the future this forum has been put into READ ONLY MODE. There will be no new posts! A replacement is coming SoonTM . If you wish to stay up-to-date on whats going on or post your content. Please use the Discord or Sub-Reddit until the new forums are running.

      Any questions or comments can be directed to Claycorp on either platform.
Sign in to follow this  
Followers 0
Majca

InventoryPlayerTFC sync between client / server

1 post in this topic

Hi,

 

I'm playing a bit with tfc source code.

I've added an Integer member to the InventoryPlayerTFC class in order to dynamically disable x slots in my hotbar, that x being increased every time a mob hits me.

 

The thing is that I cannot find the way to sync that value between the client and the server.

 

Could you please help me? (code below)

 

Thx,

 

Majca 

package com.bioxx.tfc.Core.Player;import net.minecraft.entity.player.EntityPlayer;import net.minecraft.entity.player.InventoryPlayer;import net.minecraft.item.Item;import net.minecraft.item.ItemArmor;import net.minecraft.item.ItemStack;import net.minecraft.nbt.NBTTagCompound;import net.minecraft.nbt.NBTTagList;import java.util.ArrayList;import java.util.Collections;import java.util.List;import com.bioxx.tfc.Core.TFC_Core;public class InventoryPlayerTFC extends InventoryPlayer {	public int unavailableSlotCount = 0;		public ItemStack[] extraEquipInventory = new ItemStack[TFC_Core.getExtraEquipInventorySize()];	public InventoryPlayerTFC(EntityPlayer par1EntityPlayer) {		super(par1EntityPlayer);		this.player = par1EntityPlayer;	}	@Override	public void damageArmor(float par1)	{		par1 /= 4.0F;		if (par1 < 1.0F)			par1 = 1.0F;		for (int i = 0; i < this.armorInventory.length; ++i)		{			if (this.armorInventory[i] != null && this.armorInventory[i].getItem() instanceof ItemArmor)			{				this.armorInventory[i].damageItem((int) par1, this.player);				if (this.armorInventory[i].stackSize == 0)					this.armorInventory[i] = null;			}		}	}	@Override	public int getSizeInventory()	{		return this.mainInventory.length + armorInventory.length + this.extraEquipInventory.length;	}	@Override	public void readFromNBT(NBTTagList par1NBTTagList)	{		super.readFromNBT(par1NBTTagList);		this.extraEquipInventory = new ItemStack[TFC_Core.getExtraEquipInventorySize()];		NBTTagList extraList = player.getEntityData().getTagList("ExtraInventory", 10);		for (int i = 0; i < extraList.tagCount(); ++i)		{			NBTTagCompound nbttagcompound = extraList.getCompoundTagAt(i);			ItemStack itemstack = ItemStack.loadItemStackFromNBT(nbttagcompound);			if (itemstack != null)			{				extraEquipInventory[i] = itemstack;			}		}				unavailableSlotCount = player.getEntityData().getInteger("unavailableSlotCount");	}	@Override	/**	 * Returns the stack in slot i	 */	public ItemStack getStackInSlot(int par1)	{		ItemStack[] aitemstack = this.mainInventory;		if (par1 >= this.mainInventory.length + this.extraEquipInventory.length)		{			par1 -= this.mainInventory.length + this.extraEquipInventory.length;			aitemstack = this.armorInventory;		}		else if(par1 >= this.mainInventory.length){			par1-= aitemstack.length;			aitemstack = this.extraEquipInventory;		}		return aitemstack[par1];	}	@Override	public ItemStack getStackInSlotOnClosing(int par1)	{		ItemStack[] aitemstack = this.mainInventory;		if (par1 >= this.mainInventory.length + this.extraEquipInventory.length)		{			aitemstack = this.armorInventory;			par1 -= this.mainInventory.length + this.extraEquipInventory.length;		}		else if(par1 >= this.mainInventory.length){			par1-= aitemstack.length;			aitemstack = this.extraEquipInventory;		}		if (aitemstack[par1] != null)		{			ItemStack itemstack = aitemstack[par1];			aitemstack[par1] = null;			return itemstack;		}		else		{			return null;		}	}	@Override	public int clearInventory(Item item, int meta)	{		for(int i = 0; i < this.extraEquipInventory.length; i++)		{			if (extraEquipInventory[i] != null && (item == null || extraEquipInventory[i].getItem() == item) && 					(meta <= -1 || extraEquipInventory[i].getItemDamage() == meta))			{				this.extraEquipInventory[i] = null;			}		}		return super.clearInventory(item, meta);	}	@Override	public void decrementAnimations()	{		for (int i = 0; i < this.extraEquipInventory.length; ++i)		{			if (this.extraEquipInventory[i] != null)			{				this.extraEquipInventory[i].updateAnimation(this.player.worldObj, this.player, i, this.currentItem == i);			}		}		super.decrementAnimations();	}	@Override	public ItemStack decrStackSize(int par1, int par2)	{		ItemStack[] aitemstack = this.mainInventory;		if (par1 >= this.mainInventory.length + this.extraEquipInventory.length)		{			aitemstack = this.armorInventory;			par1 -= this.mainInventory.length + this.extraEquipInventory.length;		}		else if(par1 >= this.mainInventory.length){			par1-= aitemstack.length;			aitemstack = this.extraEquipInventory;		}		if (aitemstack[par1] != null)		{			ItemStack itemstack;			if (aitemstack[par1].stackSize <= par2)			{				itemstack = aitemstack[par1];				aitemstack[par1] = null;				return itemstack;			}			else			{				itemstack = aitemstack[par1].splitStack(par2);				if (aitemstack[par1].stackSize == 0)				{					aitemstack[par1] = null;				}				return itemstack;			}		}		else		{			return null;		}	}	@Override	public void dropAllItems()	{		int i;		for (i = 0; i < this.extraEquipInventory.length; ++i)		{			if (this.extraEquipInventory[i] != null)			{				this.player.func_146097_a(this.extraEquipInventory[i], true, false);				this.extraEquipInventory[i] = null;			}		}				int damageInventoryInpact = 5;		for (i = 0; i < damageInventoryInpact; ++i)        {            if (this.mainInventory[i] != null )            {            	 this.mainInventory[i] = null;            }        }				super.dropAllItems();	}	@Override	public boolean hasItemStack(ItemStack par1ItemStack)	{		int i;		for (i = 0; i < this.extraEquipInventory.length; ++i)		{			if (this.extraEquipInventory[i] != null && this.extraEquipInventory[i].isItemEqual(par1ItemStack))			{				return true;			}		}		return super.hasItemStack(par1ItemStack);	}	@Override	public void setInventorySlotContents(int par1, ItemStack par2ItemStack)	{		ItemStack[] aitemstack = this.mainInventory;		if (par1 >= this.mainInventory.length + this.extraEquipInventory.length)		{			par1 -= this.mainInventory.length + this.extraEquipInventory.length;			aitemstack = this.armorInventory;		}		else if(par1 >= this.mainInventory.length){			par1-= aitemstack.length;			aitemstack = this.extraEquipInventory;		}		aitemstack[par1] = par2ItemStack;	}	/*	 * This method is currently never being called properly.	 * The copying of the extraEquipment is being handled with 	 * com.bioxx.tfc.Core.Player.PlayerInfo.tempEquipment	 * com.bioxx.tfc.Core.Player.PlayerTracker.onPlayerRespawn(PlayerRespawnEvent)	 * and com.bioxx.tfc.Handlers.EntityLivingHandler.onEntityDeath(LivingDeathEvent)	 */	@Override	public void copyInventory(InventoryPlayer par1InventoryPlayer)	{		if(par1InventoryPlayer instanceof InventoryPlayerTFC){			this.copyInventoryTFC((InventoryPlayerTFC)par1InventoryPlayer);		}		else{			super.copyInventory(par1InventoryPlayer);		}	}			public int getUnavailableSlotsCount()	{		return unavailableSlotCount;	}			public void removeUnavailableSlots(int slotCount)	{		unavailableSlotCount -= slotCount;		if(unavailableSlotCount < 0)		{			unavailableSlotCount = 0;		}	}	    public void addUnavailableSlots(int slotCount)    {    	if(slotCount > 9 - unavailableSlotCount)    	{    		slotCount = 9 - unavailableSlotCount;    	}    	    	List<Integer> dataList = new ArrayList<Integer>();        for (int i = unavailableSlotCount; i < 9; ++i) {        	dataList.add(i);        }        Collections.shuffle(dataList);                for (int i = 0; i < unavailableSlotCount; ++i)        {        	if (this.mainInventory[i] != null)            {                this.player.func_146097_a(this.mainInventory[i], true, false);                this.mainInventory[i] = null;            }        }                for (int i = 0; i < slotCount; ++i)        {        	int slotIdx = dataList.get(i);            if (this.mainInventory[slotIdx] != null)            {                this.player.func_146097_a(this.mainInventory[slotIdx], true, false);                this.mainInventory[slotIdx] = null;            }        }                unavailableSlotCount += slotCount;                for (int i = 0; i < unavailableSlotCount; ++i)        {        	if (this.mainInventory[i] != null)        	{        		int slotIdx = getFirstEmptyStack();        		if(slotIdx >= 0)        		{        			setInventorySlotContents(slotIdx, this.mainInventory[i]);        			this.mainInventory[i] = null;        		}        	}        }    }	public void copyInventoryTFC(InventoryPlayerTFC par1InventoryPlayer)	{		this.unavailableSlotCount = par1InventoryPlayer.unavailableSlotCount;				int i;		for (i = 0; i < this.extraEquipInventory.length; ++i)		{			this.extraEquipInventory[i] = ItemStack.copyItemStack(par1InventoryPlayer.extraEquipInventory[i]);		}		super.copyInventory(par1InventoryPlayer);	}	@Override	public NBTTagList writeToNBT(NBTTagList par1NBTTagList)	{		super.writeToNBT(par1NBTTagList);		int i;		NBTTagCompound nbt;		NBTTagList tagList = new NBTTagList();		for (i = 0; i < extraEquipInventory.length; i++)		{			ItemStack is = extraEquipInventory[i];			if (is != null)			{				nbt = new NBTTagCompound();				nbt.setByte("Slot", (byte) i);				is.writeToNBT(nbt);				tagList.appendTag(nbt);			}		}				player.getEntityData().setTag("ExtraInventory", tagList);		player.getEntityData().setInteger("unavailableSlotCount", unavailableSlotCount);				return par1NBTTagList;	}}
Edited by Majca
0

Share this post


Link to post
Share on other sites
Sign in to follow this  
Followers 0