let mob = 'minecraft:zombie'
let radius = 40
BlockEvents.placed(event => {
let {player, level} = event;
let aabb = player.getBoundingBox().inflate(radius);
let ents = level.getEntities(player, aabb);
for (let ent of ents) {
if (ent.type == mob) {
let dx = ent.x - player.x;
let dy = ent.y - player.y;
let dz = ent.z - player.z;
if (dx*dx + dy*dy + dz*dz <= radius * radius) {
player.inventoryMenu.broadcastFullState()
event.cancel();
}
}
}
});
I ve got the code and it works pretty well. but now im trying to optimize it a little bit. the main goal is to stop running script if there is no needed entity in the world.
is there any way to check that entity is alive and it is in the world?