import { world, system } from "@minecraft/server";

function getblockFace(block,blockFace) {
    switch (blockFace) {
        case "Up":
            return block.above();
        case "Down":
            return block.below()
        case "South":
            return block.south()
        case "North":
            return block.north()
        case "East":
            return block.east()
        case "West":
            return block.west()
    }
}
//rubber ducke fruit
world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})


world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_banana") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_banana",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_dragon_fruit") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_dragon_fruit",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_lime") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_dragon_lime",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_mango") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_mango",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})
//rubber ducke dessert
world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_icecream") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_icecream",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_donut") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_donut",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_raspberry_cheesecake") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_raspberry_cheesecake",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_chocolate_cake") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_chocolate_cake",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})
//rubber ducke farm
world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_cow") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_cow",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_rooster") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_rooster",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_sheep") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_sheep",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_pig") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_pig",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})
//rubber ducke holiday
world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_easter") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_easter",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_christmas") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_christmas",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_july") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_july",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_halloween") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_halloween",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})
//rubber ducke sky
world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_day") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_day",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_night") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_night",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_sunrise") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_sunrise",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_sunset") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_sunset",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})
//rubber ducke special
world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_farm") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_farm",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_dessert") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_dessert",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_fruit") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_fruit",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_holiday") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_holiday",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})
//rubber ducke random
world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_beach") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_beach",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_the_grey") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_they_grey",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_stone") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_stone",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:rubber_ducke_sky") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:rubber_ducke_sky",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})
//ducke set
world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:ducke_set") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:ducke_set",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:ducke_set_dessert") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:ducke_set_dessert",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:ducke_set_fruit") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:ducke_set_fruit",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:ducke_set_farm") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:ducke_set_farm",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:ducke_set_holiday") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:ducke_set_holiday",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:ducke_set_sky") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:ducke_set_sky",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:ducke_set_special") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:ducke_set_special",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})
//Rubber ducke sets emissive
world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:ducke_set_emissive") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:ducke_set_emissive",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:ducke_set_emissive_transparent") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:ducke_set_emissive_transparent",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:ducke_set_trippy") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:ducke_set_trippy",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:ducke_set_beaming") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:ducke_set_beaming",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})

world.beforeEvents.playerInteractWithBlock.subscribe(async({player, isFirstEvent, itemStack, block, blockFace})=>{
    if (itemStack?.typeId !== "just:ducke_set_transparent") return;
    await system.waitTicks(1);
    const entities = player.dimension.getEntities({
        location: getblockFace(block,blockFace).center(),
        closest: 1,
        type: "just:ducke_set_transparent",
        excludeTags: ["rotated"]
    });
    if (!entities.length) return;
    const rot = player.getRotation().y + 180;
    let yRot = 0;
    if (rot >= 22.5 && rot < 67.5) yRot = 45
    else if (rot >= 67.5 && rot < 112.5) yRot = 90
    else if (rot >= 112.5 && rot < 157.5) yRot = 135
    else if (rot >= 157.5 && rot < 202.5) yRot = 180
    else if (rot >= 202.5 && rot < 247.5) yRot = 225
    else if (rot >= 247.5 && rot < 292.5) yRot = 270
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    else if (rot >= 292.5 && rot < 337.5) yRot = 315
    
    entities.forEach(entity=>{
        entity.setRotation({x:0,y:yRot});
        entity.addTag("rotated")
    })
})









