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
This commit is contained in:
the-real-herowl 2023-12-25 23:50:06 +01:00
parent cb7878249d
commit 9e3d7ce0f4
4 changed files with 49 additions and 40 deletions

View file

@ -31,6 +31,7 @@ local known_controls = {
aux1 = true, aux1 = true,
down = true, down = true,
up = true, up = true,
zoom = true,
} }
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)

View file

@ -239,7 +239,7 @@ end
controls.register_on_release(function(player, key, time) 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 inv = minetest.get_inventory({type="player", name=player:get_player_name()})
local wielditem = player:get_wielded_item() 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 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) controls.register_on_hold(function(player, key, time)
local name = player:get_player_name() local name = player:get_player_name()
local creative = minetest.is_creative_enabled(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 return
end end
--local inv = minetest.get_inventory({type="player", name=name}) --local inv = minetest.get_inventory({type="player", name=name})
local wielditem = player:get_wielded_item() 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 if bow_load[name] == nil
local enchanted = mcl_enchanting.is_enchanted(wielditem:get_name()) and (wielditem:get_name()=="mcl_bows:bow" or wielditem:get_name()=="mcl_bows:bow_enchanted")
if enchanted then and (wielditem:get_meta():get("active") or key == "zoom") and (creative or get_arrow(player)) then
wielditem:set_name("mcl_bows:bow_0_enchanted") local enchanted = mcl_enchanting.is_enchanted(wielditem:get_name())
else if enchanted then
wielditem:set_name("mcl_bows:bow_0") wielditem:set_name("mcl_bows:bow_0_enchanted")
end else
player:set_wielded_item(wielditem) wielditem:set_name("mcl_bows:bow_0")
if minetest.get_modpath("playerphysics") then end
-- Slow player down when using bow player:set_wielded_item(wielditem)
playerphysics.add_physics_factor(player, "speed", "mcl_bows:use_bow", PLAYER_USE_BOW_SPEED) if minetest.get_modpath("playerphysics") then
end -- Slow player down when using bow
bow_load[name] = minetest.get_us_time() playerphysics.add_physics_factor(player, "speed", "mcl_bows:use_bow", PLAYER_USE_BOW_SPEED)
bow_index[name] = player:get_wield_index() end
bow_load[name] = minetest.get_us_time()
bow_index[name] = player:get_wield_index()
-- begin Bow Zoom. -- begin Bow Zoom.
mcl_fovapi.apply_modifier(player, "bowcomplete") mcl_fovapi.apply_modifier(player, "bowcomplete")
else else
if player:get_wield_index() == bow_index[name] then if player:get_wield_index() == bow_index[name] then
if type(bow_load[name]) == "number" then if type(bow_load[name]) == "number" then

View file

@ -263,7 +263,7 @@ end
controls.register_on_release(function(player, key, time) 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 inv = minetest.get_inventory({type="player", name=player:get_player_name()})
local wielditem = player:get_wielded_item() 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 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) controls.register_on_hold(function(player, key, time)
local name = player:get_player_name() local name = player:get_player_name()
local creative = minetest.is_creative_enabled(name) local creative = minetest.is_creative_enabled(name)
if key ~= "RMB" then if key ~= "RMB" and key ~= "zoom" then
return return
end end
--local inv = minetest.get_inventory({type="player", name=name}) --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 BOW_CHARGE_TIME_FULL = _BOW_CHARGE_TIME_FULL
end 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 if bow_load[name] == nil
local enchanted = mcl_enchanting.is_enchanted(wielditem:get_name()) and (wielditem:get_name()=="mcl_bows:crossbow" or wielditem:get_name()=="mcl_bows:crossbow_enchanted")
if enchanted then and (wielditem:get_meta():get("active") or key=="zoom") and (creative or get_arrow(player)) then
wielditem:set_name("mcl_bows:crossbow_0_enchanted") local enchanted = mcl_enchanting.is_enchanted(wielditem:get_name())
play_load_sound(0, player:get_pos()) if enchanted then
else wielditem:set_name("mcl_bows:crossbow_0_enchanted")
wielditem:set_name("mcl_bows:crossbow_0") play_load_sound(0, player:get_pos())
play_load_sound(0, player:get_pos()) else
end wielditem:set_name("mcl_bows:crossbow_0")
player:set_wielded_item(wielditem) play_load_sound(0, player:get_pos())
if minetest.get_modpath("playerphysics") then end
-- Slow player down when using bow player:set_wielded_item(wielditem)
playerphysics.add_physics_factor(player, "speed", "mcl_bows:use_crossbow", PLAYER_USE_CROSSBOW_SPEED) if minetest.get_modpath("playerphysics") then
end -- Slow player down when using bow
bow_load[name] = minetest.get_us_time() playerphysics.add_physics_factor(player, "speed", "mcl_bows:use_crossbow", PLAYER_USE_CROSSBOW_SPEED)
bow_index[name] = player:get_wield_index() end
bow_load[name] = minetest.get_us_time()
bow_index[name] = player:get_wield_index()
else else
if player:get_wield_index() == bow_index[name] then if player:get_wield_index() == bow_index[name] then
if type(bow_load[name]) == "number" then if type(bow_load[name]) == "number" then

View file

@ -58,17 +58,21 @@ local function remove_scope(player)
end end
controls.register_on_press(function(player, key) controls.register_on_press(function(player, key)
if key ~= "RMB" then return end if key ~= "RMB" and key ~= "zoom" then return end
add_scope(player) if spyglass_scope[player] == nil then
add_scope(player)
end
end) end)
controls.register_on_release(function(player, key, time) 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) remove_scope(player)
end) end)
controls.register_on_hold(function(player, key, time) 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() local wielditem = player:get_wielded_item()
if wielditem:get_name() == "mcl_spyglass:spyglass" then if wielditem:get_name() == "mcl_spyglass:spyglass" then
mcl_fovapi.apply_modifier(player, "spyglass") -- apply the FOV effect. mcl_fovapi.apply_modifier(player, "spyglass") -- apply the FOV effect.