1
0
Fork 0

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
Bamboo-Piston-Dig
Michieal 2023-01-30 18:27:53 -05:00
parent 865d260f83
commit 7039bf9e7d
2 changed files with 105 additions and 39 deletions

View File

@ -1,5 +1,34 @@
--local deepslate_mod = minetest.get_modpath("mcl_deepslate") --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) local function register_oxidation_abm(abm_name, node_name, oxidized_variant)
minetest.register_abm({ minetest.register_abm({
label = abm_name, label = abm_name,
@ -14,20 +43,42 @@ end
function waxing_copper_block(pos, node, player, itemstack, convert_to) function waxing_copper_block(pos, node, player, itemstack, convert_to)
if itemstack:get_name() == "mcl_honey:honeycomb" then 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) minetest.set_node(pos, node)
awards.unlock(player:get_player_name(), "mcl:wax_on") awards.unlock(player:get_player_name(), "mcl:wax_on")
if not minetest.is_creative_enabled(player:get_player_name()) then if not minetest.is_creative_enabled(player:get_player_name()) then
itemstack:take_item() itemstack:take_item()
end end
return itemstack
else else
return true return -- changed to work with mcl_util.call_on_rightclick()
end end
end end
function scraping_copper_block(pos, node, player, itemstack, convert_to) function scraping_copper_block(pos, node, player, itemstack, convert_to)
if itemstack:get_name():find("axe") then 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) minetest.set_node(pos, node)
awards.unlock(player:get_player_name(), "mcl:wax_off") awards.unlock(player:get_player_name(), "mcl:wax_off")
if not minetest.is_creative_enabled(player:get_player_name()) then 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) itemstack:add_wear(wear)
end end
else else
return true return
end end
end end

View File

@ -12,7 +12,6 @@ minetest.register_node("mcl_copper:stone_with_copper", {
_mcl_hardness = 3, _mcl_hardness = 3,
_mcl_silk_touch_drop = true, _mcl_silk_touch_drop = true,
_mcl_fortune_drop = mcl_core.fortune_drop_ore, _mcl_fortune_drop = mcl_core.fortune_drop_ore,
}) })
minetest.register_node("mcl_copper:block_raw", { minetest.register_node("mcl_copper:block_raw", {
@ -35,6 +34,7 @@ minetest.register_node("mcl_copper:block", {
sounds = mcl_sounds.node_sound_metal_defaults(), sounds = mcl_sounds.node_sound_metal_defaults(),
_mcl_blast_resistance = 6, _mcl_blast_resistance = 6,
_mcl_hardness = 3, _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, 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(), sounds = mcl_sounds.node_sound_metal_defaults(),
_mcl_blast_resistance = 6, _mcl_blast_resistance = 6,
_mcl_hardness = 3, _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, 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(), sounds = mcl_sounds.node_sound_metal_defaults(),
_mcl_blast_resistance = 6, _mcl_blast_resistance = 6,
_mcl_hardness = 5, _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, 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(), sounds = mcl_sounds.node_sound_metal_defaults(),
_mcl_blast_resistance = 6, _mcl_blast_resistance = 6,
_mcl_hardness = 5, _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, 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(), sounds = mcl_sounds.node_sound_metal_defaults(),
_mcl_blast_resistance = 6, _mcl_blast_resistance = 6,
_mcl_hardness = 5, _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, 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(), sounds = mcl_sounds.node_sound_metal_defaults(),
_mcl_blast_resistance = 6, _mcl_blast_resistance = 6,
_mcl_hardness = 5, _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, 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(), sounds = mcl_sounds.node_sound_metal_defaults(),
_mcl_blast_resistance = 6, _mcl_blast_resistance = 6,
_mcl_hardness = 5, _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, 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(), sounds = mcl_sounds.node_sound_metal_defaults(),
_mcl_blast_resistance = 6, _mcl_blast_resistance = 6,
_mcl_hardness = 5, _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, 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(), sounds = mcl_sounds.node_sound_metal_defaults(),
_mcl_blast_resistance = 6, _mcl_blast_resistance = 6,
_mcl_hardness = 5, _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, 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(), sounds = mcl_sounds.node_sound_metal_defaults(),
_mcl_blast_resistance = 6, _mcl_blast_resistance = 6,
_mcl_hardness = 5, _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, 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(), sounds = mcl_sounds.node_sound_metal_defaults(),
_mcl_blast_resistance = 6, _mcl_blast_resistance = 6,
_mcl_hardness = 5, _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, 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(), sounds = mcl_sounds.node_sound_metal_defaults(),
_mcl_blast_resistance = 6, _mcl_blast_resistance = 6,
_mcl_hardness = 5, _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, 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(), sounds = mcl_sounds.node_sound_metal_defaults(),
_mcl_blast_resistance = 6, _mcl_blast_resistance = 6,
_mcl_hardness = 5, _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, 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(), sounds = mcl_sounds.node_sound_metal_defaults(),
_mcl_blast_resistance = 6, _mcl_blast_resistance = 6,
_mcl_hardness = 5, _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, 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(), sounds = mcl_sounds.node_sound_metal_defaults(),
_mcl_blast_resistance = 6, _mcl_blast_resistance = 6,
_mcl_hardness = 5, _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, 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(), sounds = mcl_sounds.node_sound_metal_defaults(),
_mcl_blast_resistance = 6, _mcl_blast_resistance = 6,
_mcl_hardness = 5, _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, on_rightclick = function(pos, node, player, itemstack) scraping_copper_block(pos, node, player, itemstack, "mcl_copper:block_weathered_cut") end,
}) })