Posted June 23, 201312 yr hello so im making something that requires that i need to detect if the block placed in the slot is the sand block(Block.sand) so this is what i did for a item: //checking if the placed item is "Hydrocroconyzx ingot" only retuns false if there is no item in the slot since no othere item/block is allowed in the slot public boolean CheckInventoryTrader1(ItemStack par1ItemStack) { Item item = par1ItemStack.getItem(); if(par1ItemStack != null && item == EsteticsPLUS.HydrocroconyxIngot){ return true; } else return false; } and then i dont know how to do the same kind of thing, but with the Sand block or any kind of block for that matter
June 23, 201312 yr hello so im making something that requires that i need to detect if the block placed in the slot is the sand block(Block.sand) so this is what i did for a item: //checking if the placed item is "Hydrocroconyzx ingot" only retuns false if there is no item in the slot since no othere item/block is allowed in the slot public boolean CheckInventoryTrader1(ItemStack par1ItemStack) { Item item = par1ItemStack.getItem(); if(par1ItemStack != null && item == EsteticsPLUS.HydrocroconyxIngot){ return true; } else return false; } and then i dont know how to do the same kind of thing, but with the Sand block or any kind of block for that matter first I would suggest a couple of changes to your code. //checking if the placed item is "Hydrocroconyzx ingot" only retuns false if there is no item in the slot since no othere item/block is allowed in the slot public boolean CheckInventoryTrader1(ItemStack par1ItemStack) { if(par1ItemStack != null){ Item item = par1ItemStack.getItem(); if(item.equals(EsteticsPLUS.HydrocroconyxIngot)) return true; else if(item.equals(Block.sand)) return true; else if(item.equals(ITEM_OR_BLOCK_HERE)) return true; } return false; } when you compare things that have Object as a parent, you use .eqauls() to compare them. if they're primitives, then you can use ==. you should also check if the ItemStack is null before getting the item otherwise it can cause crashes. "else return false" is the same as "return false"
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.