diff --git a/doc/ru/scripting.md b/doc/ru/scripting.md index 12878e88..95d3d944 100644 --- a/doc/ru/scripting.md +++ b/doc/ru/scripting.md @@ -21,6 +21,7 @@ - [pack](scripting/builtins/libpack.md) - [player](scripting/builtins/libplayer.md) - [quat](scripting/builtins/libquat.md) + - [rules](scripting/builtins/librules.md) - [time](scripting/builtins/libtime.md) - [utf8](scripting/builtins/libutf8.md) - [vec2, vec3, vec4](scripting/builtins/libvecn.md) diff --git a/res/config/bindings.toml b/res/config/bindings.toml index a0ab278f..426a580f 100644 --- a/res/config/bindings.toml +++ b/res/config/bindings.toml @@ -13,6 +13,7 @@ camera.mode="key:f4" player.noclip="key:n" player.flight="key:f" player.attack="mouse:left" +player.destroy="mouse:left" player.build="mouse:right" player.pick="mouse:middle" player.drop="key:q" diff --git a/res/layouts/console.xml.lua b/res/layouts/console.xml.lua index 711f0435..7f5ccd0e 100644 --- a/res/layouts/console.xml.lua +++ b/res/layouts/console.xml.lua @@ -61,7 +61,7 @@ function submit(text) if name == nil then name = text end - if not rules.get("cheat-commands") and table.has(console.cheats, name) then + if not rules.get("allow-cheats") and table.has(console.cheats, name) then console.log("cheat commands are disabled") document.prompt.text = "" document.prompt.focused = true diff --git a/res/scripts/stdcmd.lua b/res/scripts/stdcmd.lua index b8645916..98609688 100644 --- a/res/scripts/stdcmd.lua +++ b/res/scripts/stdcmd.lua @@ -33,7 +33,7 @@ console.add_command( local str = "Available commands:" for i,k in ipairs(commands) do - if rules.get("cheat-commands") or not table.has(console.cheats, k) then + if rules.get("allow-cheats") or not table.has(console.cheats, k) then str = str .. "\n " .. build_scheme(console.get_command_info(k)) end end diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index c9cef6dd..16e04b6e 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -229,7 +229,10 @@ function _rules.create(name, value, handler) end function _rules.unlisten(name, id) - local rule = _rules.get_rule(name) + local rule = _rules.rules[name] + if rule == nil then + return + end rule.listeners[utf8.encode(id)] = nil end @@ -237,7 +240,7 @@ function _rules.clear() _rules.rules = {} _rules.nextid = 1 - _rules.create("cheat-commands", true) + _rules.create("allow-cheats", true) end function __vc_create_hud_rules() @@ -250,9 +253,12 @@ function __vc_create_hud_rules() _rules.create("allow-noclip", true, function(value) input.set_enabled("player.noclip", value) end) - _rules.create("allow-destruct", true, function(value) + _rules.create("allow-attack", true, function(value) input.set_enabled("player.attack", value) end) + _rules.create("allow-destroy", true, function(value) + input.set_enabled("player.destroy", value) + end) _rules.create("allow-cheat-movement", true, function(value) input.set_enabled("movement.cheat", value) end) diff --git a/res/texts/en_US.txt b/res/texts/en_US.txt index 40c684a4..0d15d5b0 100644 --- a/res/texts/en_US.txt +++ b/res/texts/en_US.txt @@ -29,7 +29,8 @@ movement.crouch=Crouch movement.cheat=Cheat hud.inventory=Inventory player.pick=Pick Block -player.attack=Attack / Break +player.attack=Attack +player.destroy=Destroy player.build=Place Block player.fast_interaction=Accelerated interaction player.flight=Flight diff --git a/res/texts/ru_RU.txt b/res/texts/ru_RU.txt index 490ef4d7..a7d5ce43 100644 --- a/res/texts/ru_RU.txt +++ b/res/texts/ru_RU.txt @@ -91,7 +91,8 @@ movement.crouch=Красться movement.cheat=Чит hud.inventory=Инвентарь player.pick=Подобрать Блок -player.attack=Атаковать / Сломать +player.attack=Атаковать +player.destroy=Сломать player.build=Поставить Блок player.fast_interaction=Ускоренное взаимодействие player.flight=Полёт diff --git a/src/core_defs.hpp b/src/core_defs.hpp index c2b5dd39..4a02cac9 100644 --- a/src/core_defs.hpp +++ b/src/core_defs.hpp @@ -25,6 +25,7 @@ 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"; inline const std::string BIND_PLAYER_PICK = "player.pick"; inline const std::string BIND_PLAYER_FAST_INTERACTOIN = diff --git a/src/logic/PlayerController.cpp b/src/logic/PlayerController.cpp index ed916aac..57af3c13 100644 --- a/src/logic/PlayerController.cpp +++ b/src/logic/PlayerController.cpp @@ -494,7 +494,9 @@ void PlayerController::updateInteraction(float delta) { bool xkey = Events::active(BIND_PLAYER_FAST_INTERACTOIN); float maxDistance = xkey ? 200.0f : 10.0f; bool longInteraction = interactionTimer <= 0 || xkey; - bool lclick = Events::jactive(BIND_PLAYER_ATTACK) || + bool lclick = Events::jactive(BIND_PLAYER_DESTROY) || + (longInteraction && Events::active(BIND_PLAYER_DESTROY)); + bool lattack = Events::jactive(BIND_PLAYER_ATTACK) || (longInteraction && Events::active(BIND_PLAYER_ATTACK)); bool rclick = Events::jactive(BIND_PLAYER_BUILD) || (longInteraction && Events::active(BIND_PLAYER_BUILD)); @@ -512,7 +514,7 @@ void PlayerController::updateInteraction(float delta) { scripting::on_item_use(player.get(), item); } if (selection.entity) { - updateEntityInteraction(selection.entity, lclick, rclick); + updateEntityInteraction(selection.entity, lattack, rclick); } return; }