Jump to content

[1.5.1]GUI: detecting certain blocks(SOLVED)


rasmustof

Recommended Posts

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

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

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.