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

xD next problem xD.

 

I am using for loops to check the inventory (if it is full)

but it only checks the last slot so what is the problem?

 

code:

 

    @Override
    public void updateEntity()
    {
    	for(int i = 0; i < getSizeInventory(); i++)
    	{
    		if (getStackInSlot(i) == null || getStackInSlot(i).stackSize < Math.min(getInventoryStackLimit(), getStackInSlot(i).getMaxStackSize()))
    		{
    			isFull = false;
    		}
    		else
    		{
    			isFull = true;
    		}
    		
    		if (getStackInSlot(i) != null)
    		{
    			isEmpty = false;
    		}
    		else
    		{
    			isEmpty = true;
    		}
    	}
    }

  • Author

ok.

 

Sloved.

 

To detect if the chest is full or empty here the code:

 



private ItemStack[] yourstack;
private int inventorysize;
private boolean isFull = false;
private boolean isEmpty = true;
private boolean chestfulldetect[] = new boolean[9];
private boolean chestemptydetect[] = new boolean[9];

public TileTestChest(int i)
{
    yourstack = new ItemStack[i];
    inventorysize = i;
}

public void updateEntity()
{
	for(int i = 0; i < getSizeInventory(); i++)
	{
		if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == Math.min(getInventoryStackLimit(), getStackInSlot(i).getMaxStackSize())) 
		{
			this.chestfulldetect[i] = true;	
		}
		else chestfulldetect[i] = false;

		if(getStackInSlot(i) == null)
		{
			chestemptydetect[i] = true;
		}
		else
		{
			chestemptydetect[i] = false;
		}
	}

	if(inventorysize == 1)
	{
		if(chestfulldetect[0] == true)isFull = true;
		else isFull = false;
		if(chestemptydetect[0] == true)isEmpty = true;
		else isEmpty = false;
	}
	else if(inventorysize == 2)
	{
		if(chestfulldetect[0] == true && chestfulldetect[1] == true)isFull = true;
		else isFull = false;
		if(chestemptydetect[0] == true && chestemptydetect[1] == true)isEmpty = true;
		else isEmpty = false;
	}
	else if(inventorysize == 3)
	{
		if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true)isFull = true;
		else isFull = false;
		if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true)isEmpty = true;
		else isEmpty = false;
	}
	else if(inventorysize == 4)
	{
		if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true && chestfulldetect[3] == true)isFull = true;
		else isFull = false;
		if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true && chestemptydetect[3] == true)isEmpty = true;
		else isEmpty = false;
	}
	else if(inventorysize == 5)
	{
		if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true && chestfulldetect[3] == true && chestfulldetect[4] == true)isFull = true;
		else isFull = false;
		if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true && chestemptydetect[3] == true && chestemptydetect[4] == true)isEmpty = true;
		else isEmpty = false;
	}
	else if(inventorysize == 6)
	{
		if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true && chestfulldetect[3] == true && chestfulldetect[4] == true && chestfulldetect[5] == true)isFull = true;
		else isFull = false;
		if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true && chestemptydetect[3] == true && chestemptydetect[4] == true && chestemptydetect[5] == true)isEmpty = true;
		else isEmpty = false;
	}
	else if(inventorysize == 7)
	{
		if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true && chestfulldetect[3] == true && chestfulldetect[4] == true && chestfulldetect[5] == true && chestfulldetect[6] == true)isFull = true;
		else isFull = false;
		if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true && chestemptydetect[3] == true && chestemptydetect[4] == true && chestemptydetect[5] == true && chestemptydetect[6] == true)isEmpty = true;
		else isEmpty = false;
	}
	else if(inventorysize == 
	{
		if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true && chestfulldetect[3] == true && chestfulldetect[4] == true && chestfulldetect[5] == true && chestfulldetect[6] == true && chestfulldetect[7] == true)isFull = true;
		else isFull = false;
		if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true && chestemptydetect[3] == true && chestemptydetect[4] == true && chestemptydetect[5] == true && chestemptydetect[6] == true && chestemptydetect[7] == true)isEmpty = true;
		else isEmpty = false;
	}
	else if(inventorysize == 9)
	{
		if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true && chestfulldetect[3] == true && chestfulldetect[4] == true && chestfulldetect[5] == true && chestfulldetect[6] == true && chestfulldetect[7] == true && chestfulldetect[8] == true)isFull = true;
		else isFull = false;
		if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true && chestemptydetect[3] == true && chestemptydetect[4] == true && chestemptydetect[5] == true && chestemptydetect[6] == true && chestemptydetect[7] == true && chestemptydetect[8] == true)isEmpty = true;
		else isEmpty = false;
	}

}

may I propose this:

 

private boolean isFull = false;
private boolean isEmpty = true;
private boolean chestfulldetect[] = new boolean[9];
private boolean chestemptydetect[] = new boolean[9];

public TileTestChest(int i)
{
    yourstack = new ItemStack[i];
    inventorysize = i;
}

public void updateEntity()
{
for(int i = 0; i < getSizeInventory(); i++)
{
	if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == Math.min(getInventoryStackLimit(), getStackInSlot(i).getMaxStackSize())) 
	{
		this.chestfulldetect[i] = true;	
	}
	else
	{
		chestfulldetect[i] = false;
	}

	if(getStackInSlot(i) == null)
	{
		chestemptydetect[i] = true;
	}
	else
	{
		chestemptydetect[i] = false;
	}
}

this.isFull = true;
this.isEmpty = true;
for(int i = 0; i < inventorysize; i++)
{
	this.isFull &= this.chestfulldetect[i];
	this.isEmpty &= this.chestemptydetect[i];
}
}

running minecraft on Mac OS X - Sierra --- creating code since 1986 ... --- मेरा दिल भारतवासी है!

width=289 height=100http://www.arno-saxena.de/pictures/chococraft/banner_signature.png[/img]

and if you do not need the individual entries in chestfulldetect and chestemptydetect at a later time, I would skip them altogether and only use the isFull and isEmpty bools ...

running minecraft on Mac OS X - Sierra --- creating code since 1986 ... --- मेरा दिल भारतवासी है!

width=289 height=100http://www.arno-saxena.de/pictures/chococraft/banner_signature.png[/img]

  • Author

Sorry but your way is wrong! I made some kinda thing like this and it always detect the last slot! and every other slot will not detected!

 

I do not talking this because i think i am better than you. I say that because i got the result out of it!

And you know much more than me. xD

with the a &= list_of_b and starting a as true, a will finally be true only if every entry in list_of_b is true and false if any one in list_of_b is false. You notice the

  &=

not just

=

 

a &= b will set a to true if a *and* b are true and false if a *or* b are false. The code provided by me will do exactly the same as your code, plus it will do so for any inventory size. And it's a lot better to read. But your mod, your code, your call :)

running minecraft on Mac OS X - Sierra --- creating code since 1986 ... --- मेरा दिल भारतवासी है!

width=289 height=100http://www.arno-saxena.de/pictures/chococraft/banner_signature.png[/img]

  • Author

Ok. But for learning is my way good enough. And bevor i change something i let it like this!

 

Can you explain me why my redstone signal does not work korrectly?

 

Because i only want that it powers a block above it. but now its powering the block above it + 1. why does he doing that?

 

Thread is: Redstone is buggy!

 

I made pictures of that. Than you will see what i mean.

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.