{"id":"6B5VVuabJZ","url":"https://pastebin.ca/6B5VVuabJZ","raw_url":"https://raw.anybin.ca/6B5VVuabJZ","visibility":"unlisted","access":"public","created_at":1793632371702,"expires_at":1801408371702,"fetch_limit":null,"fetches_used":0,"reads_remaining":null,"size_bytes":2280,"syntax_hint":"javascript","title":"Custom Player Body Yaw Code (Bypass yBodyRot bugs)","filename":"BodyYawCode","change_note":null,"cipher":null,"cipher_meta":null,"parent_id":null,"root_id":"6B5VVuabJZ","version":1,"owner_id":null,"recipient_id":null,"body":"if (entity instanceof net.minecraft.world.entity.player.Player player) {\n    net.mcreator.[yourmodname].network.YourModVariables.PlayerVariables vars = player.getCapability(net.mcreator.[yourmodname].network.YourModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new net.mcreator.[yourmodname].network.YourModVariables.PlayerVariables());\n\n    float currentBodyYaw = (float) [global_bodyYaw];\n    if (currentBodyYaw == 0.0f && player.getYRot() != 0.0f) {\n        currentBodyYaw = player.getYRot();\n    }\n\n    float headYaw = player.getYRot();\n\n    double dx = player.getX() - [global_lastX];\n    double dz = player.getZ() - [global_lastZ];\n\n    int moveGrace = player.getPersistentData().getInt(\"move_grace\");\n\n    if (dx * dx + dz * dz > 0.001) {\n        moveGrace = 5;\n        float moveYaw = (float)(Math.atan2(-dx, dz) * (180.0 / Math.PI));\n        float relativeYaw = net.minecraft.util.Mth.wrapDegrees(moveYaw - headYaw);\n        player.getPersistentData().putFloat(\"last_rel_yaw\", relativeYaw);\n        \n        [global_lastX] = player.getX();\n        [global_lastZ] = player.getZ();\n    } else if (moveGrace > 0) {\n        moveGrace--;\n    }\n\n    player.getPersistentData().putInt(\"move_grace\", moveGrace);\n    boolean isMoving = moveGrace > 0;\n\n    float idealBodyYaw = headYaw;\n\n    if (isMoving) {\n        float relYaw = player.getPersistentData().getFloat(\"last_rel_yaw\");\n        \n        if (Math.abs(relYaw) < 135.0f) {\n            if (relYaw > 50.0f) relYaw = 50.0f;\n            if (relYaw < -50.0f) relYaw = -50.0f;\n            idealBodyYaw = headYaw + relYaw;\n        }\n    }\n\n    float diffIdeal = net.minecraft.util.Mth.wrapDegrees(idealBodyYaw - currentBodyYaw);\n    boolean isInteracting = player.swinging || player.isUsingItem();\n\n    if (isInteracting) {\n        currentBodyYaw += diffIdeal * 0.4f;\n    } else if (isMoving) {\n        currentBodyYaw += diffIdeal * 0.4f;\n    }\n\n    float diffHeadBody = net.minecraft.util.Mth.wrapDegrees(headYaw - currentBodyYaw);\n\n    if (diffHeadBody > 50.0f) {\n        currentBodyYaw = headYaw - 50.0f;\n    } else if (diffHeadBody < -50.0f) {\n        currentBodyYaw = headYaw + 50.0f;\n    }\n\n    [global_bodyYaw] = (double) net.minecraft.util.Mth.wrapDegrees(currentBodyYaw);\n    vars.syncPlayerVariables(player);\n}\n"}