get a item from blocks inventory with nbt tag

Started by FuchsPlayZ on

Topic category: Help with modding (Java Edition)

Last seen on 20:01, 18. Apr 2020
Joined Nov 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
get a item from blocks inventory with nbt tag

Hello sorry for my bad English right away.

so here is my question: how can I make a procedure that if on right-click on a certain block it checks if the block has an item in the inventory of the block and if yes then drops it

and if a player right-clicks with a certain item in its hand, the item (with nbt data) will be transferred to the inventory of the block.

 

so please help me 

Last seen on 14:30, 2. Aug 2022
Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Here's a brief explanation…
Tue, 08/11/2020 - 13:42

Here's a brief explanation of how to do each of those things

1. Make a procedure run when right-clicking a block

Go to the triggers section of your block and set the procedure to run "On block right-clicked."

2. Check if a block has an item in its inventory

I think the best way to do this is to loop through each of the slots of the block and check if the amount of items in that slot is not 0.

3. Drop an item

Use the "spawn gem at (xyz)" block found in the world management tab.

4. Check if the player is right-clicking with a specific item

Check if "item in the main hand of Event/Target entity" (found in entity procedures tab) is equal to the item you want to check for.

5. Transfer the item to the inventory of the block

First, use the "set (item) in slot (0) of block at (xyz)" (block procedures) with (item) as "item in main hand" (entity procedures) to move the item into the inventory of the block (I'm not sure whether or not this also moves the nbt data). Then use the "set item in main hand of (event/target entity) to (1) (item)" to put 0 of anything in the player's main hand.

 

Sorry if this is confusing. Don't hesitate to ask any questions!