I'm trying to spawn a wandering trader when the player throws an apple into the water, but I'm not sure how to do it correctly. I found/created this mess 😅, and it doesn't seem to work.
const entity = event.entity;
if (entity.type == 'minecraft:item' && entity.item.id == 'minecraft:stone') {
const world = entity.level;
const x = entity.x;
const y = entity.y;
const z = entity.z;
if (world.getBlock(x, y, z).id == 'minecraft:water') {
const wanderingTrader = world.createEntity('minecraft:wandering_trader');
if (wanderingTrader) {
wanderingTrader.setPosition(x, y + 1, z);
world.spawnEntity(wanderingTrader);
console.log(`Wandering Trader spawned at (${x}, ${y + 1}, ${z}) in water`);
}
}
}
})```