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

world.afterEvents.entitySpawn.subscribe((event) => {
    const entity = event.entity;

    const fixedMobs = [
        "mebesm:cutscene_huggy_wuggy_wounded_door",
        "mebesm:energy_module",
        "mebesm:power_module",
        "mebesm:ice_module",
        "mebesm:fire_module",
        "mebesm:brain_soyer",
        "mebesm:brain_soyer_off",
        "mebesm:machine1",
        "mebesm:machine2",
        "mebesm:machine",
        "mebesm:jump_platform",
        "mebesm:horizontal_bar",
        "mebesm:cutscene_mom_poppy_arms_steals_red_hand",
        "mebesm:cutscene_mom_poppy_arms_steals_red_hand1",
        "mebesm:cutscene_mom_poppy_arms_steals_red_hand3",
        "mebesm:cutscene_poppy_mom_hole",
        "mebesm:cutscene_poppy_mom_hole1",
        "mebesm:battery_compartment_close",
        "mebesm:battery_compartment",
        "mebesm:energy_giver",
        "mebesm:energy_pylons",
        "mebesm:energy_receiver",
        "mebesm:hand_scaner_blue",
        "mebesm:hand_scaner_green",
        "mebesm:hand_scaner_red",
        "mebesm:lever_open",
        "mebesm:lever",
        "mebesm:omni_scanner",
        "mebesm:power_receptor",
        "mebesm:security_panel",
        "mebesm:tv",
        "mebesm:tv1",
        "mebesm:tv2",
        "mebesm:tv3",
        "mebesm:tv4",
        "mebesm:tv5",
        "mebesm:tv6",
        "mebesm:door1_open",
        "mebesm:door1",
        "mebesm:door2_open",
        "mebesm:door2",
        "mebesm:door3_open",
        "mebesm:door3",
        "mebesm:door4_open",
        "mebesm:door4",
        "mebesm:door5_open",
        "mebesm:door5",
        "mebesm:door6_open",
        "mebesm:door6",
        "mebesm:door7_open",
        "mebesm:door7",
        "mebesm:door8_open",
        "mebesm:door8",
        "mebesm:door9_open",
        "mebesm:door9",
        "mebesm:tv_harley_sawyer",
        "mebesm:hand_scaner_red_and_blue"
    ];

    if (fixedMobs.includes(entity.typeId)) {
        const rotation = entity.getRotation();
        const yaw = rotation.y;

        const fixedYaw = Math.round(yaw / 90) * 90;

        entity.setRotation({ x: 0, y: fixedYaw });
    }
});