Remove undecay/unpreserve group; use tool callbacks everywhere
This commit is contained in:
parent
985bebb6f2
commit
42e96066b3
@ -70,13 +70,8 @@ end
|
|||||||
local function register_unpreserve(nodename,od,def)
|
local function register_unpreserve(nodename,od,def)
|
||||||
local nd = table.copy(od)
|
local nd = table.copy(od)
|
||||||
nd.description = (def.preserved_description or S("Preserved ") )..nd.description
|
nd.description = (def.preserved_description or S("Preserved ") )..nd.description
|
||||||
nd._on_axe_place = function(itemstack, clicker, pointed_thing)
|
nd["_on_"..def.unpreserve_tool.."_place"] = function(itemstack, clicker, pointed_thing)
|
||||||
if minetest.get_item_group(itemstack:get_name(),def.unpreserve_group) == 0 then
|
if pointed_thing then
|
||||||
if od._on_axe_place then return od._on_axe_place(itemstack, clicker, pointed_thing) end
|
|
||||||
if minetest.item_place_node(itemstack, clicker, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.under,vector.offset(clicker:get_pos(),0,1,0)))) and not minetest.is_creative_enabled(clicker:get_player_name()) then
|
|
||||||
itemstack:take_item()
|
|
||||||
end
|
|
||||||
elseif pointed_thing and minetest.get_item_group(itemstack:get_name(),def.unpreserve_group) > 0 then
|
|
||||||
return unpreserve(itemstack, clicker, pointed_thing)
|
return unpreserve(itemstack, clicker, pointed_thing)
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
@ -85,15 +80,11 @@ local function register_unpreserve(nodename,od,def)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function register_undecay(nodename,def)
|
local function register_undecay(nodename,def)
|
||||||
local old_os = minetest.registered_items[nodename]._on_axe_place
|
local old_os = minetest.registered_items[nodename]["_on_"..def.undecay_tool.."_place"]
|
||||||
minetest.override_item(nodename,{
|
minetest.override_item(nodename,{
|
||||||
_on_axe_place = function(itemstack, clicker, pointed_thing)
|
["_on_"..def.undecay_tool.."_place"] = function(itemstack, clicker, pointed_thing)
|
||||||
if minetest.get_item_group(itemstack:get_name(),def.undecay_group) == 0 then
|
if old_os then itemstack = old_os(itemstack, clicker, pointed_thing) end
|
||||||
if old_os then return old_os(itemstack, clicker, pointed_thing) end
|
if pointed_thing then
|
||||||
if minetest.item_place_node(itemstack, clicker, pointed_thing) and not minetest.is_creative_enabled(clicker:get_player_name()) then
|
|
||||||
itemstack:take_item()
|
|
||||||
end
|
|
||||||
elseif minetest.get_item_group(itemstack:get_name(),def.undecay_group) > 0 then
|
|
||||||
return undecay(itemstack, clicker, pointed_thing)
|
return undecay(itemstack, clicker, pointed_thing)
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
@ -130,12 +121,10 @@ end
|
|||||||
-- --optional: description of the preserved variant will be prepended with this. Default: "Preserved"
|
-- --optional: description of the preserved variant will be prepended with this. Default: "Preserved"
|
||||||
-- preserve_group = "preserves_copper",
|
-- preserve_group = "preserves_copper",
|
||||||
-- --optional: item group that when used on the node will preserve this state
|
-- --optional: item group that when used on the node will preserve this state
|
||||||
-- unpreserve_group = "axe",
|
-- unpreserve_tool = "axe",
|
||||||
-- --optional: item group that when used on the node will unpreserve a preserved node.
|
-- --optional: tool that when used on the node will unpreserve a preserved node. (axe|shovel|sword|shears|pick)
|
||||||
-- decay_group = "oxidizes_copper",
|
-- undecay_tool = "axe",
|
||||||
-- --optional: item group that when used on the node will decay the node further.
|
-- --optional: tool that when used on the node will undecay the node to the previous stage. (axe|shovel|sword|shears|pick)
|
||||||
-- undecay_group = "axe",
|
|
||||||
-- --optional: item group that when used on the node will undecay the node to the previous stage.
|
|
||||||
-- nodes = { --order is significant
|
-- nodes = { --order is significant
|
||||||
-- "mcl_copper:block",
|
-- "mcl_copper:block",
|
||||||
-- "mcl_copper:block_exposed",
|
-- "mcl_copper:block_exposed",
|
||||||
@ -155,11 +144,11 @@ function mcl_copper.register_decaychain(name,def)
|
|||||||
nodename_chains[v] = name
|
nodename_chains[v] = name
|
||||||
table.insert(decay_nodes,v)
|
table.insert(decay_nodes,v)
|
||||||
|
|
||||||
if k < #def.nodes and def.unpreserve_group then --exclude last entry in chain - can't decay further, hence no preservation
|
if k < #def.nodes and def.unpreserve_tool then --exclude last entry in chain - can't decay further, hence no preservation
|
||||||
register_unpreserve(v,od,def)
|
register_unpreserve(v,od,def)
|
||||||
end
|
end
|
||||||
|
|
||||||
if k > 1 and def.undecay_group then --exclude first entry in chain - can't be undecayed further
|
if k > 1 and def.undecay_tool then --exclude first entry in chain - can't be undecayed further
|
||||||
register_undecay(v,def)
|
register_undecay(v,def)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -9,8 +9,8 @@ dofile(path .. "/crafting.lua")
|
|||||||
mcl_copper.register_decaychain("copper",{
|
mcl_copper.register_decaychain("copper",{
|
||||||
preserved_description = "Waxed ",
|
preserved_description = "Waxed ",
|
||||||
preserve_group = "preserves_copper",
|
preserve_group = "preserves_copper",
|
||||||
unpreserve_group = "axe",
|
unpreserve_tool = "axe",
|
||||||
undecay_group = "axe",
|
undecay_tool = "axe",
|
||||||
nodes = { --order is significant
|
nodes = { --order is significant
|
||||||
"mcl_copper:block",
|
"mcl_copper:block",
|
||||||
"mcl_copper:block_exposed",
|
"mcl_copper:block_exposed",
|
||||||
@ -22,8 +22,8 @@ mcl_copper.register_decaychain("copper",{
|
|||||||
mcl_copper.register_decaychain("cut_copper",{
|
mcl_copper.register_decaychain("cut_copper",{
|
||||||
preserved_description = "Waxed ",
|
preserved_description = "Waxed ",
|
||||||
preserve_group = "preserves_copper",
|
preserve_group = "preserves_copper",
|
||||||
unpreserve_group = "axe",
|
unpreserve_tool = "axe",
|
||||||
undecay_group = "axe",
|
undecay_tool = "axe",
|
||||||
nodes = { --order is significant
|
nodes = { --order is significant
|
||||||
"mcl_copper:block_cut",
|
"mcl_copper:block_cut",
|
||||||
"mcl_copper:block_exposed_cut",
|
"mcl_copper:block_exposed_cut",
|
||||||
@ -38,8 +38,8 @@ for _,v in pairs({"stair","slab"}) do
|
|||||||
mcl_copper.register_decaychain("cut_copper_"..v,{
|
mcl_copper.register_decaychain("cut_copper_"..v,{
|
||||||
preserved_description = "Waxed ",
|
preserved_description = "Waxed ",
|
||||||
preserve_group = "preserves_copper",
|
preserve_group = "preserves_copper",
|
||||||
unpreserve_group = "axe",
|
unpreserve_tool = "axe",
|
||||||
undecay_group = "axe",
|
undecay_tool = "axe",
|
||||||
nodes = { --order is significant
|
nodes = { --order is significant
|
||||||
"mcl_stairs:"..v.."_copper_cut",
|
"mcl_stairs:"..v.."_copper_cut",
|
||||||
"mcl_stairs:"..v.."_copper_exposed_cut",
|
"mcl_stairs:"..v.."_copper_exposed_cut",
|
||||||
@ -53,8 +53,8 @@ for _,v in pairs({"inner","outer"}) do
|
|||||||
mcl_copper.register_decaychain("cut_copper_stair_"..v,{
|
mcl_copper.register_decaychain("cut_copper_stair_"..v,{
|
||||||
preserved_description = "Waxed ",
|
preserved_description = "Waxed ",
|
||||||
preserve_group = "preserves_copper",
|
preserve_group = "preserves_copper",
|
||||||
unpreserve_group = "axe",
|
unpreserve_tool = "axe",
|
||||||
undecay_group = "axe",
|
undecay_tool = "axe",
|
||||||
nodes = { --order is significant
|
nodes = { --order is significant
|
||||||
"mcl_stairs:stair_copper_cut_"..v,
|
"mcl_stairs:stair_copper_cut_"..v,
|
||||||
"mcl_stairs:stair_copper_exposed_cut_"..v,
|
"mcl_stairs:stair_copper_exposed_cut_"..v,
|
||||||
@ -67,8 +67,8 @@ for _,v in pairs({"top","double"}) do
|
|||||||
mcl_copper.register_decaychain("cut_copper_slab_"..v,{
|
mcl_copper.register_decaychain("cut_copper_slab_"..v,{
|
||||||
preserved_description = "Waxed ",
|
preserved_description = "Waxed ",
|
||||||
preserve_group = "preserves_copper",
|
preserve_group = "preserves_copper",
|
||||||
unpreserve_group = "axe",
|
unpreserve_tool = "axe",
|
||||||
undecay_group = "axe",
|
undecay_tool = "axe",
|
||||||
nodes = { --order is significant
|
nodes = { --order is significant
|
||||||
"mcl_stairs:slab_copper_cut_"..v,
|
"mcl_stairs:slab_copper_cut_"..v,
|
||||||
"mcl_stairs:slab_copper_exposed_cut_"..v,
|
"mcl_stairs:slab_copper_exposed_cut_"..v,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user