Jump to content

Recommended Posts

Posted

hi am am trying to make a new furnace style thingy 

 

but i only want certain item into certain slots  i hav being trying this

 

@Override

public boolean isItemValid(ItemStack par1ItemStack, int Slot)

{

switch(Slot)

{

case 0: if(par1ItemStack.getItem() instanceof Item)

return true;

}

return false;

}

 

But the problem is one it doesnt work and 2 that will let any item in

 

i want it to only let blazerod in to the slot but if i do this

 

case 0: if(par1ItemStack.getItem() instanceof Item.blazeRod)

 

it errors out and says that it cant be done

 

plz help

 

 

Posted

Override slotClicked and return null(maybe just return? can't remember) if that item shouldn't be placed in the slot number passed in, otherwise, call the super.

 

You can get the itemstack that is currently stuck to the players mouse by doing a player.inventory.getItemStack()

 

Edit: Return the ItemStack, not null. Returning Null will delete the item in their hand.

Posted

Not be rude, by I really think that If you don't have at least a decent understanding in java you shouldn't be doing forge modding.

 

The reason:

 

case 0: if(par1ItemStack.getItem() instanceof Item.blazeRod)

 

does not work is because instanceof is used to check if an Item is of the class type. Item.blazeRod isn't a class type but rather an instance of a class. To get it to work I would do

 

case 0: if(par1ItemStack.getItem().shiftedIndex == Item.blazeRod.shiftedIndex){

//code in here

}

 

 

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.