Exchange of items

Started by Demon_Cry on

Topic category: Help with Minecraft modding (Java Edition)

Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Exchange of items

I created a staff, when you right-click it gives me regeneration, and takes the earth. How to make sure that if I don't have land, it doesn't work.

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You are looking for, if …
Sun, 05/31/2020 - 16:54

You are looking for,

if (playerIn.onGround == true)
{
// Do the regeneration thing here
}

To clarify, this only works if you are on the ground. Is that what you want?

Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
If the land is in the…
Sun, 05/31/2020 - 17:01

If the land is in the inventory

Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
If the land is in the…
Sun, 05/31/2020 - 17:01

If the land is in the inventory.

Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
If the land is in the…
Sun, 05/31/2020 - 17:01

If the land is in the inventory

Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
if the land is in the…
Sun, 05/31/2020 - 17:02

if the land is in the inventory

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Like if you have dirt in the…
Sun, 05/31/2020 - 17:29

Like if you have dirt in the inventory?

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ok, so I tested some methods…
Sun, 05/31/2020 - 19:22

Ok, so I tested some methods in MCreator and this is possible without coding. Here is the MCreator method,

Check if Player Has Dirt

Mirror Link

Alternatively, you can add this snippet of code to your item,

    public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn)
    {
        ItemStack itemstack = playerIn.getHeldItem(handIn);
        if (!worldIn.isRemote && playerIn.inventory.hasItemStack(new ItemStack(Blocks.DIRT, 1))) {
            //OPTIONAL BELOW
            playerIn.inventory.clearMatchingItems(p -> new ItemStack(Blocks.DIRT, 1).getItem() == p.getItem(), 1);
            //OPTIONAL^^^ THIS DELETES THE 1 ITEM. YOU CAN CHANGE THE 1 TO WHATEVER AMOUNT YOU DESIRE.
        }
        return ActionResult.resultSuccess(itemstack);
    }

 

Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thank you very much, I have…
Mon, 06/01/2020 - 08:52

Thank you very much, I have been looking for an answer for a long time.

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
No problem 😁
Mon, 06/01/2020 - 13:02

No problem 😁