From 8c703f1352b6356f1f5237db16bed2d78eea0b9d Mon Sep 17 00:00:00 2001 From: Michieal Date: Mon, 30 Jan 2023 18:27:53 -0500 Subject: [PATCH] Refactored out "varient" in foavor of "variant". Set up a basic "on_place" function. Made _mcl_copper_waxed_variant and _mcl_copper_unwaxed_variant node parameters so that the waxing_copper_block and scraping_copper_block functions can be made generic. Adjusted said functions to look first for the variants, and added in protection checks for the blocks --- mods/ITEMS/mcl_copper/functions.lua | 115 ++++++++++++++++++++-------- mods/ITEMS/mcl_copper/nodes.lua | 29 +++++-- 2 files changed, 105 insertions(+), 39 deletions(-) diff --git a/mods/ITEMS/mcl_copper/functions.lua b/mods/ITEMS/mcl_copper/functions.lua index 81dfdb69d..348b9a995 100644 --- a/mods/ITEMS/mcl_copper/functions.lua +++ b/mods/ITEMS/mcl_copper/functions.lua @@ -1,33 +1,84 @@ --local deepslate_mod = minetest.get_modpath("mcl_deepslate") +-- a basic on_place() +function mcl_copper.on_place (itemstack, placer, pointed_thing) + if pointed_thing.type ~= "node" then + return itemstack + end + local node = minetest.get_node(pointed_thing.under) + local pos = pointed_thing.under + local node_name = node.name + + if mcl_util.check_position_protection(pos, placer) then + return itemstack + end + + -- Use pointed node's on_rightclick function first, if present + local new_stack = mcl_util.call_on_rightclick(itemstack, placer, pointed_thing) + if new_stack then + return new_stack + end + + local placed = ItemStack(itemstack:get_name()) + if not minetest.is_creative_enabled(placer:get_player_name()) then + itemstack:take_item() + end + minetest.item_place(placed, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under))) + + return itemstack + +end + local function register_oxidation_abm(abm_name, node_name, oxidized_variant) minetest.register_abm({ label = abm_name, - nodenames = {node_name}, + nodenames = { node_name }, interval = 500, chance = 3, action = function(pos, node) - minetest.swap_node(pos, {name = oxidized_variant, param2 = node.param2}) + minetest.swap_node(pos, { name = oxidized_variant, param2 = node.param2 }) end, }) end function waxing_copper_block(pos, node, player, itemstack, convert_to) if itemstack:get_name() == "mcl_honey:honeycomb" then - node.name = convert_to + -- prevent modification of protected nodes. + if mcl_util.check_position_protection(pos, player) then + return + end + + local def = minetest.registered_nodes(node.name) + + if def and def._mcl_copper_waxed_variant then + node.name = def._mcl_copper_waxed_variant + end + minetest.set_node(pos, node) awards.unlock(player:get_player_name(), "mcl:wax_on") if not minetest.is_creative_enabled(player:get_player_name()) then itemstack:take_item() end + return itemstack + else - return true + return -- changed to work with mcl_util.call_on_rightclick() end end function scraping_copper_block(pos, node, player, itemstack, convert_to) if itemstack:get_name():find("axe") then - node.name = convert_to + -- prevent modification of protected nodes. + if mcl_util.check_position_protection(pos, player) then + return + end + + local def = minetest.registered_nodes(node.name) + + if def and def._mcl_copper_unwaxed_variant then + node.name = def._mcl_copper_unwaxed_variant + end + minetest.set_node(pos, node) awards.unlock(player:get_player_name(), "mcl:wax_off") if not minetest.is_creative_enabled(player:get_player_name()) then @@ -36,7 +87,7 @@ function scraping_copper_block(pos, node, player, itemstack, convert_to) itemstack:add_wear(wear) end else - return true + return end end @@ -164,41 +215,41 @@ if not deepslate_mod then end --]] local block_oxidation = { - {"", "_exposed"}, - {"_cut", "_exposed_cut"}, - {"_exposed", "_weathered"}, - {"_exposed_cut", "_weathered_cut"}, - {"_weathered", "_oxidized"}, - {"_weathered_cut", "_oxidized_cut"} + { "", "_exposed" }, + { "_cut", "_exposed_cut" }, + { "_exposed", "_weathered" }, + { "_exposed_cut", "_weathered_cut" }, + { "_weathered", "_oxidized" }, + { "_weathered_cut", "_oxidized_cut" } } local stair_oxidation = { - {"slab", "cut", "exposed_cut"}, - {"slab", "exposed_cut", "weathered_cut"}, - {"slab", "weathered_cut", "oxidized_cut"}, - {"slab", "cut_top", "exposed_cut_top"}, - {"slab", "exposed_cut_top", "weathered_cut_top"}, - {"slab", "weathered_cut_top", "oxidized_cut_double"}, - {"slab", "cut_double", "exposed_cut_double"}, - {"slab", "exposed_cut_double", "weathered_cut_double"}, - {"slab", "weathered_cut_double", "oxidized_cut_double"}, - {"stair", "cut", "exposed_cut"}, - {"stair", "exposed_cut", "weathered_cut"}, - {"stair", "weathered_cut", "oxidized_cut"}, - {"stair", "cut_inner", "exposed_cut_inner"}, - {"stair", "exposed_cut_inner", "weathered_cut_inner"}, - {"stair", "weathered_cut_inner", "oxidized_cut_inner"}, - {"stair", "cut_outer", "exposed_cut_outer"}, - {"stair", "exposed_cut_outer", "weathered_cut_outer"}, - {"stair", "weathered_cut_outer", "oxidized_cut_outer"} + { "slab", "cut", "exposed_cut" }, + { "slab", "exposed_cut", "weathered_cut" }, + { "slab", "weathered_cut", "oxidized_cut" }, + { "slab", "cut_top", "exposed_cut_top" }, + { "slab", "exposed_cut_top", "weathered_cut_top" }, + { "slab", "weathered_cut_top", "oxidized_cut_double" }, + { "slab", "cut_double", "exposed_cut_double" }, + { "slab", "exposed_cut_double", "weathered_cut_double" }, + { "slab", "weathered_cut_double", "oxidized_cut_double" }, + { "stair", "cut", "exposed_cut" }, + { "stair", "exposed_cut", "weathered_cut" }, + { "stair", "weathered_cut", "oxidized_cut" }, + { "stair", "cut_inner", "exposed_cut_inner" }, + { "stair", "exposed_cut_inner", "weathered_cut_inner" }, + { "stair", "weathered_cut_inner", "oxidized_cut_inner" }, + { "stair", "cut_outer", "exposed_cut_outer" }, + { "stair", "exposed_cut_outer", "weathered_cut_outer" }, + { "stair", "weathered_cut_outer", "oxidized_cut_outer" } } for _, b in pairs(block_oxidation) do - register_oxidation_abm("Copper oxidation", "mcl_copper:block"..b[1], "mcl_copper:block"..b[2]) + register_oxidation_abm("Copper oxidation", "mcl_copper:block" .. b[1], "mcl_copper:block" .. b[2]) end for _, s in pairs(stair_oxidation) do - register_oxidation_abm("Copper oxidation", "mcl_stairs:"..s[1].."_copper_"..s[2], "mcl_stairs:"..s[1].."_copper_"..s[3]) + register_oxidation_abm("Copper oxidation", "mcl_stairs:" .. s[1] .. "_copper_" .. s[2], "mcl_stairs:" .. s[1] .. "_copper_" .. s[3]) end --local axes = {"wood", "stone", "iron", "gold", "diamond"} diff --git a/mods/ITEMS/mcl_copper/nodes.lua b/mods/ITEMS/mcl_copper/nodes.lua index 6c498f9f6..ecc80a0f2 100644 --- a/mods/ITEMS/mcl_copper/nodes.lua +++ b/mods/ITEMS/mcl_copper/nodes.lua @@ -12,7 +12,6 @@ minetest.register_node("mcl_copper:stone_with_copper", { _mcl_hardness = 3, _mcl_silk_touch_drop = true, _mcl_fortune_drop = mcl_core.fortune_drop_ore, - }) minetest.register_node("mcl_copper:block_raw", { @@ -35,6 +34,7 @@ minetest.register_node("mcl_copper:block", { sounds = mcl_sounds.node_sound_metal_defaults(), _mcl_blast_resistance = 6, _mcl_hardness = 3, + _mcl_copper_waxed_variant = "mcl_copper:waxed_block", on_rightclick = function(pos, node, player, itemstack) waxing_copper_block(pos, node, player, itemstack, "mcl_copper:waxed_block") end, }) @@ -47,6 +47,7 @@ minetest.register_node("mcl_copper:waxed_block", { sounds = mcl_sounds.node_sound_metal_defaults(), _mcl_blast_resistance = 6, _mcl_hardness = 3, + _mcl_copper_unwaxed_variant = "mcl_copper:block", on_rightclick = function(pos, node, player, itemstack) scraping_copper_block(pos, node, player, itemstack, "mcl_copper:block") end, }) @@ -59,7 +60,8 @@ minetest.register_node("mcl_copper:block_exposed", { sounds = mcl_sounds.node_sound_metal_defaults(), _mcl_blast_resistance = 6, _mcl_hardness = 5, - _mcl_anti_oxidation_varient = "mcl_copper:block", + _mcl_anti_oxidation_variant = "mcl_copper:block", + _mcl_copper_waxed_variant = "mcl_copper:waxed_block_exposed", on_rightclick = function(pos, node, player, itemstack) waxing_copper_block(pos, node, player, itemstack, "mcl_copper:waxed_block_exposed") end, }) @@ -72,6 +74,7 @@ minetest.register_node("mcl_copper:waxed_block_exposed", { sounds = mcl_sounds.node_sound_metal_defaults(), _mcl_blast_resistance = 6, _mcl_hardness = 5, + _mcl_copper_unwaxed_variant = "mcl_copper:block", on_rightclick = function(pos, node, player, itemstack) scraping_copper_block(pos, node, player, itemstack, "mcl_copper:block") end, }) @@ -84,7 +87,8 @@ minetest.register_node("mcl_copper:block_weathered", { sounds = mcl_sounds.node_sound_metal_defaults(), _mcl_blast_resistance = 6, _mcl_hardness = 5, - _mcl_anti_oxidation_varient = "mcl_copper:block_exposed", + _mcl_anti_oxidation_variant = "mcl_copper:block_exposed", + _mcl_copper_waxed_variant = "mcl_copper:waxed_block_weathered", on_rightclick = function(pos, node, player, itemstack) waxing_copper_block(pos, node, player, itemstack, "mcl_copper:waxed_block_weathered") end, }) @@ -97,6 +101,7 @@ minetest.register_node("mcl_copper:waxed_block_weathered", { sounds = mcl_sounds.node_sound_metal_defaults(), _mcl_blast_resistance = 6, _mcl_hardness = 5, + _mcl_copper_unwaxed_variant = "mcl_copper:block_exposed", on_rightclick = function(pos, node, player, itemstack) scraping_copper_block(pos, node, player, itemstack, "mcl_copper:block_exposed") end, }) @@ -109,7 +114,8 @@ minetest.register_node("mcl_copper:block_oxidized", { sounds = mcl_sounds.node_sound_metal_defaults(), _mcl_blast_resistance = 6, _mcl_hardness = 5, - _mcl_anti_oxidation_varient = "mcl_copper:block_weathered", + _mcl_anti_oxidation_variant = "mcl_copper:block_weathered", + _mcl_copper_waxed_variant = "mcl_copper:waxed_block_oxidized", on_rightclick = function(pos, node, player, itemstack) waxing_copper_block(pos, node, player, itemstack, "mcl_copper:waxed_block_oxidized") end, }) @@ -122,6 +128,7 @@ minetest.register_node("mcl_copper:waxed_block_oxidized", { sounds = mcl_sounds.node_sound_metal_defaults(), _mcl_blast_resistance = 6, _mcl_hardness = 5, + _mcl_copper_unwaxed_variant = "mcl_copper:block_weathered", on_rightclick = function(pos, node, player, itemstack) scraping_copper_block(pos, node, player, itemstack, "mcl_copper:block_weathered") end, }) @@ -134,6 +141,7 @@ minetest.register_node("mcl_copper:block_cut", { sounds = mcl_sounds.node_sound_metal_defaults(), _mcl_blast_resistance = 6, _mcl_hardness = 5, + _mcl_copper_waxed_variant = "mcl_copper:waxed_block_cut", on_rightclick = function(pos, node, player, itemstack) waxing_copper_block(pos, node, player, itemstack, "mcl_copper:waxed_block_cut") end, }) @@ -146,6 +154,7 @@ minetest.register_node("mcl_copper:waxed_block_cut", { sounds = mcl_sounds.node_sound_metal_defaults(), _mcl_blast_resistance = 6, _mcl_hardness = 5, + _mcl_copper_unwaxed_variant = "mcl_copper:block_cut", on_rightclick = function(pos, node, player, itemstack) scraping_copper_block(pos, node, player, itemstack, "mcl_copper:block_cut") end, }) @@ -158,7 +167,8 @@ minetest.register_node("mcl_copper:block_exposed_cut", { sounds = mcl_sounds.node_sound_metal_defaults(), _mcl_blast_resistance = 6, _mcl_hardness = 5, - _mcl_anti_oxidation_varient = "mcl_copper:block_cut", + _mcl_anti_oxidation_variant = "mcl_copper:block_cut", + _mcl_copper_waxed_variant = "mcl_copper:waxed_block_exposed_cut", on_rightclick = function(pos, node, player, itemstack) waxing_copper_block(pos, node, player, itemstack, "mcl_copper:waxed_block_exposed_cut") end, }) @@ -171,6 +181,7 @@ minetest.register_node("mcl_copper:waxed_block_exposed_cut", { sounds = mcl_sounds.node_sound_metal_defaults(), _mcl_blast_resistance = 6, _mcl_hardness = 5, + _mcl_copper_unwaxed_variant = "mcl_copper:block_cut", on_rightclick = function(pos, node, player, itemstack) scraping_copper_block(pos, node, player, itemstack, "mcl_copper:block_cut") end, }) @@ -183,7 +194,8 @@ minetest.register_node("mcl_copper:block_weathered_cut", { sounds = mcl_sounds.node_sound_metal_defaults(), _mcl_blast_resistance = 6, _mcl_hardness = 5, - _mcl_anti_oxidation_varient = "mcl_copper:block_exposed_cut", + _mcl_anti_oxidation_variant = "mcl_copper:block_exposed_cut", + _mcl_copper_waxed_variant = "mcl_copper:waxed_block_weathered_cut", on_rightclick = function(pos, node, player, itemstack) waxing_copper_block(pos, node, player, itemstack, "mcl_copper:waxed_block_weathered_cut") end, }) @@ -196,6 +208,7 @@ minetest.register_node("mcl_copper:waxed_block_weathered_cut", { sounds = mcl_sounds.node_sound_metal_defaults(), _mcl_blast_resistance = 6, _mcl_hardness = 5, + _mcl_copper_unwaxed_variant = "mcl_copper:block_exposed_cut", on_rightclick = function(pos, node, player, itemstack) scraping_copper_block(pos, node, player, itemstack, "mcl_copper:block_exposed_cut") end, }) @@ -208,7 +221,8 @@ minetest.register_node("mcl_copper:block_oxidized_cut", { sounds = mcl_sounds.node_sound_metal_defaults(), _mcl_blast_resistance = 6, _mcl_hardness = 5, - _mcl_anti_oxidation_varient = "mcl_copper:block_weathered_cut", + _mcl_anti_oxidation_variant = "mcl_copper:block_weathered_cut", + _mcl_copper_waxed_variant = "mcl_copper:waxed_block_oxidized_cut", on_rightclick = function(pos, node, player, itemstack) waxing_copper_block(pos, node, player, itemstack, "mcl_copper:waxed_block_oxidized_cut") end, }) @@ -221,6 +235,7 @@ minetest.register_node("mcl_copper:waxed_block_oxidized_cut", { sounds = mcl_sounds.node_sound_metal_defaults(), _mcl_blast_resistance = 6, _mcl_hardness = 5, + _mcl_copper_unwaxed_variant = "mcl_copper:block_weathered_cut", on_rightclick = function(pos, node, player, itemstack) scraping_copper_block(pos, node, player, itemstack, "mcl_copper:block_weathered_cut") end, })