Moritz Posted April 11, 2013 Posted April 11, 2013 next problem . 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; } } } Quote
Moritz Posted April 11, 2013 Author Posted April 11, 2013 solved. Only my redstone is buggy but then ill finish my mod Quote
Torojima Posted April 11, 2013 Posted April 11, 2013 for the sake of ppl reading this later while searching for a solution for their problems, you should post your found solution, not only a "solved" statement... Quote running minecraft on Mac OS X - Sierra --- creating code since 1986 ... --- मेरा दिल भारतवासी है! http://www.arno-saxena.de/pictures/chococraft/banner_signature.png[/img]
Moritz Posted April 11, 2013 Author Posted April 11, 2013 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; } } Quote
Torojima Posted April 11, 2013 Posted April 11, 2013 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]; } } Quote running minecraft on Mac OS X - Sierra --- creating code since 1986 ... --- मेरा दिल भारतवासी है! http://www.arno-saxena.de/pictures/chococraft/banner_signature.png[/img]
Torojima Posted April 11, 2013 Posted April 11, 2013 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 ... Quote running minecraft on Mac OS X - Sierra --- creating code since 1986 ... --- मेरा दिल भारतवासी है! http://www.arno-saxena.de/pictures/chococraft/banner_signature.png[/img]
Moritz Posted April 11, 2013 Author Posted April 11, 2013 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. Quote
Torojima Posted April 12, 2013 Posted April 12, 2013 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 Quote running minecraft on Mac OS X - Sierra --- creating code since 1986 ... --- मेरा दिल भारतवासी है! http://www.arno-saxena.de/pictures/chococraft/banner_signature.png[/img]
Moritz Posted April 12, 2013 Author Posted April 12, 2013 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. Quote
Recommended Posts
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.