Block that detects the player's proximity and object?

Started by rextir on

Topic category: Help with modding (Java Edition)

Last seen on 23:57, 3. May 2024
Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Block that detects the player's proximity and object?

How can I make a block detect (via server ticks) when a player approaches it with a specific item in hand?

 

Last seen on 18:36, 3. May 2024
Joined Dec 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Here's a simple way to do it…
Sun, 04/21/2024 - 18:56

Here's a simple way to do it : 

 

Add a "when tick updates" trigger to the block, then in World procedures, go to "for each entity at x y z in a ___ blocks radius as entity iterator 

(you can set the radius so that it only  gets triggered when the entity is near)

then add an "if" "then" condition,

add the logic data is "Is target entity entity subtype of _______"

Replace Target entity by Entity iterator and chooze Player as entity type,

couple that condition with another condition using an "AND"

(which you can get by clicking on the " = " on the logic comparator   [   ] = [   ] if you know what i'm talking about)

that condition will be : [Item in main hand of "Event:Target entity"] = [Whatever Item you wanna put]

Don't forget to change the "Event:Target entity" to Entity Iterator


Then you're good to go

However, this doesn't allow to count how near the player is, or to trigger it only if he is in a certain area around the block, like on top of it or under it. It will trigger if he is in the radius you set. Take into account that it is a box shaped detection zone. You cannot do a round one (or can you? idk if it's possible)

Also, be very careful with what you put after that because the fact that it triggers on each tick can cause DIRE lag.

Do not forget to go in "Advanced settings" for the block then setting the tick rate. I recommand you not to put something too low. Do like 10 ticks so it triggers two times a seconds.