From 9e3d7ce0f4cced4d23054e8fd9e44aff7f6203a2 Mon Sep 17 00:00:00 2001 From: the-real-herowl Date: Mon, 25 Dec 2023 23:50:06 +0100 Subject: [PATCH 1/2] Added a workaround for mobile using zoom key * Bow can now be used with zoom key aside of RMB * Crossbow can now be loaded with zoom key as well * Spyglass can now be used with zoom key --- mods/CORE/controls/init.lua | 1 + mods/ITEMS/mcl_bows/bow.lua | 38 +++++++++++++++++--------------- mods/ITEMS/mcl_bows/crossbow.lua | 38 +++++++++++++++++--------------- mods/ITEMS/mcl_spyglass/init.lua | 12 ++++++---- 4 files changed, 49 insertions(+), 40 deletions(-) diff --git a/mods/CORE/controls/init.lua b/mods/CORE/controls/init.lua index ef57281a4..7f308d8e0 100644 --- a/mods/CORE/controls/init.lua +++ b/mods/CORE/controls/init.lua @@ -31,6 +31,7 @@ local known_controls = { aux1 = true, down = true, up = true, + zoom = true, } minetest.register_on_joinplayer(function(player) diff --git a/mods/ITEMS/mcl_bows/bow.lua b/mods/ITEMS/mcl_bows/bow.lua index 6ae64a14e..3126f822b 100644 --- a/mods/ITEMS/mcl_bows/bow.lua +++ b/mods/ITEMS/mcl_bows/bow.lua @@ -239,7 +239,7 @@ end controls.register_on_release(function(player, key, time) - if key~="RMB" then return end + if key~="RMB" and key~="zoom" then return end --local inv = minetest.get_inventory({type="player", name=player:get_player_name()}) local wielditem = player:get_wielded_item() if (wielditem:get_name()=="mcl_bows:bow_0" or wielditem:get_name()=="mcl_bows:bow_1" or wielditem:get_name()=="mcl_bows:bow_2" or @@ -307,28 +307,30 @@ end) controls.register_on_hold(function(player, key, time) local name = player:get_player_name() local creative = minetest.is_creative_enabled(name) - if key ~= "RMB" or not (creative or get_arrow(player)) then + if (key ~= "RMB" and key ~= "zoom") or not (creative or get_arrow(player)) then return end --local inv = minetest.get_inventory({type="player", name=name}) local wielditem = player:get_wielded_item() - if bow_load[name] == nil and (wielditem:get_name()=="mcl_bows:bow" or wielditem:get_name()=="mcl_bows:bow_enchanted") and wielditem:get_meta():get("active") and (creative or get_arrow(player)) then - local enchanted = mcl_enchanting.is_enchanted(wielditem:get_name()) - if enchanted then - wielditem:set_name("mcl_bows:bow_0_enchanted") - else - wielditem:set_name("mcl_bows:bow_0") - end - player:set_wielded_item(wielditem) - if minetest.get_modpath("playerphysics") then - -- Slow player down when using bow - playerphysics.add_physics_factor(player, "speed", "mcl_bows:use_bow", PLAYER_USE_BOW_SPEED) - end - bow_load[name] = minetest.get_us_time() - bow_index[name] = player:get_wield_index() + if bow_load[name] == nil + and (wielditem:get_name()=="mcl_bows:bow" or wielditem:get_name()=="mcl_bows:bow_enchanted") + and (wielditem:get_meta():get("active") or key == "zoom") and (creative or get_arrow(player)) then + local enchanted = mcl_enchanting.is_enchanted(wielditem:get_name()) + if enchanted then + wielditem:set_name("mcl_bows:bow_0_enchanted") + else + wielditem:set_name("mcl_bows:bow_0") + end + player:set_wielded_item(wielditem) + if minetest.get_modpath("playerphysics") then + -- Slow player down when using bow + playerphysics.add_physics_factor(player, "speed", "mcl_bows:use_bow", PLAYER_USE_BOW_SPEED) + end + bow_load[name] = minetest.get_us_time() + bow_index[name] = player:get_wield_index() - -- begin Bow Zoom. - mcl_fovapi.apply_modifier(player, "bowcomplete") + -- begin Bow Zoom. + mcl_fovapi.apply_modifier(player, "bowcomplete") else if player:get_wield_index() == bow_index[name] then if type(bow_load[name]) == "number" then diff --git a/mods/ITEMS/mcl_bows/crossbow.lua b/mods/ITEMS/mcl_bows/crossbow.lua index df7b5f560..012268fa8 100644 --- a/mods/ITEMS/mcl_bows/crossbow.lua +++ b/mods/ITEMS/mcl_bows/crossbow.lua @@ -263,7 +263,7 @@ end controls.register_on_release(function(player, key, time) - if key~="RMB" then return end + if key~="RMB" and key~="zoom" then return end --local inv = minetest.get_inventory({type="player", name=player:get_player_name()}) local wielditem = player:get_wielded_item() if wielditem:get_name()=="mcl_bows:crossbow_2" and get_arrow(player) or wielditem:get_name()=="mcl_bows:crossbow_2" and minetest.is_creative_enabled(player:get_player_name()) or wielditem:get_name()=="mcl_bows:crossbow_2_enchanted" and get_arrow(player) or wielditem:get_name()=="mcl_bows:crossbow_2_enchanted" and minetest.is_creative_enabled(player:get_player_name()) then @@ -359,7 +359,7 @@ end) controls.register_on_hold(function(player, key, time) local name = player:get_player_name() local creative = minetest.is_creative_enabled(name) - if key ~= "RMB" then + if key ~= "RMB" and key ~= "zoom" then return end --local inv = minetest.get_inventory({type="player", name=name}) @@ -373,22 +373,24 @@ controls.register_on_hold(function(player, key, time) BOW_CHARGE_TIME_FULL = _BOW_CHARGE_TIME_FULL end - if bow_load[name] == nil and (wielditem:get_name()=="mcl_bows:crossbow" or wielditem:get_name()=="mcl_bows:crossbow_enchanted") and wielditem:get_meta():get("active") and (creative or get_arrow(player)) then - local enchanted = mcl_enchanting.is_enchanted(wielditem:get_name()) - if enchanted then - wielditem:set_name("mcl_bows:crossbow_0_enchanted") - play_load_sound(0, player:get_pos()) - else - wielditem:set_name("mcl_bows:crossbow_0") - play_load_sound(0, player:get_pos()) - end - player:set_wielded_item(wielditem) - if minetest.get_modpath("playerphysics") then - -- Slow player down when using bow - playerphysics.add_physics_factor(player, "speed", "mcl_bows:use_crossbow", PLAYER_USE_CROSSBOW_SPEED) - end - bow_load[name] = minetest.get_us_time() - bow_index[name] = player:get_wield_index() + if bow_load[name] == nil + and (wielditem:get_name()=="mcl_bows:crossbow" or wielditem:get_name()=="mcl_bows:crossbow_enchanted") + and (wielditem:get_meta():get("active") or key=="zoom") and (creative or get_arrow(player)) then + local enchanted = mcl_enchanting.is_enchanted(wielditem:get_name()) + if enchanted then + wielditem:set_name("mcl_bows:crossbow_0_enchanted") + play_load_sound(0, player:get_pos()) + else + wielditem:set_name("mcl_bows:crossbow_0") + play_load_sound(0, player:get_pos()) + end + player:set_wielded_item(wielditem) + if minetest.get_modpath("playerphysics") then + -- Slow player down when using bow + playerphysics.add_physics_factor(player, "speed", "mcl_bows:use_crossbow", PLAYER_USE_CROSSBOW_SPEED) + end + bow_load[name] = minetest.get_us_time() + bow_index[name] = player:get_wield_index() else if player:get_wield_index() == bow_index[name] then if type(bow_load[name]) == "number" then diff --git a/mods/ITEMS/mcl_spyglass/init.lua b/mods/ITEMS/mcl_spyglass/init.lua index 31d461107..afa7adaf4 100644 --- a/mods/ITEMS/mcl_spyglass/init.lua +++ b/mods/ITEMS/mcl_spyglass/init.lua @@ -58,17 +58,21 @@ local function remove_scope(player) end controls.register_on_press(function(player, key) - if key ~= "RMB" then return end - add_scope(player) + if key ~= "RMB" and key ~= "zoom" then return end + if spyglass_scope[player] == nil then + add_scope(player) + end end) controls.register_on_release(function(player, key, time) - if key ~= "RMB" then return end + if key ~= "RMB" and key ~= "zoom" then return end + local ctrl = player:get_player_control() + if key == "RMB" and ctrl.zoom or key == "zoom" and ctrl.place then return end remove_scope(player) end) controls.register_on_hold(function(player, key, time) - if key ~= "RMB" then return end + if key ~= "RMB" and key ~= "zoom" then return end local wielditem = player:get_wielded_item() if wielditem:get_name() == "mcl_spyglass:spyglass" then mcl_fovapi.apply_modifier(player, "spyglass") -- apply the FOV effect. From 39f98ec6fbd66cf5351825c78ed3d59e39ebfcb3 Mon Sep 17 00:00:00 2001 From: the-real-herowl Date: Mon, 25 Dec 2023 23:56:39 +0100 Subject: [PATCH 2/2] Updated doc strings for bow and crossbow Mentioned the zoom key --- mods/ITEMS/mcl_bows/bow.lua | 2 +- mods/ITEMS/mcl_bows/crossbow.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_bows/bow.lua b/mods/ITEMS/mcl_bows/bow.lua index 3126f822b..6b05b5434 100644 --- a/mods/ITEMS/mcl_bows/bow.lua +++ b/mods/ITEMS/mcl_bows/bow.lua @@ -140,7 +140,7 @@ minetest.register_tool("mcl_bows:bow", { _tt_help = S("Launches arrows"), _doc_items_longdesc = S("Bows are ranged weapons to shoot arrows at your foes.").."\n".. S("The speed and damage of the arrow increases the longer you charge. The regular damage of the arrow is between 1 and 9. At full charge, there's also a 20% of a critical hit, dealing 10 damage instead."), - _doc_items_usagehelp = S("To use the bow, you first need to have at least one arrow anywhere in your inventory (unless in Creative Mode). Hold down the right mouse button to charge, release to shoot."), + _doc_items_usagehelp = S("To use the bow, you first need to have at least one arrow anywhere in your inventory (unless in Creative Mode). Hold down the right mouse button (or the zoom key) to charge, release to shoot."), _doc_items_durability = BOW_DURABILITY, inventory_image = "mcl_bows_bow.png", wield_scale = mcl_vars.tool_wield_scale, diff --git a/mods/ITEMS/mcl_bows/crossbow.lua b/mods/ITEMS/mcl_bows/crossbow.lua index 012268fa8..af356e399 100644 --- a/mods/ITEMS/mcl_bows/crossbow.lua +++ b/mods/ITEMS/mcl_bows/crossbow.lua @@ -132,7 +132,7 @@ minetest.register_tool("mcl_bows:crossbow", { _tt_help = S("Launches arrows"), _doc_items_longdesc = S("Crossbows are ranged weapons to shoot arrows at your foes.").."\n".. S("The speed and damage of the arrow increases the longer you charge. The regular damage of the arrow is between 1 and 9. At full charge, there's also a 20% of a critical hit, dealing 10 damage instead."), - _doc_items_usagehelp = S("To use the crossbow, you first need to have at least one arrow anywhere in your inventory (unless in Creative Mode). Hold down the right mouse button to charge, release to load an arrow into the chamber, then to shoot press left mouse."), + _doc_items_usagehelp = S("To use the crossbow, you first need to have at least one arrow anywhere in your inventory (unless in Creative Mode). Hold down the right mouse button (or zoom key) to charge, release to load an arrow into the chamber, then to shoot press left mouse."), _doc_items_durability = BOW_DURABILITY, inventory_image = "mcl_bows_crossbow.png", wield_scale = mcl_vars.tool_wield_scale,