#right click detection

1 messages · Page 1 of 1 (latest)

woven sierraBOT
#

<@&1201956957406109788>

Someone will come and help soon!

💬 While you wait, take this time to provide more context and details.

🙇 If nobody has answered you by <t:1732733798:t>, feel free to use the Summon Helpers button to ping our helper team.

✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve

#
⚠️ You already have a question open!

Don't forget to close or resolve your old questions once you're done with them. It makes our lives much easier! :D

Open question: #1310302374409277521

rustic perch
#
    "criteria": {
      "using_item": {
        "trigger": "minecraft:using_item",
        "conditions": {
          "item": {
            "items": "golden_hoe",
            "components": {
              "minecraft:custom_data": {
                "tag:smg": {}
              }
            }
          }
        }
      }
    },
    "rewards": {
      "function": "jg:throw"
    }
  }```
#

its supposed to be detecting if a player is using a golden hoe with the tag of smg

crimson depot
#

Pretty sure your custom data is wrong. Show us the components of the actual item?

rustic perch
#

/give @p golden_hoe[custom_data={smg:1}]

#

i did use misode

crimson depot
#

Yeah your custom data in the advancement is not the same as it is here

#

In the advancement, you need custom_data:{"smg":1}

rustic perch
#

ok ill change that

#

this

    "criteria": {
      "using_item": {
        "trigger": "minecraft:using_item",
        "conditions": {
          "item": {
            "items": "golden_hoe",
            "components": {
              "custom_data:{"smg":1}": {
              }
            }
          }
        }
      }
    },
    "rewards": {
      "function": "jg:throw"
    }
  }```
#

now wont let me grant my self the advancement

last talon
#

Did you revoke the advancement in the function?

rustic perch
#

it does in the throw function

#

and i tried to revoke it in game but it just didint show up

last talon
#

Hmmmm

#

There must be something wrong with the syntax then

slim sundial
#

"custom_data:{"smg":1}" should be "custom_data":{"smg":1}

rustic perch
#

wasent paying attention

#

ok

last talon
#

Does it work now? ^^

rustic perch
#

is it possible to do it with interaction entitys

crimson depot
rustic perch
#

but yeah im still having issues with it

crimson depot
#

Such as?

rustic perch
#

just wont trigger

#

ill right click with a golden hoe and not at the ground and it wont trigger the function

crimson depot
#

Does the golden hoe have a food or consumable component?

rustic perch
#

idk

#

i havent done anything with the consumable stuff

crimson depot
#

...did you give it a food or consumable component in the give command?

rustic perch
#

no

crimson depot
#

So that's why

rustic perch
#

how do i do it

safe scarabBOT
#

Rightclick Detection Food

    >>> This is an example, so you'll need to change a few things for your actual datapack:
  • Change stick to the item you want to detect
  • Change namespace to your namespace
  • Change custom_stick to whatever custom data you want
    Note: You can use any item for this, but if it has existing right-click functionality (like placing a block), it will keep that.

This is the command to give you a stick with the custom food component (You can run this in the chat to test it, or put it in a function to trigger when you want):

give @s stick[minecraft:food={nutrition:0, saturation:0, can_always_eat:true, eat_seconds:999999999}, minecraft:custom_data={custom_stick:true}]

click_food.json (located in your pack's advancement folder)

{
  "criteria": {
    "requirement": {
      "trigger": "minecraft:using_item",
      "conditions": {
        "item": {
          "items": [
            "minecraft:stick"
          ],
          "predicates": {
            "minecraft:custom_data": {"custom_stick": true}
          }
        }
      }
    }
  },
  "rewards": {
    "function": "namespace:rightclick_run"
  }
}

rightclick_run.mcfunction (located in your pack's function folder)

# revokes the advancement from the player so it can be used again
advancement revoke @s only namespace:click_food

# announces the use of the item in chat, feel free to replace this with whatever
say I successfully used food component detection!

How it works

We've added a food component to our custom stick item, allowing it to be consumed like food. The player won't actually eat it, since eat_seconds is set to 999999999, so it would take them over 30 years. The food component lets the player try to eat it, which can be detected using an advancement. That advancement runs a function which removes the advancement so it can be triggered again next tick, and runs whatever code you want to the item to trigger.

crimson depot
#

If you're in 1.21.2+, you need to use consumable instead of food, but the same principle applies other than that

rustic perch
#

ok

#

what about the predicate can i remove that and put a tag there instead

crimson depot
#

I don't understand

rustic perch
#

instead of using a predicate

crimson depot
#

Where are you using a predicate?

rustic perch
#
  "criteria": {
    "requirement": {
      "trigger": "minecraft:using_item",
      "conditions": {
        "item": {
          "items": [
            "minecraft:stick"
          ],
          "predicates": {
            "minecraft:custom_data": {"custom_stick": true}
          }
        }
      }
    }
  },
  "rewards": {
    "function": "namespace:rightclick_run"
  }
}```
crimson depot
#

No

#

You do need that

rustic perch
#

ok

crimson depot
#

That's not remotely the problem

#

The problem is that Golden Hoes do not do anything detectable when you right click with them, unless you're looking at a block than can be tilled into farmland

#

So there's nothing for the advancement to be triggered by. You give it the food component so that it can be eaten, and therefore right clicked, allowing the advancement to detect it

rustic perch
crimson depot
#

Ok, then you can follow the tutorial as written

rustic perch
#

ok

rustic perch
#

nvm

#

now it is

woven sierraBOT
#
Question Closed

Your question, #1311397789661528075 (right click detection), was resolved!

Original Message

#1311397789661528075 message

Duration open

1d5h47m

woven sierraBOT
#

Re-opened the channel. Make sure to close it again once you're done.