#entity.isInSunLight | Entity Prototype

1 messages · Page 1 of 1 (latest)

rough eagle
#
import {Entity} from '@minecraft/server'

Object.defineProperty(Entity.prototype, "isInSunLight", {
  get: function () {
    const height = this.dimension.heightRange;
    const time = world.getTimeOfDay();
    if (time >= 0 && time < 12000) {
      for (let y = this.location.y; y <= height.max; y++) {
        const block = this.dimension.getBlock({ ...this.location, y: y });
        if (block && block.isSolid) {
// Is not in sunlight since their is a non air/transparent block above them
          return false;
        }
      }
// Is in sunlight since their is air above them
      return true;
    }
// Is not in sunlight since it is night
    return false;
  },
});
  • How to use
    Put the code above in your script
if (entity.isInSunLight) {
   entity.setOnFire(4)
} else {
  entity.extinguishFire()
}
teal haven
fair rune