Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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!

 

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.