Skip to content

Commit

Permalink
Add a new setting to auto-trash stone tools when you pick up better o…
Browse files Browse the repository at this point in the history
…nes (#1251)

* Update player.lua

Add a new setting to auto-trash stone pickaxes when you pick up a better pickaxe

* Update player.lua

---------

Co-authored-by: LoneWolfHT <[email protected]>
  • Loading branch information
HobbitPower and LoneWolfHT authored Dec 5, 2023
1 parent 2c3c6f4 commit 296ad48
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions mods/ctf/ctf_modebase/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ ctf_settings.register("auto_trash_stone_swords", {
default = "false"
})

ctf_settings.register("auto_trash_stone_tools", {
type = "bool",
label = "Auto-trash stone tools when you pick up a better one",
description = "Only triggers when picking up tools from the ground",
default = "false"
})

local simplify_for_saved_stuff = function(iname)
if not iname or iname == "" then return iname end

Expand Down Expand Up @@ -212,10 +219,16 @@ minetest.register_on_item_pickup(function(itemstack, picker)
local cprio = func(compare)

if cprio and cprio < priority then
local item, type = simplify_for_saved_stuff(compare:get_name())
inv:set_stack("main", i, itemstack)

if compare:get_name() == "ctf_melee:sword_stone" and
ctf_settings.get(picker, "auto_trash_stone_swords") == "true" then
if item == "sword" and type == "stone" and
ctf_settings.get(picker, "auto_trash_stone_swords") == "true" then
return ItemStack("")
end

if item ~= "sword" and type == "stone" and
ctf_settings.get(picker, "auto_trash_stone_tools") == "true" then
return ItemStack("")
else
local result = inv:add_item("main", compare):get_count()
Expand All @@ -224,14 +237,12 @@ minetest.register_on_item_pickup(function(itemstack, picker)
return ItemStack("")
else
compare:set_count(result)

return compare
end
end
end
end
end

break -- We already found a place for it, don't check for one held by a different item type
end
end
Expand Down

0 comments on commit 296ad48

Please sign in to comment.