From 10881d4211002b088a07623e69bfe05b1c857647 Mon Sep 17 00:00:00 2001 From: Apelta <54854228+TSafa-23@users.noreply.github.com> Date: Tue, 5 Jan 2021 22:14:55 -0600 Subject: [PATCH] Fix antisabotage bugs and make to work with paxel(#731) * Fix crucial bugs with antisabotage Fix possible crashes, infinite items, and any related issues * Make sabotage into function to be used with paxel * Fix paxel to work with antisabotage * Fix whitespace for luacheck * Update mods/pvp/antisabotage/init.lua Remove unnecessary newline Co-authored-by: David Leal * Update function * Update function name * Add check for antisabotage * Remove whitespace for luacheck * Add antisabotage as an optional dependency * Remove more whitespace Co-authored-by: David Leal * Fix optional depends dev wiki lied to me :( Co-authored-by: David Leal * Fix up a comment P.1 * Move a line in mod.conf * Fix up comments and spacing Co-authored-by: David Leal Co-authored-by: LoneWolfHT --- mods/ctf/ctf_classes/medic.lua | 8 +++++++- mods/ctf/ctf_classes/mod.conf | 3 ++- mods/pvp/antisabotage/init.lua | 23 +++++++++++++++++------ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/mods/ctf/ctf_classes/medic.lua b/mods/ctf/ctf_classes/medic.lua index 54fb841..561bdaa 100644 --- a/mods/ctf/ctf_classes/medic.lua +++ b/mods/ctf/ctf_classes/medic.lua @@ -151,9 +151,15 @@ local function remove_pillar(pos, pname) local name = minetest.get_node(pos).name if name:find("default") and isdiggable(name) then + local player = minetest.get_player_by_name(pname) + + if minetest.get_modpath("antisabotage") then + -- Fix paxel being capable of mining blocks under teammates + if antisabotage.is_sabotage(pos, minetest.get_node(pos), player) then return end + end + minetest.dig_node(pos) - local player = minetest.get_player_by_name(pname) if player and diggers[pname] and type(diggers[pname]) ~= "table" then if vector.distance(player:get_pos(), pos) <= DIG_DIST_LIMIT then pos.y = pos.y + 1 diff --git a/mods/ctf/ctf_classes/mod.conf b/mods/ctf/ctf_classes/mod.conf index c60fda3..a933eb0 100644 --- a/mods/ctf/ctf_classes/mod.conf +++ b/mods/ctf/ctf_classes/mod.conf @@ -1,3 +1,4 @@ name = ctf_classes -depends = ctf, ctf_flag, ctf_colors, ctf_map_core, ctf_stats, ctf_bandages, physics, shooter, hpregen, give_initial_stuff, dropondie, crafting, sniper_rifles, grenades, furnace, ctf_respawn_immunity, ctf_marker, ctf_match description = Adds classes, including knight, shooter, and medic +depends = ctf, ctf_flag, ctf_colors, ctf_map_core, ctf_stats, ctf_bandages, physics, shooter, hpregen, give_initial_stuff, dropondie, crafting, sniper_rifles, grenades, furnace, ctf_respawn_immunity, ctf_marker, ctf_match +optional_depends = antisabotage diff --git a/mods/pvp/antisabotage/init.lua b/mods/pvp/antisabotage/init.lua index be1d6c8..cd8f2f1 100644 --- a/mods/pvp/antisabotage/init.lua +++ b/mods/pvp/antisabotage/init.lua @@ -1,9 +1,9 @@ --- Code by Apelta. Mutelated by Lone_Wolf - -minetest.register_on_dignode(function(pos, oldnode, digger) - if not digger:is_player() then return end +-- Code by Apelta. Mutelated by Lone_Wolf. Mutelated again by Apelta. +antisabotage = {} +function antisabotage.is_sabotage(pos, oldnode, digger) -- used for paxel local dname = digger:get_player_name() + for _, player in pairs(minetest.get_connected_players()) do local name = player:get_player_name() @@ -12,10 +12,21 @@ minetest.register_on_dignode(function(pos, oldnode, digger) if math.floor(player_pos.y) == pos.y and vector.distance(player_pos, pos) <= 1.5 then minetest.set_node(pos, oldnode) - digger:get_inventory():remove_item("main", ItemStack(oldnode)) + + -- Remove all node drops + for _, item in pairs(minetest.get_node_drops(oldnode)) do + digger:get_inventory():remove_item("main", ItemStack(item)) + end + minetest.chat_send_player(dname, "You can't mine blocks under your teammates!") - return + return true end end end +end + +minetest.register_on_dignode(function(pos, oldnode, digger) + if not digger:is_player() then return end + + antisabotage.is_sabotage(pos, oldnode, digger) end)