Minecraft datapack check if in block (portal)

300 Views Asked by At

So this is 100% a minecraft data pack thing... (programming languages are not similar at all) I have a function to detect if I am in a portal

execute at @a if block ~ ~ ~ blue_stained_glass_pane run say inPortal

Which looks like enter image description here

So I was wondering if it would be possible to somehow either change this function into a predicate

Or if there is a way to change this into a seperate function and write

execute as @a if function???:inportal run...

A comment on any other ways to detect if they are in the portal would be cool too.

2

There are 2 best solutions below

0
RoyalQuack On

Setting into a predicate is not very practical and will just cause more issues! Doing it this way is simpler and will work fine for you!

0
Silvathor On

Like RoyalQuack, I don't recommend predicate, but if you use execute at @a if block ~ ~ ~ blue_stained_glass_pane run ... you will probably have some issues. Unless you only have this block in one place on your map, you will probably run portal somewhere else.

I recommend using a positional detection instead:

execute as @a[x=XX,y=YY,z=ZZ,dx=0,dy=1,dz=0] run function sys:yourfunction (change XX YY ZZ by your location of course)

Using as instead of at allows to use @s in yourfunction which can be convenient. Example of yourfunction:

tp @s 10 25 10 particle flame X Y Z 0 0 0 0.02 force @a title @a [{"selector":@s, "text":" used a portal!", "color": "red"}]

If you have several portals that need to do the same action, instead of using fixed location and having to redo a different command at each portal, you can use an invisible entity to place on each portal and do the detection according to the invisible entity: execute at @e[type=marker,tag=portal] as @a[dx=0,dy=1,dz=0] run function sys:yourfunction

Here it will run the yourfunction function for all players on the marker entity with the portal tag.