diff --git a/res/content/base/scripts/hud.lua b/res/content/base/scripts/hud.lua index a3df0849..31125631 100644 --- a/res/content/base/scripts/hud.lua +++ b/res/content/base/scripts/hud.lua @@ -23,30 +23,4 @@ function on_hud_open() local velocity = vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL)) drop.rigidbody:set_vel(velocity) end) - input.add_callback("player.pick", function () - if hud.is_paused() or hud.is_inventory_open() then - return - end - local pid = hud.get_player() - local x, y, z = player.get_selected_block(pid) - if x == nil then - return - end - local id = block.get_picking_item(block.get(x, y, z)) - local inv, cur_slot = player.get_inventory(pid) - local slot = inventory.find_by_item(inv, id, 0, 9) - if slot then - player.set_selected_slot(pid, slot) - return - end - if not rules.get("allow-content-access") then - return - end - slot = inventory.find_by_item(inv, 0, 0, 9) - if slot then - cur_slot = slot - end - player.set_selected_slot(pid, cur_slot) - inventory.set(inv, cur_slot, id, 1) - end) end diff --git a/res/scripts/hud.lua b/res/scripts/hud.lua new file mode 100644 index 00000000..093d43c3 --- /dev/null +++ b/res/scripts/hud.lua @@ -0,0 +1,58 @@ +function on_hud_open() + input.add_callback("player.pick", function () + if hud.is_paused() or hud.is_inventory_open() then + return + end + local pid = hud.get_player() + local x, y, z = player.get_selected_block(pid) + if x == nil then + return + end + local id = block.get_picking_item(block.get(x, y, z)) + local inv, cur_slot = player.get_inventory(pid) + local slot = inventory.find_by_item(inv, id, 0, 9) + if slot then + player.set_selected_slot(pid, slot) + return + end + if not rules.get("allow-content-access") then + return + end + slot = inventory.find_by_item(inv, 0, 0, 9) + if slot then + cur_slot = slot + end + player.set_selected_slot(pid, cur_slot) + inventory.set(inv, cur_slot, id, 1) + end) + + input.add_callback("player.noclip", function () + if hud.is_paused() or hud.is_inventory_open() then + return + end + local pid = hud.get_player() + if player.is_noclip(pid) then + player.set_flight(pid, false) + player.set_noclip(pid, false) + else + player.set_flight(pid, true) + player.set_noclip(pid, true) + end + end) + + input.add_callback("player.flight", function () + if hud.is_paused() or hud.is_inventory_open() then + return + end + local pid = hud.get_player() + if player.is_noclip(pid) then + return + end + if player.is_flight(pid) then + player.set_flight(pid, false) + else + player.set_flight(pid, true) + player.set_vel(pid, 0, 1, 0) + end + end) +end diff --git a/src/core_defs.hpp b/src/core_defs.hpp index 60f9ec79..8042ca36 100644 --- a/src/core_defs.hpp +++ b/src/core_defs.hpp @@ -21,8 +21,6 @@ inline const std::string BIND_MOVE_CROUCH = "movement.crouch"; inline const std::string BIND_MOVE_CHEAT = "movement.cheat"; inline const std::string BIND_CAM_ZOOM = "camera.zoom"; inline const std::string BIND_CAM_MODE = "camera.mode"; -inline const std::string BIND_PLAYER_NOCLIP = "player.noclip"; -inline const std::string BIND_PLAYER_FLIGHT = "player.flight"; inline const std::string BIND_PLAYER_ATTACK = "player.attack"; inline const std::string BIND_PLAYER_DESTROY = "player.destroy"; inline const std::string BIND_PLAYER_BUILD = "player.build"; diff --git a/src/logic/PlayerController.cpp b/src/logic/PlayerController.cpp index f26b5395..44d1a64c 100644 --- a/src/logic/PlayerController.cpp +++ b/src/logic/PlayerController.cpp @@ -288,8 +288,6 @@ void PlayerController::updateKeyboard() { input.jump = Events::active(BIND_MOVE_JUMP); input.zoom = Events::active(BIND_CAM_ZOOM); input.cameraMode = Events::jactive(BIND_CAM_MODE); - input.noclip = Events::jactive(BIND_PLAYER_NOCLIP); - input.flight = Events::jactive(BIND_PLAYER_FLIGHT); } void PlayerController::resetKeyboard() { diff --git a/src/objects/Player.cpp b/src/objects/Player.cpp index 0a2106ed..d5493a6e 100644 --- a/src/objects/Player.cpp +++ b/src/objects/Player.cpp @@ -135,18 +135,7 @@ void Player::updateInput(PlayerInput& input, float delta) { hitbox->velocity.y = JUMP_FORCE; } - if ((input.flight && !noclip) || (input.noclip && flight == noclip)) { - flight = !flight; - if (flight) { - hitbox->velocity.y += 1.0f; - } - } hitbox->type = noclip ? BodyType::KINEMATIC : BodyType::DYNAMIC; - if (input.noclip) { - noclip = !noclip; - } - input.noclip = false; - input.flight = false; } void Player::updateSelectedEntity() { diff --git a/src/objects/Player.hpp b/src/objects/Player.hpp index 1f57c6f7..55f824d6 100644 --- a/src/objects/Player.hpp +++ b/src/objects/Player.hpp @@ -27,8 +27,6 @@ struct PlayerInput { bool shift : 1; bool cheat : 1; bool jump : 1; - bool noclip : 1; - bool flight : 1; }; struct CursorSelection {