Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.10] Weird sync problems with players inventory


Elix_x
 Share

Recommended Posts

Hi there, i have a problem:

I have a method, where i'm removing items form players inventory. Decreasing it's stack size works completely, but setting it to null because of size being 0, for some reasons desyncs client and server: On server they don't exists, on client they do... Running this code on both size (removing !isRemote), doesn't change anything... Making inventory as dirty does not produce effect neither...

Here's full method, consuming is on buttom:

public static boolean hasConsumeDyes(EntityPlayer player) {
	if(!player.worldObj.isRemote){
		boolean red = false;
		boolean green = false;
		boolean blue = false;
		boolean water = false;

		int rs = 0;
		int gs = 0;
		int bs = 0;

		for(int i = 0; i < player.inventory.mainInventory.length; i++){
			ItemStack itemstack = player.inventory.mainInventory[i];
			if(itemstack != null){
				for(int id : OreDictionary.getOreIDs(itemstack)){
					if(!red && OreDictionary.getOreName(id).equals("dyeRed")){
						red = true;
						rs = i;
					}
					if(!green && OreDictionary.getOreName(id).equals("dyeGreen")){
						green = true;
						gs = i;
					}
					if(!blue && OreDictionary.getOreName(id).equals("dyeBlue")){
						blue = true;
						bs = i;
					}
				}
				if(itemstack.getItem() == Items.water_bucket){
					water = true;
				}
			}
		}

		if(red && green && blue && water){
			{
				ItemStack itemstack = player.inventory.getStackInSlot(rs);
				itemstack.stackSize -= 1;
				if(itemstack.stackSize == 0){
					itemstack = null;
				}
				player.inventory.setInventorySlotContents(rs, itemstack);
			}

			{
				ItemStack itemstack = player.inventory.getStackInSlot(gs);
				itemstack.stackSize -= 1;
				if(itemstack.stackSize == 0){
					itemstack = null;
				}
				player.inventory.setInventorySlotContents(gs, itemstack);
			}

			{
				ItemStack itemstack = player.inventory.getStackInSlot(bs);
				itemstack.stackSize -= 1;
				if(itemstack.stackSize == 0){
					itemstack = null;
				}
				player.inventory.setInventorySlotContents(bs, itemstack);
			}

		}

		return red && green && blue && water;
	}
	return false;
}

Any ideas?

 

EDIT: oh, and also, this issue disspears after relogging in (logical... :) )...

 

Thanks for help!

If you have any questions - just ask!

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.