forked from VoxeLibre/VoxeLibre
Refactor
This commit is contained in:
parent
25219c7102
commit
a6ea84b55d
|
@ -1,3 +1,15 @@
|
||||||
|
mcl_oxidize = {}
|
||||||
|
|
||||||
|
function mcl_oxidize.oxidize(pos, node, node_def)
|
||||||
|
local node = node or minetest.get_node(pos)
|
||||||
|
local node_def = node_def or registered_nodes[node.name]
|
||||||
|
node.name = node_def._mcl_oxidized_variant
|
||||||
|
if not node.name then return end
|
||||||
|
|
||||||
|
minetest.swap_node(pos, node)
|
||||||
|
end
|
||||||
|
local oxidize = mcl_oxidize
|
||||||
|
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
label = "Oxidatize Nodes",
|
label = "Oxidatize Nodes",
|
||||||
nodenames = { "group:oxidizable" },
|
nodenames = { "group:oxidizable" },
|
||||||
|
@ -6,16 +18,9 @@ minetest.register_abm({
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
local def = minetest.registered_nodes[node.name]
|
local def = minetest.registered_nodes[node.name]
|
||||||
if def and def._mcl_oxidized_variant then
|
if def and def._mcl_oxidized_variant then
|
||||||
if def.groups.door == 1 then
|
local hook = def._on_oxidize
|
||||||
if node.name:find("_b_") then
|
if hook then hook(pos, node, def) end
|
||||||
local top_pos = { x = pos.x, y = pos.y + 1, z = pos.z }
|
oxidize(pos, node, def)
|
||||||
minetest.swap_node(top_pos, { name = def._mcl_oxidized_variant:gsub("_b_", "_t_"), param2 = node.param2 })
|
|
||||||
elseif node.name:find("_t_") then
|
|
||||||
local bot_pos = { x = pos.x, y = pos.y - 1, z = pos.z }
|
|
||||||
minetest.swap_node(bot_pos, { name = def._mcl_oxidized_variant:gsub("_t_", "_b_"), param2 = node.param2 })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
minetest.swap_node(pos, { name = def._mcl_oxidized_variant, param2 = node.param2 })
|
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,3 +1,43 @@
|
||||||
|
-- Functions used to strip wax from the other half of the door
|
||||||
|
local function strip(pos, node, node_def)
|
||||||
|
local node = node or minetest.get_node(pos)
|
||||||
|
local node_def = node_def or registered_nodes[node.name]
|
||||||
|
if not node_def then return end
|
||||||
|
|
||||||
|
node.name = node_def._mcl_stripped_variant
|
||||||
|
minetest.swap_node(pos, node)
|
||||||
|
end
|
||||||
|
local function strip_door_top(pos, node, node_def)
|
||||||
|
strip(vector.offset(pos,0,-1,0))
|
||||||
|
end
|
||||||
|
local function strip_door_bottom(pos, node, node_def)
|
||||||
|
strip(vector.offset(pos,0,1,0))
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Functions used to wax the other half of the door
|
||||||
|
local function wax(pos, node, node_def)
|
||||||
|
local node = node or minetest.get_node(pos)
|
||||||
|
local node_def = node_def or registered_nodes[node.name]
|
||||||
|
if not node_def then return end
|
||||||
|
|
||||||
|
node.name = node_def._mcl_waxed_variant
|
||||||
|
minetest.swap_node(pos, node)
|
||||||
|
end
|
||||||
|
local function wax_door_top(pos, node, node_def)
|
||||||
|
wax(vector.offset(pos,0,-1.0))
|
||||||
|
end
|
||||||
|
local function wax_door_bottom(pos, node, node_def)
|
||||||
|
wax(vector.offset(pos,0,1,0))
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Functions used to oxidize the other half of the door.
|
||||||
|
local function oxidize_door_top(pos, node, node_def)
|
||||||
|
mcl_oxidize.oxidize(vector.offset(pos,0,-1,0))
|
||||||
|
end
|
||||||
|
local function oxidize_door_bottom(pos, node, node_def)
|
||||||
|
mcl_oxidize.oxidize(vector.offset(pos,0,1,0))
|
||||||
|
end
|
||||||
|
|
||||||
--- Function used to define the oxidized and stripped variants of copper-related blocks that
|
--- Function used to define the oxidized and stripped variants of copper-related blocks that
|
||||||
--- are registered by APIs external to mcl_copper (stairs, slabs, doors and trapdoors). "mod_name"
|
--- are registered by APIs external to mcl_copper (stairs, slabs, doors and trapdoors). "mod_name"
|
||||||
--- should be the name of the mod the blocks belong to. "subname" must be the subname of the block that
|
--- should be the name of the mod the blocks belong to. "subname" must be the subname of the block that
|
||||||
|
@ -35,25 +75,25 @@ local function register_oxidation_and_scraping(mod_name, subname, decay_chain)
|
||||||
minetest.override_item(item.."_open", {_mcl_oxidized_variant = oxidized_item.."_open"})
|
minetest.override_item(item.."_open", {_mcl_oxidized_variant = oxidized_item.."_open"})
|
||||||
minetest.override_item(oxidized_item.."_open", {_mcl_stripped_variant = item.."_open"})
|
minetest.override_item(oxidized_item.."_open", {_mcl_stripped_variant = item.."_open"})
|
||||||
elseif subname == "door" then
|
elseif subname == "door" then
|
||||||
minetest.override_item(item.."_b_1", {_mcl_oxidized_variant = oxidized_item.."_b_1"})
|
for i = 1,4 do
|
||||||
minetest.override_item(oxidized_item.."_b_1", {_mcl_stripped_variant = item.."_b_1"})
|
local is = tostring(i)
|
||||||
minetest.override_item(item.."_t_1", {_mcl_oxidized_variant = oxidized_item.."_t_1"})
|
minetest.override_item(item.."_b_"..is, {
|
||||||
minetest.override_item(oxidized_item.."_t_1", {_mcl_stripped_variant = item.."_t_1"})
|
_mcl_oxidized_variant = oxidized_item.."_b_"..is,
|
||||||
|
_mcl_on_oxidize = oxidize_door_bottom
|
||||||
minetest.override_item(item.."_b_2", {_mcl_oxidized_variant = oxidized_item.."_b_2"})
|
})
|
||||||
minetest.override_item(oxidized_item.."_b_2", {_mcl_stripped_variant = item.."_b_2"})
|
minetest.override_item(oxidized_item.."_b_"..is, {
|
||||||
minetest.override_item(item.."_t_2", {_mcl_oxidized_variant = oxidized_item.."_t_2"})
|
_mcl_stripped_variant = item.."_b_"..is,
|
||||||
minetest.override_item(oxidized_item.."_t_2", {_mcl_stripped_variant = item.."_t_2"})
|
_mcl_on_strip = strip_door_bottom,
|
||||||
|
})
|
||||||
minetest.override_item(item.."_b_3", {_mcl_oxidized_variant = oxidized_item.."_b_3"})
|
minetest.override_item(item.."_t_"..is, {
|
||||||
minetest.override_item(oxidized_item.."_b_3", {_mcl_stripped_variant = item.."_b_3"})
|
_mcl_oxidized_variant = oxidized_item.."_t_"..is,
|
||||||
minetest.override_item(item.."_t_3", {_mcl_oxidized_variant = oxidized_item.."_t_3"})
|
_mcl_on_oxidize = oxidize_door_top,
|
||||||
minetest.override_item(oxidized_item.."_t_3", {_mcl_stripped_variant = item.."_t_3"})
|
})
|
||||||
|
minetest.override_item(oxidized_item.."_t_"..is, {
|
||||||
minetest.override_item(item.."_b_4", {_mcl_oxidized_variant = oxidized_item.."_b_4"})
|
_mcl_stripped_variant = item.."_t_"..is,
|
||||||
minetest.override_item(oxidized_item.."_b_4", {_mcl_stripped_variant = item.."_b_4"})
|
_mcl_on_strip = strip_door_top,
|
||||||
minetest.override_item(item.."_t_4", {_mcl_oxidized_variant = oxidized_item.."_t_4"})
|
})
|
||||||
minetest.override_item(oxidized_item.."_t_4", {_mcl_stripped_variant = item.."_t_4"})
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -92,25 +132,25 @@ local function register_waxing_and_scraping(mod_name, subname, decay_chain)
|
||||||
minetest.override_item(waxed_item.."_open", {_mcl_stripped_variant = unwaxed_item.."_open"})
|
minetest.override_item(waxed_item.."_open", {_mcl_stripped_variant = unwaxed_item.."_open"})
|
||||||
minetest.override_item(unwaxed_item.."_open", {_mcl_waxed_variant = waxed_item.."_open"})
|
minetest.override_item(unwaxed_item.."_open", {_mcl_waxed_variant = waxed_item.."_open"})
|
||||||
elseif subname == "waxed_door" then
|
elseif subname == "waxed_door" then
|
||||||
minetest.override_item(waxed_item.."_b_1", {_mcl_stripped_variant = unwaxed_item.."_b_1"})
|
for i = 1,4 do
|
||||||
minetest.override_item(unwaxed_item.."_b_1", {_mcl_waxed_variant = waxed_item.."_b_1"})
|
local is = tostring(i)
|
||||||
minetest.override_item(waxed_item.."_t_1", {_mcl_stripped_variant = unwaxed_item.."_t_1"})
|
minetest.override_item(waxed_item.."_b_1", {
|
||||||
minetest.override_item(unwaxed_item.."_t_1", {_mcl_waxed_variant = waxed_item.."_t_1"})
|
_mcl_stripped_variant = unwaxed_item.."_b_1",
|
||||||
|
_mcl_on_strip = strip_door_bottom,
|
||||||
minetest.override_item(waxed_item.."_b_2", {_mcl_stripped_variant = unwaxed_item.."_b_2"})
|
})
|
||||||
minetest.override_item(unwaxed_item.."_b_2", {_mcl_waxed_variant = waxed_item.."_b_2"})
|
minetest.override_item(unwaxed_item.."_b_1", {
|
||||||
minetest.override_item(waxed_item.."_t_2", {_mcl_stripped_variant = unwaxed_item.."_t_2"})
|
_mcl_waxed_variant = waxed_item.."_b_1",
|
||||||
minetest.override_item(unwaxed_item.."_t_2", {_mcl_waxed_variant = waxed_item.."_t_2"})
|
_mcl_on_wax = wax_door_bottom,
|
||||||
|
})
|
||||||
minetest.override_item(waxed_item.."_b_3", {_mcl_stripped_variant = unwaxed_item.."_b_3"})
|
minetest.override_item(waxed_item.."_t_1", {
|
||||||
minetest.override_item(unwaxed_item.."_b_3", {_mcl_waxed_variant = waxed_item.."_b_3"})
|
_mcl_stripped_variant = unwaxed_item.."_t_1",
|
||||||
minetest.override_item(waxed_item.."_t_3", {_mcl_stripped_variant = unwaxed_item.."_t_3"})
|
_mcl_on_strip = strip_door_top,
|
||||||
minetest.override_item(unwaxed_item.."_t_3", {_mcl_waxed_variant = waxed_item.."_t_3"})
|
})
|
||||||
|
minetest.override_item(unwaxed_item.."_t_1", {
|
||||||
minetest.override_item(waxed_item.."_b_4", {_mcl_stripped_variant = unwaxed_item.."_b_4"})
|
_mcl_waxed_variant = waxed_item.."_t_1",
|
||||||
minetest.override_item(unwaxed_item.."_b_4", {_mcl_waxed_variant = waxed_item.."_b_4"})
|
_mcl_on_wax = wax_door_top,
|
||||||
minetest.override_item(waxed_item.."_t_4", {_mcl_stripped_variant = unwaxed_item.."_t_4"})
|
})
|
||||||
minetest.override_item(unwaxed_item.."_t_4", {_mcl_waxed_variant = waxed_item.."_t_4"})
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,34 +10,29 @@ local alldirs = { { x = 0, y = 0, z = 1 }, { x = 1, y = 0, z = 0 }, { x = 0, y =
|
||||||
-- Waxing Function
|
-- Waxing Function
|
||||||
function mcl_honey.wax_block(pos, node, player, itemstack, pointed_thing)
|
function mcl_honey.wax_block(pos, node, player, itemstack, pointed_thing)
|
||||||
-- prevent modification of protected nodes.
|
-- prevent modification of protected nodes.
|
||||||
if mcl_util.check_position_protection(pos, player) then
|
if mcl_util.check_position_protection(pos, player) then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
|
-- Make sure we aren't trying to wax an unknown node
|
||||||
local def = minetest.registered_nodes[node.name]
|
local def = minetest.registered_nodes[node.name]
|
||||||
if player and player:get_player_control().sneak then
|
if not def then return itemstack end
|
||||||
if def and def._mcl_waxed_variant then
|
|
||||||
if def.groups.door == 1 then
|
-- Do right-click action if a handler exists and the player isn't sneaking
|
||||||
if node.name:find("_b_") then
|
if def.on_rightclick and not ( player and player:get_player_control().sneak ) then
|
||||||
local top_pos = { x = pos.x, y = pos.y + 1, z = pos.z }
|
|
||||||
minetest.swap_node(top_pos, { name = def._mcl_waxed_variant:gsub("_b_", "_t_"), param2 = node.param2 })
|
|
||||||
elseif node.name:find("_t_") then
|
|
||||||
local bot_pos = { x = pos.x, y = pos.y - 1, z = pos.z }
|
|
||||||
minetest.swap_node(bot_pos, { name = def._mcl_waxed_variant:gsub("_t_", "_b_"), param2 = node.param2 })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
return
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if def and def.on_rightclick then
|
|
||||||
return def.on_rightclick(pos, node, player, itemstack, pointed_thing)
|
return def.on_rightclick(pos, node, player, itemstack, pointed_thing)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
-- Wax the node
|
||||||
node.name = def._mcl_waxed_variant
|
node.name = def._mcl_waxed_variant
|
||||||
minetest.swap_node(pos, node)
|
minetest.swap_node(pos, node)
|
||||||
|
|
||||||
|
-- Call the node's waxed hook
|
||||||
|
local hook = def._mcl_on_waxed
|
||||||
|
if hook then hook(pos, node, def) end
|
||||||
|
|
||||||
|
-- Handle the award
|
||||||
awards.unlock(player:get_player_name(), "mcl:wax_on")
|
awards.unlock(player:get_player_name(), "mcl:wax_on")
|
||||||
|
|
||||||
|
-- Deal with the honeycomb
|
||||||
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
|
||||||
|
|
|
@ -393,7 +393,7 @@ local function make_stripped_trunk(itemstack, placer, pointed_thing)
|
||||||
if pointed_thing.type ~= "node" then return end
|
if pointed_thing.type ~= "node" then return end
|
||||||
|
|
||||||
local node = minetest.get_node(pointed_thing.under)
|
local node = minetest.get_node(pointed_thing.under)
|
||||||
local node_name = minetest.get_node(pointed_thing.under).name
|
local node_name = node.name
|
||||||
|
|
||||||
local noddef = minetest.registered_nodes[node_name]
|
local noddef = minetest.registered_nodes[node_name]
|
||||||
|
|
||||||
|
@ -413,16 +413,9 @@ local function make_stripped_trunk(itemstack, placer, pointed_thing)
|
||||||
if noddef._mcl_stripped_variant == nil then
|
if noddef._mcl_stripped_variant == nil then
|
||||||
return itemstack
|
return itemstack
|
||||||
else
|
else
|
||||||
if noddef.groups.door == 1 then
|
local hook = noddef._mcl_on_strip
|
||||||
local pt_under = pointed_thing.under
|
if hook then hook(pointed_thing.under, node, noddef) end
|
||||||
if node_name:find("_b_") then
|
|
||||||
local top_pos = {x = pt_under.x, y = pt_under.y + 1, z = pt_under.z}
|
|
||||||
minetest.swap_node(top_pos, {name=noddef._mcl_stripped_variant:gsub("_b_", "_t_"), param2=node.param2})
|
|
||||||
elseif node_name:find("_t_") then
|
|
||||||
local bot_pos = {x = pt_under.x, y = pt_under.y - 1, z = pt_under.z}
|
|
||||||
minetest.swap_node(bot_pos, {name=noddef._mcl_stripped_variant:gsub("_t_", "_b_"), param2=node.param2})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
minetest.swap_node(pointed_thing.under, {name=noddef._mcl_stripped_variant, param2=node.param2})
|
minetest.swap_node(pointed_thing.under, {name=noddef._mcl_stripped_variant, param2=node.param2})
|
||||||
if minetest.get_item_group(node_name, "waxed") ~= 0 then
|
if minetest.get_item_group(node_name, "waxed") ~= 0 then
|
||||||
awards.unlock(placer:get_player_name(), "mcl:wax_off")
|
awards.unlock(placer:get_player_name(), "mcl:wax_off")
|
||||||
|
|
Loading…
Reference in New Issue