How do I make a block clone what's in my right hand?

Started by HariBanGa on

Topic category: Advanced modding

Joined Dec 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How do I make a block clone what's in my right hand?

Basically, what I want to do is have a block where you simply right-click on the block, and the block gives you the item that you already have in your right hand (for example, if you held a diamond and you right-clicked the Cloning Block, the Block would drop a diamond, so now you would have two diamonds in your hand).  However, I don't know what to write in the code section, as it is not a default option.

Here is the code:

if (entity.inventory.getCurrentItem() != null && entity.inventory.getCurrentItem().getItem() == whatdoIwritehere) {
                if (entity instanceof EntityPlayer)
                    ((EntityPlayer) entity).inventory.addItemStackToInventory(new ItemStack(whatdoIwritehere, 1));

I've tried using itemInPlayersHand[] but it doesn't work. Please help.

Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Just remove the 2nd check…
Fri, 12/29/2017 - 18:04

Just remove the 2nd check and as a parameter in addItemStackToInventory use the ItemStack from getCurrentItem()  (and it would be a good idea to call ItemStack#copy()), so you will end up with something like this:

 

if (entity instanceof EntityPlayer)
{
                if (entity.inventory.getCurrentItem() != null)
				{
                    ((EntityPlayer) entity).inventory.addItemStackToInventory(entity.inventory.getCurrentItem().copy());
				}
}

 

Joined Dec 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thanks very much! It's…
Sat, 12/30/2017 - 16:46

Thanks very much! It's working great.