ItemEvents.entityInteracted("minecraft:villager", e => {
    if(e.getTarget().getType() == "minecraft:villager" && e.getPlayer()) {
        //e.target.getLevel().createExplosion(e.target.x, e.target.y, e.target.z).exploder(e.getTarget()).explosionMode("mob").strength(5).explode();
        const mobType = 'minecraft:villager';

        const mobCount = 9;

        for (let i = 0; i < mobCount; i++) {
            const x = e.target.x;
            const z = e.target.z;
            const y = e.target.y;

            const mob = e.level.createEntity(mobType)
            mob.setPosition(x, y, z);
            mob.spawn();

            const mob2 = e.level.createEntity(mobType);
            mob2.setPosition(x, y, z + 1);
            mob2.spawn();
            const mob3 = e.level.createEntity(mobType);
            mob3.setPosition(x + 1, y, z);
            mob3.spawn();
            const mob4 = e.level.createEntity(mobType);
            mob4.setPosition(x + 1, y, z + 1);
            mob4.spawn();
            const mob5 = e.level.createEntity(mobType);
            mob5.setPosition(x, y, z - 1);
            mob5.spawn();
            const mob6 = e.level.createEntity(mobType);
            mob6.setPosition(x - 1, y, z);
            mob6.spawn();
            const mob7 = e.level.createEntity(mobType);
            mob7.setPosition(x - 1, y, z - 1);
            mob7.spawn();
            const mob8 = e.level.createEntity(mobType);
            mob8.setPosition(x - 1, y, z + 2);
            mob8.spawn();

            mob.addDeltaMovement(new Vec3d(0, 1, 0));
            mob.setGlowing(true);
            mob2.addDeltaMovement(new Vec3d(0, 1, 0));
            mob2.setGlowing(true);
            mob3.addDeltaMovement(new Vec3d(0, 1, 0));
            mob3.setGlowing(true);
            mob4.addDeltaMovement(new Vec3d(0, 1, 0));
            mob4.setGlowing(true);
            mob5.addDeltaMovement(new Vec3d(0, 1, 0));
            mob5.setGlowing(true);
            mob6.addDeltaMovement(new Vec3d(0, 1, 0));
            mob6.setGlowing(true);
            mob7.addDeltaMovement(new Vec3d(0, 1, 0));
            mob7.setGlowing(true);
            mob8.addDeltaMovement(new Vec3d(0, 1, 0));
            mob8.setGlowing(true);

            e.player.sendSystemMessage(Component.red("E5"));
        }

        e.player.sendSystemMessage(Component.red("E5"));
        
        e.target.addDeltaMovement(new Vec3d(0, 3, 0));
        e.target.setGlowing(true);
        //e.target.kill();
        e.player.sendSystemMessage(Component.red("НЕЛЬЗЯ"));
        e.cancel();
    }
})