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) {
return false;
}
}
return true;
}
return false;
},
});
- How to use
Put the code above in your script
if (entity.isInSunLight) {
entity.setOnFire(4)
} else {
entity.extinguishFire()
}