3

I'm currently working on a datapack which, among many other things, enables certain players to move swiftly through cobwebs, instead of being slowed down by them. However, I'm encountering the issue that testing for the block at the ~ ~ ~ position will only detect the cobweb if the player is in the center, not if they're touching the edge of it. As such, the player has to trudge through a small amount of cobweb before they receive the increased speed.

Is there any way to effectively remedy this? My current workaround is just testing for the block at the player's feet and for the block 0.3 blocks away from them in all cardinal directions, which seems to work on my test world, but has been causing problems on the server the datapack is made for. Plus, it's just painfully inefficient code.

As I'm using a datapack, predicates and advancements are, of course, on the table. A predicate would be preferable, although I understand it's not always possible.

My current inefficient code is as follows:

execute as @a[scores={Species=007}] at @s if block ~0.3 ~ ~ cobweb run scoreboard players set @s species007-01 2
execute as @a[scores={Species=007}] at @s if block ~-0.3 ~ ~ cobweb run scoreboard players set @s species007-01 2
execute as @a[scores={Species=007}] at @s if block ~ ~ ~0.3 cobweb run scoreboard players set @s species007-01 2
execute as @a[scores={Species=007}] at @s if block ~ ~ ~-0.3 cobweb run scoreboard players set @s species007-01 2
execute as @a[scores={Species=007}] at @s if block ~0.21 ~ ~0.21 cobweb run scoreboard players set @s species007-01 2
execute as @a[scores={Species=007}] at @s if block ~-0.21 ~ ~0.21 cobweb run scoreboard players set @s species007-01 2
execute as @a[scores={Species=007}] at @s if block ~-0.21 ~ ~-0.21 cobweb run scoreboard players set @s species007-01 2
execute as @a[scores={Species=007}] at @s if block ~0.21 ~ ~-0.21 cobweb run scoreboard players set @s species007-01 2
0

1 Answer 1

1

You can detect when a player is touching a cobweb with advancements using the minecraft:enter_block requirement. Here is an example advancement file that executes the function example:touched_cobweb when a player touches a cobweb.

{
  "criteria": {
    "requirement": {
      "trigger": "minecraft:enter_block",
      "conditions": {
        "block": "minecraft:cobweb"
      }
    }
  },
  "rewards": {
    "function": "example:touched_cobweb"
  }
}

You could also do away with the rewards section of the JSON and check whether a player has the advancement in another function, like so.

execute as <target selector> if entity @s[advancements={example:advancement_name=true}] run <command>

Note that you'll need to revoke the advancement from the player yourself; it is not automatically removed when the player leaves a cobweb.

You must log in to answer this question.

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