From 85a00396b493355664c770eaa56f7a5582de771e Mon Sep 17 00:00:00 2001 From: Coder12a <38924418+Coder12a@users.noreply.github.com> Date: Fri, 30 Oct 2020 17:03:21 -0500 Subject: [PATCH] Throw: with use and zoom keys --- chatcommands.lua | 52 ++++++++++++++++++++++++----------------------- globalstep.lua | 7 ++++++- overrides.lua | 7 ++++++- player_events.lua | 12 ++++++----- 4 files changed, 46 insertions(+), 32 deletions(-) diff --git a/chatcommands.lua b/chatcommands.lua index 4179cdc..d5998fe 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -117,29 +117,31 @@ minetest.register_chatcommand("move_item", { -- See if the mod armor_3d is a thing here. if minetest.global_exists("armor") then - -- Cmd for changing the way you block incoming damage. - minetest.register_chatcommand("use_shield", { - params = "[]: Change how you block incoming damage.", - description = "If set to true, the shield plate placed in the armor inventory will be used to block all incoming damage when block key is pressed.", - privs = { - interact = true, - }, - func = function(name, param) - -- Check the given param. - if param == "true" then - -- block key will now use the shield in the armor inv to block any incoming damage. - player_persistent_data[name].use_shield = true - - return true, "Shield from armor inventory will now be used to block damage." - elseif param == "false" then - -- block key will now use whatever tool selected to block any incoming damage. - player_persistent_data[name].use_shield = nil - - return true, "Tools will now be used to block damage." - end - - -- use_shield cmd help. - return false, "Only parameters: 'true', and 'false' are accepted." - end - }) + return end + +-- Cmd for changing the way you block incoming damage. +minetest.register_chatcommand("use_shield", { + params = "[]: Change how you block incoming damage.", + description = "If set to true, the shield plate placed in the armor inventory will be used to block all incoming damage when block key is pressed.", + privs = { + interact = true, + }, + func = function(name, param) + -- Check the given param. + if param == "true" then + -- block key will now use the shield in the armor inv to block any incoming damage. + player_persistent_data[name].use_shield = true + + return true, "Shield from armor inventory will now be used to block damage." + elseif param == "false" then + -- block key will now use whatever tool selected to block any incoming damage. + player_persistent_data[name].use_shield = nil + + return true, "Tools will now be used to block damage." + end + + -- use_shield cmd help. + return false, "Only parameters: 'true', and 'false' are accepted." + end +}) diff --git a/globalstep.lua b/globalstep.lua index b9ad6a5..725bdbd 100644 --- a/globalstep.lua +++ b/globalstep.lua @@ -121,7 +121,12 @@ minetest.register_globalstep(function(dtime) local full_throw = throw_data.time + tool_capabilities.full_throw -- If neither dig or place is down then throw the item. - if (floor(control_bits / 128) % 2 ~= 1 and floor(control_bits / 256) % 2 ~= 1) or pp_data.active_dodges or pp_data.active_barrel_rolls then + if (floor(control_bits / 128) % 2 ~= 1 and + floor(control_bits / 256) % 2 ~= 1 and + floor(control_bits / 512) % 2 ~= 1 and + floor(control_bits / 32) % 2 ~= 1) or + pp_data.active_dodges or pp_data.active_barrel_rolls then + local pos = player:get_pos() pos.y = pos.y + player:get_properties().eye_height diff --git a/overrides.lua b/overrides.lua index e450752..39f6056 100644 --- a/overrides.lua +++ b/overrides.lua @@ -161,7 +161,12 @@ minetest.register_on_mods_loaded(function() local shield_data = data.shield -- If in the process of throwing, either dig, place, or item name is not the same then return the old function. - if throw_data or dropper:get_wielded_item():get_name() ~= name or (floor(control_bits / 128) % 2 ~= 1 and floor(control_bits / 256) % 2 ~= 1) then + if throw_data or dropper:get_wielded_item():get_name() ~= name or + (floor(control_bits / 128) % 2 ~= 1 and + floor(control_bits / 256) % 2 ~= 1 and + floor(control_bits / 512) % 2 ~= 1 and + floor(control_bits / 32) % 2 ~= 1) then + return old_on_drop(itemstack, dropper, pos) end diff --git a/player_events.lua b/player_events.lua index 7be01b7..5ecbae9 100644 --- a/player_events.lua +++ b/player_events.lua @@ -106,9 +106,7 @@ minetest.register_on_player_inventory_action(function(player) end end) -local function break_guard(player) - local name = player:get_player_name() - +local function break_guard(player, name) if not player_data or not player_data[name] then return end @@ -131,11 +129,15 @@ local function break_guard(player) end minetest.register_on_placenode(function(pos, newnode, placer) + local name = placer:get_player_name() + -- Break guard if player placed a node. - break_guard(placer) + break_guard(placer, name) end) minetest.register_on_dignode(function(pos, oldnode, digger) + local name = digger:get_player_name() + -- Break guard if player dug a node. - break_guard(digger) + break_guard(digger, name) end) \ No newline at end of file