Posted April 21, 201411 yr Hi there, I'm trying to make a machine which has 3 slots - 2 inputs and an output. One of the inputs is for anything, and the other is for cobblestone only. What I want is that when you place cobblestone into the bottom slot, it increases a variable and in turn increases a meter on the screen. How can I check for cobblestone in the slot? I have tried public void updateEntity() { if(this.getStackInSlot(2).equals(Blocks.cobblestone)); { System.out.println("I am awesome!"); } } with no luck. When I attempt to load a world I get a null pointer exception. P.S I know this is a bit off topic, but will help other issues I'm having with the GUI. How can I only let stone be placed in the slot, and how can I only allow items to be taken from the output slot and not placed? I have no idea what I'm doing.
April 21, 201411 yr If there is no stack in slot 2, you're going to get that NPE. Try testing for a 'null' before using .equals() -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
April 21, 201411 yr Firstly, you should always check if the stack in the slot is null before doing anything with it, or you will get a null pointer exception. Secondly, an ItemStack will never return true when comparing it to a Block with equals; instead, you need to get the Item and compare that to the ItemBlock: ItemStack stack = getStackInSlot(2); // or whatever slot if (stack != null && stack.getItem() == Item.getItemFromBlock(Blocks.cobblestone)) { // now you know for sure you've got a stack with cobblestone } Finally, you should look at the Slot class for methods you can use to limit what goes into a slot; you will need to make your own class that extends Slot and add that instead of the generic Slot to your container. http://i.imgur.com/NdrFdld.png[/img]
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.