Added the Termite buff for axes and the Cobble Eater buff for picks

master
Alexand(er|ra) Yst 2020-12-27 14:03:31 -08:00
parent fe41fefd8d
commit 39738ab9bc
4 changed files with 163 additions and 70 deletions

View File

@ -47,13 +47,13 @@ return {
aspen_sapling = "lumberjack",
flint = "lumberjack",
coral_skeleton = "toter",
acacia_bush_sapling = "lumberjack",
bush_sapling = "lumberjack",
acacia_bush_sapling = "termite",
bush_sapling = "termite",
tin_lump = "toter",
blueberries = "toter",
blueberry_bush_sapling = "lumberjack",
ice = "toter",
pine_bush_sapling = "lumberjack",
pine_bush_sapling = "termite",
dry_dirt = "toter",
},
fire_starter = {
@ -99,11 +99,11 @@ return {
diamond = "durable",
gold_lump = "rapid",
junglesapling = "rapid",
seed_cotton = "rapid",
seed_wheat = "rapid",
string = "rapid",
wheat = "rapid",
cotton = "rapid",
seed_cotton = "cobbleeater",
seed_wheat = "cobbleeater",
string = "cobbleeater",
wheat = "cobbleeater",
cotton = "cobbleeater",
pine_sapling = "rapid",
acacia_sapling = "rapid",
mushroom_brown = "rapid",

View File

@ -1,61 +0,0 @@
-- runes mod for Minetest
-- Copyright © 2020 Alex Yst <mailto:copyright@y.st>
-- This program is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Lesser General Public
-- License as published by the Free Software Foundation; either
-- version 2.1 of the License, or (at your option) any later version.
-- This software is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- Lesser General Public License for more details.
-- You should have received a copy of the GNU Lesser General Public
-- License along with this program. If not, see
-- <https://www.gnu.org./licenses/>.
local original_handle_node_drops
local force_drop = {}
for node, tool in next, {
["default:acacia_bush_leaves" ] = "runes:sword",
["default:acacia_leaves" ] = "runes:sword",
["default:aspen_leaves" ] = "runes:sword",
["default:blueberry_bush_leaves"] = "runes:sword",
["default:bush_leaves" ] = "runes:sword",
["default:gravel" ] = "runes:shovel",
["default:junglegrass" ] = "runes:sword",
["default:jungleleaves" ] = "runes:sword",
["default:leaves" ] = "runes:sword",
["default:pine_bush_needles" ] = "runes:sword",
["default:pine_needles" ] = "runes:sword",
} do
force_drop[node] = {
tool = tool,
drop = minetest.registered_nodes[node].drop.items[1].items[1],
}
end
liblevelup.register.startup_function(function()
original_handle_node_drops = minetest.handle_node_drops
function minetest.handle_node_drops(pos, drops, digger)
if drops.node_dug then
if force_drop[drops.node_dug] then
local tool = digger:get_wielded_item()
if force_drop[drops.node_dug].tool == tool:get_name()
and tool:get_meta():get("thirst") then
drops[1] = force_drop[drops.node_dug].drop
end
elseif drops[1] == "default:dirt" and drops.node_dug ~= "default:dirt" then
local tool = digger:get_wielded_item()
if tool:get_name() == "runes:shovel"
and tool:get_meta():get("transplanter") then
drops[1] = drops.node_dug
end
end
end
return original_handle_node_drops(pos, drops, digger)
end
end)

View File

@ -18,7 +18,6 @@
dofile(minetest.get_modpath("runes").."/runes.lua")
dofile(minetest.get_modpath("runes").."/tools.lua")
dofile(minetest.get_modpath("runes").."/tool_crafting.lua")
dofile(minetest.get_modpath("runes").."/buffs/thirst.lua")
dofile(minetest.get_modpath("runes").."/buffs/toter.lua")
dofile(minetest.get_modpath("runes").."/buffs/lumberjack.lua")
dofile(minetest.get_modpath("runes").."/debug.lua")

View File

@ -56,6 +56,8 @@ local buff_name = {
toter = S("Toter"),
transplanter = S("Transplanter"),
lumberjack = S("Lumberjack"),
termite = S("Termite"),
cobbleeater = S("Cobble Eater"),
}
local rune_element_modname = {
@ -124,6 +126,36 @@ local function add_colour(meta)
meta:set_string("color", colour)
end
-- Sometimes, a tool's description will need to be updated even when
-- not crafting it for the first time or repairing it. Originally,
-- creating the description was done in the crafting functions, but
-- when the Termite and Cobble Eater buffs were added, it had to be
-- separated out into its own function.
--
-- NOTE: Currently, duplicate copys of this functionality exists in the
-- crafting functions still. These copies are sort of deprecated at
-- this point, but they're also more efficient because they're so
-- entwined with the rest of what's going on that they optimise by
-- sharing work that then doesn't have to be done multiple times.
-- However, if there's ever another update to how the descriptions are
-- constructed, the duplicate functionality should not be updated with
-- it, but instead removed and replaced with a call to this function.
local function update_tool_description(tool)
local meta = tool:get_meta()
local description = minetest.registered_tools[tool:get_name()].description.."\nRepair count: "..meta:get_int("repair")
if meta:get_int("cobble_regen") ~= 0 then
description = description.." (Heal count: "..meta:get_int("cobble_regen")..")"
elseif meta:get_int("wood_regen") ~= 0 then
description = description.." (Heal count: "..meta:get_int("wood_regen")..")"
end
for buff, name in next, buff_name do
if meta:get(buff) then
description = description.."\n"..name.." ("..meta:get_int(buff)..")"
end
end
meta:set_string("description", description)
end
-- This function applies the initial buffs to a tool upon crafting.
local function generate_tool(tool_name, player_name, runes)
local tool = ItemStack("runes:"..tool_name)
@ -308,6 +340,24 @@ local function calculate_craft_result(itemstack, player, old_craft_grid, craft_i
local repair_count = meta0:get_int("repair") + meta1:get_int("repair") + 1
meta:set_int("repair", repair_count)
local description = minetest.registered_tools[tool_type].description.."\nRepair count: "..repair_count
-- Counters get added together, but not decremented from repair.
for counter, _ in next, {
cobble_regen = true,
wood_regen = true,
} do
local strength = meta0:get_int(counter) + meta1:get_int(counter)
if strength > 0 then
meta:set_int(counter, strength)
end
end
-- If the tool has been repaired via the Termite or Cobble Eater buffs,
-- we'll append that repair information to the normal repair
-- information.
if meta:get_int("cobble_regen") ~= 0 then
description = description.." (Heal count: "..meta:get_int("cobble_regen")..")"
elseif meta:get_int("wood_regen") ~= 0 then
description = description.." (Heal count: "..meta:get_int("wood_regen")..")"
end
local buff_durability = false
local buff_rapid = false
-- Merge the buffs, then wear them by subtracting one from each. If any
@ -529,3 +579,108 @@ minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv
return cache1[player:get_player_name()]
end
end)
-----------------------------------------------------------------------
-- Everything below this line was previously in its own file, but had
-- to be moved here so it'd have access to update_tool_description().
-- Nothing below this line should be moved above it.
-----------------------------------------------------------------------
local original_handle_node_drops
local force_drop = {}
for node, tool in next, {
["default:acacia_bush_leaves" ] = "runes:sword",
["default:acacia_leaves" ] = "runes:sword",
["default:aspen_leaves" ] = "runes:sword",
["default:blueberry_bush_leaves"] = "runes:sword",
["default:bush_leaves" ] = "runes:sword",
["default:gravel" ] = "runes:shovel",
["default:junglegrass" ] = "runes:sword",
["default:jungleleaves" ] = "runes:sword",
["default:leaves" ] = "runes:sword",
["default:pine_bush_needles" ] = "runes:sword",
["default:pine_needles" ] = "runes:sword",
} do
force_drop[node] = {
tool = tool,
drop = minetest.registered_nodes[node].drop.items[1].items[1],
}
end
local termite_regen = 1040
local cobbleeater_regen = 2253
local logs = {
["default:acacia_tree"] = true,
["default:aspen_tree"] = true,
["default:jungletree"] = true,
["default:pine_tree"] = true,
["default:tree"] = true,
}
local stems = {
["default:acacia_bush_stem"] = true,
["default:bush_stem"] = true,
["default:pine_bush_stem"] = true,
}
liblevelup.register.startup_function(function()
original_handle_node_drops = minetest.handle_node_drops
function minetest.handle_node_drops(pos, drops, digger)
if drops.node_dug then
if force_drop[drops.node_dug] then
local tool = digger:get_wielded_item()
if force_drop[drops.node_dug].tool == tool:get_name()
and tool:get_meta():get("thirst") then
drops[1] = force_drop[drops.node_dug].drop
end
elseif drops[1] == "default:dirt" and drops.node_dug ~= "default:dirt" then
local tool = digger:get_wielded_item()
if tool:get_name() == "runes:shovel"
and tool:get_meta():get("transplanter") then
drops[1] = drops.node_dug
end
elseif drops[1] == "default:cobble" then
local tool = digger:get_wielded_item()
if tool:get_name() == "runes:pick"
and tool:get_meta():get("cobbleeater") then
if tool:get_wear() >= cobbleeater_regen then
local meta = tool:get_meta()
drops[1] = nil
tool:add_wear(-cobbleeater_regen)
meta:set_int("cobble_regen", meta:get_int("cobble_regen") + 1)
update_tool_description(tool)
digger:set_wielded_item(tool)
end
end
elseif logs[drops[1]] or stems[drops[1]] then
local tool = digger:get_wielded_item()
if tool:get_name() == "runes:axe"
and tool:get_meta():get("termite") then
local wear = tool:get_wear()
local meta = tool:get_meta()
if logs[drops[1]] then
if wear >= termite_regen * 4 then
drops[1] = nil
tool:add_wear(-termite_regen * 4)
meta:set_int("wood_regen", meta:get_int("wood_regen") + 4)
update_tool_description(tool)
digger:set_wielded_item(tool)
end
else -- must be stems[drop[1]]
if wear >= termite_regen then
drops[1] = nil
tool:add_wear(-termite_regen)
meta:set_int("wood_regen", meta:get_int("wood_regen") + 1)
update_tool_description(tool)
digger:set_wielded_item(tool)
end
end
end
end
end
return original_handle_node_drops(pos, drops, digger)
end
end)