5

I'm attempting to build a datapack, and I need to know the block at @e[tag=relevantMob] ~ ~-2 ~ (The block under the block the relevantMob is standing on).

Is there an easy and compact way to get that information?

1 Answer 1

2

I finally figured out a way to do it.

execute as @e[tag=relevantMob] at @s if block ~ ~-2 ~ <blockID> run <function>

  • execute is a function that controls the conditions another function runs under.
  • as @e[tag=relevantMob] causes each relevant mob (and no other entities) to continue running the rest of the execute function.
  • at @s makes every mob running the command calculate the function's relative coordinates from their location.
  • if block ~ ~-2 ~ <blockID> tests the block two blocks below the mob's location. If the block at ~ ~-2 ~ matches <blockID> the command contiues
  • finally, run <function> causes each relevant mob for whom the block below the block they're standing matches the specified block to perform the desiered behavior.
3
  • It's not a clean, easily expandable way of doing it. I would preferred being able to throw it in a predicate. But it works for the purpose I needed it for (a wither apparently doesn't correctly calculate the block its standing on, so I needed another way of knowing what block that was). Commented Mar 14 at 16:08
  • You can try to change the anchored value of the execute command. You can align the command from the feet or eyes of the target. There is also the possibility to use predicates, you can use execute if predicate or build it into your target selector @a[predicate=. Commented Mar 15 at 14:15
  • I'm flumaxed; not in how to call a predicate, but in how to structure the predicate.json to evaluate whether @e[revelantMob] ~ ~-2 ~ is a particular block. I tried both anchored eyes and anchored feet but they didn't help my particular case: it just passed the buck by moving the question from ~ ~-2 ~ to ~ ~-4 ~. if block ~ ~-2 ~ <block> isn't pretty especially chained together, but it functions. Commented Mar 16 at 17:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .