Exchange of items

Started by Demon_Cry on Sun, 05/31/2020 - 08:48

Topic category: Help with modding (Java Edition)

Last seen on 14:03, 4. Dec 2020
Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Exchange of items
Sun, 05/31/2020 - 08:48

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.

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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?

Last seen on 14:03, 4. Dec 2020
Joined Aug 2019
Points:

User statistics:

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

If the land is in the inventory

Last seen on 14:03, 4. Dec 2020
Joined Aug 2019
Points:

User statistics:

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

If the land is in the inventory.

Last seen on 14:03, 4. Dec 2020
Joined Aug 2019
Points:

User statistics:

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

If the land is in the inventory

Last seen on 14:03, 4. Dec 2020
Joined Aug 2019
Points:

User statistics:

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

if the land is in the inventory

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

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

Like if you have dirt in the inventory?

Last seen on 14:03, 4. Dec 2020
Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Yes  
Sun, 05/31/2020 - 18:53

Yes

 

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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);
    }

 

Last seen on 14:03, 4. Dec 2020
Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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.

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

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

No problem 😁