#Blocks that Hurt Players/Mobs on Contact

1 messages · Page 1 of 1 (latest)

silver herald
#

Trying to make a custom cactus, how do I have it so that if a player or other entity touches it, they receive damage?

raven loom
# silver herald Trying to make a custom cactus, how do I have it so that if a player or other en...

Something like that could work. 😉

  const dimensions = ["minecraft:overworld", "minecraft:nether", "minecraft:the_end"];

  for (const dimensionId of dimensions) {
    const entities = world.getDimension(dimensionId).getEntities();

    for (const entity of entities) {
      if (!entity.isValid || !entity.getComponent("minecraft:health")) continue;

      const block = world.getDimension(dimensionId).getBlock({
        x: Math.floor(entity.location.x),
        y: Math.floor(entity.location.y - 0.1),
        z: Math.floor(entity.location.z)
      });

      if (block?.isValid && block.typeId == "custom_addon:my_block") {
        entity.applyDamage(1, {cause: "contact"});
      }
    }
  }
}, 10);```
silver herald