Add enchanted hammers
This commit is contained in:
parent
2a2cfa4113
commit
4832eb0470
@ -1,5 +1,7 @@
|
|||||||
-- Register enchanted tools.
|
-- Register enchanted tools.
|
||||||
|
|
||||||
|
local S = minetest.get_translator("xdecor")
|
||||||
|
|
||||||
-- Number of uses for the (normal) steel hoe from Minetest Game (as of 01/12/20224)
|
-- Number of uses for the (normal) steel hoe from Minetest Game (as of 01/12/20224)
|
||||||
-- This is technically redundant because we cannot access that number
|
-- This is technically redundant because we cannot access that number
|
||||||
-- directly, but it's unlikely to change in future because Minetest Game is
|
-- directly, but it's unlikely to change in future because Minetest Game is
|
||||||
@ -9,6 +11,13 @@ local STEEL_HOE_USES = 500
|
|||||||
-- Modifier of the steel hoe uses for the enchanted steel hoe
|
-- Modifier of the steel hoe uses for the enchanted steel hoe
|
||||||
local STEEL_HOE_USES_MODIFIER = 3
|
local STEEL_HOE_USES_MODIFIER = 3
|
||||||
|
|
||||||
|
-- Multiplies by much faster the fast hammer repairs
|
||||||
|
local HAMMER_FAST_MODIFIER = 1.3
|
||||||
|
|
||||||
|
-- Reduces the wear taken by the hammer for a single repair step
|
||||||
|
-- (absolute value)
|
||||||
|
local HAMMER_DURABLE_MODIFIER = 100
|
||||||
|
|
||||||
-- Register enchantments for default tools from Minetest Game
|
-- Register enchantments for default tools from Minetest Game
|
||||||
local materials = {"steel", "bronze", "mese", "diamond"}
|
local materials = {"steel", "bronze", "mese", "diamond"}
|
||||||
local tooltypes = {
|
local tooltypes = {
|
||||||
@ -48,3 +57,47 @@ if farming.register_hoe then
|
|||||||
durable = "farming:enchanted_hoe_steel_durable",
|
durable = "farming:enchanted_hoe_steel_durable",
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Register enchanted hammer (more durbility and efficiency)
|
||||||
|
local hammerdef = minetest.registered_items["xdecor:hammer"]
|
||||||
|
if hammerdef then
|
||||||
|
local hitem = ItemStack("xdecor:hammer")
|
||||||
|
local hdesc = hitem:get_short_description() or "xdecor:hammer"
|
||||||
|
local repair = hammerdef._xdecor_hammer_repair
|
||||||
|
local repair_cost = hammerdef._xdecor_hammer_repair_cost
|
||||||
|
|
||||||
|
-- Durable hammer (reduces wear taken by each repair step)
|
||||||
|
local d_repair_cost_modified = repair_cost - HAMMER_DURABLE_MODIFIER
|
||||||
|
local d_percent = math.round(100 - d_repair_cost_modified/repair_cost * 100)
|
||||||
|
local d_ehdesc, d_ehsdesc = xdecor.enchant_description(hdesc, "durable", d_percent)
|
||||||
|
|
||||||
|
xdecor.register_hammer("xdecor:enchanted_hammer_durable", {
|
||||||
|
description = d_ehdesc,
|
||||||
|
short_description = d_ehsdesc,
|
||||||
|
image = xdecor.enchant_texture("xdecor_hammer.png"),
|
||||||
|
repair_cost = d_repair_cost_modified,
|
||||||
|
groups = {repair_hammer = 1, not_in_creative_inventory = 1}
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Fast hammer (increases both repair amount and repair cost per
|
||||||
|
-- repair step by an equal amount)
|
||||||
|
local f_repair_modified = math.round(repair * HAMMER_FAST_MODIFIER)
|
||||||
|
local repair_diff = f_repair_modified - repair
|
||||||
|
local f_repair_cost_modified = repair_cost + repair_diff
|
||||||
|
local f_percent = math.round(HAMMER_FAST_MODIFIER * 100 - 100)
|
||||||
|
local f_ehdesc, f_ehsdesc = xdecor.enchant_description(hdesc, "fast", f_percent)
|
||||||
|
|
||||||
|
xdecor.register_hammer("xdecor:enchanted_hammer_fast", {
|
||||||
|
description = f_ehdesc,
|
||||||
|
short_description = f_ehsdesc,
|
||||||
|
image = xdecor.enchant_texture("xdecor_hammer.png"),
|
||||||
|
repair = f_repair_modified,
|
||||||
|
repair_cost = f_repair_cost_modified,
|
||||||
|
groups = {repair_hammer = 1, not_in_creative_inventory = 1}
|
||||||
|
})
|
||||||
|
|
||||||
|
xdecor.register_custom_enchantable_tool("xdecor:hammer", {
|
||||||
|
durable = "xdecor:enchanted_hammer_durable",
|
||||||
|
fast = "xdecor:enchanted_hammer_fast",
|
||||||
|
})
|
||||||
|
end
|
||||||
|
@ -7,6 +7,9 @@ local min, ceil = math.min, math.ceil
|
|||||||
local S = minetest.get_translator("xdecor")
|
local S = minetest.get_translator("xdecor")
|
||||||
local FS = function(...) return minetest.formspec_escape(S(...)) end
|
local FS = function(...) return minetest.formspec_escape(S(...)) end
|
||||||
|
|
||||||
|
local DEFAULT_HAMMER_REPAIR = 500
|
||||||
|
local DEFAULT_HAMMER_REPAIR_COST = 700
|
||||||
|
|
||||||
|
|
||||||
-- Nodeboxes definitions
|
-- Nodeboxes definitions
|
||||||
workbench.defs = {
|
workbench.defs = {
|
||||||
@ -211,9 +214,11 @@ function workbench.timer(pos)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local hammerdef = hammer:get_definition()
|
||||||
|
|
||||||
-- Tool's wearing range: 0-65535; 0 = new condition
|
-- Tool's wearing range: 0-65535; 0 = new condition
|
||||||
tool:add_wear(-500)
|
tool:add_wear(-hammerdef._xdecor_hammer_repair or DEFAULT_HAMMER_REPAIR)
|
||||||
hammer:add_wear(700)
|
hammer:add_wear(hammerdef._xdecor_hammer_repair_cost or DEFAULT_HAMMER_REPAIR_COST)
|
||||||
|
|
||||||
inv:set_stack("tool", 1, tool)
|
inv:set_stack("tool", 1, tool)
|
||||||
inv:set_stack("hammer", 1, hammer)
|
inv:set_stack("hammer", 1, hammer)
|
||||||
@ -225,7 +230,7 @@ function workbench.allow_put(pos, listname, index, stack, player)
|
|||||||
local stackname = stack:get_name()
|
local stackname = stack:get_name()
|
||||||
if (listname == "tool" and workbench:repairable(stackname)) or
|
if (listname == "tool" and workbench:repairable(stackname)) or
|
||||||
(listname == "input" and workbench:cuttable(stackname)) or
|
(listname == "input" and workbench:cuttable(stackname)) or
|
||||||
(listname == "hammer" and stackname == "xdecor:hammer") or
|
(listname == "hammer" and minetest.get_item_group(stackname, "repair_hammer") == 1) or
|
||||||
listname == "storage" then
|
listname == "storage" then
|
||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
end
|
end
|
||||||
@ -250,7 +255,7 @@ function workbench.allow_move(pos, from_list, from_index, to_list, to_index, cou
|
|||||||
elseif (to_list == "hammer" and from_list == "tool") or (to_list == "tool" and from_list == "hammer") then
|
elseif (to_list == "hammer" and from_list == "tool") or (to_list == "tool" and from_list == "hammer") then
|
||||||
local inv = minetest.get_inventory({type="node", pos=pos})
|
local inv = minetest.get_inventory({type="node", pos=pos})
|
||||||
local stack = inv:get_stack(from_list, from_index)
|
local stack = inv:get_stack(from_list, from_index)
|
||||||
if stack:get_name() == "xdecor:hammer" then
|
if minetest.get_item_group(stack:get_name(), "repair_hammer") == 1 then
|
||||||
return count
|
return count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -463,16 +468,29 @@ function workbench:register_special_cut(nodename, cutlist)
|
|||||||
special_cuts[nodename] = cutlist
|
special_cuts[nodename] = cutlist
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Craft items
|
-- Register hammer
|
||||||
|
|
||||||
minetest.register_tool("xdecor:hammer", {
|
function xdecor.register_hammer(name, def)
|
||||||
description = S("Hammer"),
|
minetest.register_tool(name, {
|
||||||
|
description = def.description,
|
||||||
_tt_help = S("Repairs tools at the work bench"),
|
_tt_help = S("Repairs tools at the work bench"),
|
||||||
inventory_image = "xdecor_hammer.png",
|
inventory_image = def.image,
|
||||||
wield_image = "xdecor_hammer.png",
|
wield_image = def.image,
|
||||||
on_use = function() do
|
on_use = function() do
|
||||||
return end
|
return end
|
||||||
end
|
end,
|
||||||
|
groups = def.groups,
|
||||||
|
_xdecor_hammer_repair = def.repair or DEFAULT_HAMMER_REPAIR,
|
||||||
|
_xdecor_hammer_repair_cost = def.repair_cost or DEFAULT_HAMMER_REPAIR_COST,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
xdecor.register_hammer("xdecor:hammer", {
|
||||||
|
description = S("Hammer"),
|
||||||
|
image = "xdecor_hammer.png",
|
||||||
|
groups = { repair_hammer = 1 },
|
||||||
|
repair = DEFAULT_HAMMER_REPAIR,
|
||||||
|
repair_cost = DEFAULT_HAMMER_REPAIR_COST,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Recipes
|
-- Recipes
|
||||||
|
Loading…
Reference in New Issue
Block a user