Jump to content

Recommended Posts

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;
    		}
    	}
    }

Posted

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;
	}

}

Posted

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]

Posted

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

Posted

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]

Posted

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...

×   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.

Announcements



×
×
  • Create New...

Important Information

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