Improve the code

This commit is contained in:
FossFanatic 2023-05-13 12:32:17 +00:00
parent 70eb019a58
commit 9c208fb6b0
1 changed files with 296 additions and 459 deletions

View File

@ -54,19 +54,11 @@ function mcl_doors:register_door(name, def)
def.sound_close = "doors_door_close"
end
local box = {{-8/16, -8/16, -8/16, 8/16, 8/16, -5/16}}
if not def.node_box_bottom then
def.node_box_bottom = box
if not def.node_box then
def.node_box = {{-8/16, -8/16, -8/16, 8/16, 8/16, -5/16}}
end
if not def.node_box_top then
def.node_box_top = box
end
if not def.selection_box_bottom then
def.selection_box_bottom= box
end
if not def.selection_box_top then
def.selection_box_top = box
if not def.selection_box then
def.selection_box = {{-8/16, -8/16, -8/16, 8/16, 8/16, -5/16}}
end
local longdesc, usagehelp, tt_help
@ -202,22 +194,22 @@ function mcl_doors:register_door(name, def)
end,
})
local doortextop = def.tiles_top:match("(.+)%..+$")
local doortexbottom = def.tiles_bottom:match("(.+)%..+$")
local top_door_texture = def.tiles_top:match("(.+)%..+$") -- This removes the filename extension from the images.
local bottom_door_texture = def.tiles_bottom:match("(.+)%..+$") -- This removes the filename extension from the images.
local tt = doortextop .. ".png"
local tb = doortexbottom .. ".png"
local ttt = doortextop .. "_toppart.png" -- Special texture to make the top of opened doors not look weird.
local tbb = doortexbottom .. "_bottompart.png" -- Special texture to make the bottom of opened doors not look weird.
local tts = doortextop .. "_side.png" -- Special texture to make the side of opened doors not look weird.
local tbs = doortexbottom .. "_side.png" -- Special texture to make the side of opened doors not look weird.
local texture_top = top_door_texture .. ".png"
local texture_bottom = bottom_door_texture .. ".png"
local texture_top_toppart = top_door_texture .. "_toppart.png" -- Special texture to make the top of opened doors not look weird.
local texture_bottom_bottompart = bottom_door_texture .. "_bottompart.png" -- Special texture to make the bottom of opened doors not look weird.
local texture_top_side = top_door_texture .. "_side.png" -- Special texture to make the side of opened doors not look weird.
local texture_bottom_side = bottom_door_texture .. "_side.png" -- Special texture to make the side of opened doors not look weird.
local ttm = tt .. "^[transformFX"
local tbm = tb .. "^[transformFX"
local tttm = ttt .. "^[transformFX"
local tbbm = tbb .. "^[transformFX"
local ttsm = tts .. "^[transformFX"
local tbsm = tbs .. "^[transformFX"
local texture_top_mirrored = texture_top .. "^[transformFX"
local texture_bottom_mirrored = texture_bottom .. "^[transformFX"
local texture_top_toppart_mirrored = texture_top_toppart .. "^[transformFX"
local texture_bottom_bottompart_mirrored = texture_bottom_bottompart .. "^[transformFX"
local texture_top_side_mirrored = texture_top_side .. "^[transformFX"
local texture_bottom_side_mirrored = texture_bottom_side .. "^[transformFX"
local function on_open_close(pos, dir, check_name, replace, replace_dir)
local meta1 = minetest_get_meta(pos)
@ -304,8 +296,8 @@ function mcl_doors:register_door(name, def)
end
end
minetest.register_node(name.."_b_1", {
tiles = {"blank.png", tbb .. "^[transformFY", tbs, tbsm, tbm, tb},
local template_def = {
tiles = nil,
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true,
paramtype = "light",
paramtype2 = "facedir",
@ -315,18 +307,31 @@ function mcl_doors:register_door(name, def)
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = def.node_box_bottom
fixed = def.node_box
},
selection_box = {
type = "fixed",
fixed = def.selection_box_bottom
fixed = def.selection_box
},
groups = def.groups,
_mcl_hardness = def._mcl_hardness,
_mcl_blast_resistance = def._mcl_blast_resistance,
sounds = def.sounds,
after_destruct = function(bottom, oldnode)
after_destruct = nil,
on_rightclick = nil,
mesecons = nil,
on_rotate = nil,
can_dig = check_player_priv,
}
local _b_1_def = table.copy(template_def)
_b_1_def.tiles = {"blank.png", texture_bottom_bottompart .. "^[transformFY", texture_bottom_side, texture_bottom_side_mirrored, texture_bottom_mirrored, texture_bottom}
_b_1_def.after_destruct = function(bottom, oldnode)
local meta_bottom = minetest_get_meta(bottom)
if meta_bottom:get_int("rotation") == 1 then
meta_bottom:set_int("rotation", 0)
@ -337,15 +342,12 @@ function mcl_doors:register_door(name, def)
minetest.remove_node(top)
end
end
end,
on_rightclick = on_rightclick,
mesecons = { effector = {
end
_b_1_def.on_rightclick = on_rightclick
_b_1_def.mesecons = { effector = {
action_on = on_mesecons_signal_open,
}},
on_rotate = function(bottom, node, user, mode, param2)
}}
_b_1_def.on_rotate = function(bottom, node, user, mode, param2)
if mode == screwdriver.ROTATE_FACE then
local meta_bottom = minetest_get_meta(bottom)
meta_bottom:set_int("rotation", 1)
@ -361,10 +363,9 @@ function mcl_doors:register_door(name, def)
return true
end
return false
end,
end
can_dig = check_player_priv,
})
minetest.register_node(name.."_b_1", _b_1_def)
if def.only_redstone_can_open then
on_rightclick = nil
@ -376,29 +377,9 @@ function mcl_doors:register_door(name, def)
end
end
minetest.register_node(name.."_t_1", {
tiles = {ttt .. "^[transformFY", "blank.png", tts, ttsm, ttm, tt},
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true,
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
is_ground_content = false,
drop = "",
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = def.node_box_top
},
selection_box = {
type = "fixed",
fixed = def.selection_box_top
},
groups = def.groups,
_mcl_hardness = def._mcl_hardness,
_mcl_blast_resistance = def._mcl_blast_resistance,
sounds = def.sounds,
after_destruct = function(top, oldnode)
local _t_1_def = table.copy(template_def)
_t_1_def.tiles = {texture_top_toppart .. "^[transformFY", "blank.png", texture_top_side, texture_top_side_mirrored, texture_top_mirrored, texture_top}
_t_1_def.after_destruct = function(top, oldnode)
local meta_top = minetest_get_meta(top)
if meta_top:get_int("rotation") == 1 then
meta_top:set_int("rotation", 0)
@ -408,16 +389,13 @@ function mcl_doors:register_door(name, def)
minetest.dig_node(bottom)
end
end
end,
on_rightclick = on_rightclick,
mesecons = { effector = {
end
_t_1_def.on_rightclick = on_rightclick
_t_1_def.mesecons = { effector = {
action_on = on_mesecons_signal_open_top,
rules = mesecon.rules.flat,
}},
on_rotate = function(top, node, user, mode, param2)
}}
_t_1_def.on_rotate = function(top, node, user, mode, param2)
if mode == screwdriver.ROTATE_FACE then
local meta_top = minetest_get_meta(top)
meta_top:set_int("rotation", 1)
@ -433,10 +411,9 @@ function mcl_doors:register_door(name, def)
return true
end
return false
end,
end
can_dig = check_player_priv,
})
minetest.register_node(name.."_t_1", _t_1_def)
if def.only_redstone_can_open then
on_rightclick = nil
@ -448,28 +425,9 @@ function mcl_doors:register_door(name, def)
end
end
minetest.register_node(name.."_b_2", {
tiles = {"blank.png", tbbm, tbs, tbs, tb, tbm},
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true,
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
is_ground_content = false,
drop = "",
drawtype = "nodebox",
groups = def.groups,
_mcl_hardness = def._mcl_hardness,
_mcl_blast_resistance = def._mcl_blast_resistance,
sounds = def.sounds,
node_box = {
type = "fixed",
fixed = def.node_box_bottom
},
selection_box = {
type = "fixed",
fixed = def.selection_box_bottom
},
after_destruct = function(bottom, oldnode)
local _b_2_def = table.copy(template_def)
_b_2_def.tiles = {"blank.png", texture_bottom_bottompart_mirrored, texture_bottom_side, texture_bottom_side, texture_bottom, texture_bottom_mirrored}
_b_2_def.after_destruct = function(bottom, oldnode)
local meta_bottom = minetest_get_meta(bottom)
if meta_bottom:get_int("rotation") == 1 then
meta_bottom:set_int("rotation", 0)
@ -480,15 +438,12 @@ function mcl_doors:register_door(name, def)
minetest.remove_node(top)
end
end
end,
on_rightclick = on_rightclick,
mesecons = { effector = {
end
_b_2_def.on_rightclick = on_rightclick
_b_2_def.mesecons = { effector = {
action_off = on_mesecons_signal_close,
}},
on_rotate = function(bottom, node, user, mode, param2)
}}
_b_2_def.on_rotate = function(bottom, node, user, mode, param2)
if mode == screwdriver.ROTATE_FACE then
local meta_bottom = minetest_get_meta(bottom)
meta_bottom:set_int("rotation", 1)
@ -504,10 +459,9 @@ function mcl_doors:register_door(name, def)
return true
end
return false
end,
end
can_dig = check_player_priv,
})
minetest.register_node(name.."_b_2", _b_2_def)
if def.only_redstone_can_open then
on_rightclick = nil
@ -519,28 +473,9 @@ function mcl_doors:register_door(name, def)
end
end
minetest.register_node(name.."_t_2", {
tiles = {tttm, "blank.png", tts, tts, tt, ttm},
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true,
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
is_ground_content = false,
drop = "",
drawtype = "nodebox",
groups = def.groups,
_mcl_hardness = def._mcl_hardness,
_mcl_blast_resistance = def._mcl_blast_resistance,
sounds = def.sounds,
node_box = {
type = "fixed",
fixed = def.node_box_top
},
selection_box = {
type = "fixed",
fixed = def.selection_box_top
},
after_destruct = function(top, oldnode)
local _t_2_def = table.copy(template_def)
_t_2_def.tiles = {texture_top_toppart_mirrored, "blank.png", texture_top_side, texture_top_side, texture_top, texture_top_mirrored}
_t_2_def.after_destruct = function(top, oldnode)
local meta_top = minetest_get_meta(top)
if meta_top:get_int("rotation") == 1 then
meta_top:set_int("rotation", 0)
@ -550,16 +485,13 @@ function mcl_doors:register_door(name, def)
minetest.dig_node(bottom)
end
end
end,
on_rightclick = on_rightclick,
mesecons = { effector = {
end
_t_2_def.on_rightclick = on_rightclick
_t_2_def.mesecons = { effector = {
action_off = on_mesecons_signal_close_top,
rules = mesecon.rules.flat,
}},
on_rotate = function(top, node, user, mode, param2)
}}
_t_2_def.on_rotate = function(top, node, user, mode, param2)
if mode == screwdriver.ROTATE_FACE then
local meta_top = minetest_get_meta(top)
meta_top:set_int("rotation", 1)
@ -575,10 +507,9 @@ function mcl_doors:register_door(name, def)
return true
end
return false
end,
end
can_dig = check_player_priv,
})
minetest.register_node(name.."_t_2", _t_2_def)
if not def.only_redstone_can_open then
on_rightclick = function(pos, node, clicker)
@ -588,29 +519,9 @@ function mcl_doors:register_door(name, def)
end
end
minetest.register_node(name.."_b_3", {
tiles = {"blank.png", tbm .. "^[transformFY", tbs, tbsm, tb, tbm},
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true,
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
is_ground_content = false,
drop = "",
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = def.node_box_bottom
},
selection_box = {
type = "fixed",
fixed = def.selection_box_bottom
},
groups = def.groups,
_mcl_hardness = def._mcl_hardness,
_mcl_blast_resistance = def._mcl_blast_resistance,
sounds = def.sounds,
after_destruct = function(bottom, oldnode)
local _b_3_def = table.copy(template_def)
_b_3_def.tiles = {"blank.png", texture_bottom_mirrored .. "^[transformFY", texture_bottom_side, texture_bottom_side_mirrored, texture_bottom, texture_bottom_mirrored}
_b_3_def.after_destruct = function(bottom, oldnode)
local meta_bottom = minetest_get_meta(bottom)
if meta_bottom:get_int("rotation") == 1 then
meta_bottom:set_int("rotation", 0)
@ -621,15 +532,12 @@ function mcl_doors:register_door(name, def)
minetest.remove_node(top)
end
end
end,
on_rightclick = on_rightclick,
mesecons = { effector = {
end
_b_3_def.on_rightclick = on_rightclick
_b_3_def.mesecons = { effector = {
action_on = on_mesecons_signal_open,
}},
on_rotate = function(bottom, node, user, mode, param2)
}}
_b_3_def.on_rotate = function(bottom, node, user, mode, param2)
if mode == screwdriver.ROTATE_FACE then
local meta_bottom = minetest_get_meta(bottom)
meta_bottom:set_int("rotation", 1)
@ -645,10 +553,9 @@ function mcl_doors:register_door(name, def)
return true
end
return false
end,
end
can_dig = check_player_priv,
})
minetest.register_node(name.."_b_3", _b_3_def)
if def.only_redstone_can_open then
on_rightclick = nil
@ -660,29 +567,9 @@ function mcl_doors:register_door(name, def)
end
end
minetest.register_node(name.."_t_3", {
tiles = {ttm .. "^[transformFY", "blank.png", tts, ttsm, tt, ttm},
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true,
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
is_ground_content = false,
drop = "",
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = def.node_box_top
},
selection_box = {
type = "fixed",
fixed = def.selection_box_top
},
groups = def.groups,
_mcl_hardness = def._mcl_hardness,
_mcl_blast_resistance = def._mcl_blast_resistance,
sounds = def.sounds,
after_destruct = function(top, oldnode)
local _t_3_def = table.copy(template_def)
_t_3_def.tiles = {texture_top_mirrored .. "^[transformFY", "blank.png", texture_top_side, texture_top_side_mirrored, texture_top, texture_top_mirrored}
_t_3_def.after_destruct = function(top, oldnode)
local meta_top = minetest_get_meta(top)
if meta_top:get_int("rotation") == 1 then
meta_top:set_int("rotation", 0)
@ -692,16 +579,13 @@ function mcl_doors:register_door(name, def)
minetest.dig_node(bottom)
end
end
end,
on_rightclick = on_rightclick,
mesecons = { effector = {
end
_t_3_def.on_rightclick = on_rightclick
_t_3_def.mesecons = { effector = {
action_on = on_mesecons_signal_open_top,
rules = mesecon.rules.flat,
}},
on_rotate = function(top, node, user, mode, param2)
}}
_t_3_def.on_rotate = function(top, node, user, mode, param2)
if mode == screwdriver.ROTATE_FACE then
local meta_top = minetest_get_meta(top)
meta_top:set_int("rotation", 1)
@ -717,10 +601,9 @@ function mcl_doors:register_door(name, def)
return true
end
return false
end,
end
can_dig = check_player_priv,
})
minetest.register_node(name.."_t_3", _t_3_def)
if def.only_redstone_can_open then
on_rightclick = nil
@ -732,28 +615,9 @@ function mcl_doors:register_door(name, def)
end
end
minetest.register_node(name.."_b_4", {
tiles = {"blank.png", tbb, tbsm, tbsm, tbm, tb},
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true,
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
is_ground_content = false,
drop = "",
drawtype = "nodebox",
groups = def.groups,
_mcl_hardness = def._mcl_hardness,
_mcl_blast_resistance = def._mcl_blast_resistance,
sounds = def.sounds,
node_box = {
type = "fixed",
fixed = def.node_box_bottom
},
selection_box = {
type = "fixed",
fixed = def.selection_box_bottom
},
after_destruct = function(bottom, oldnode)
local _b_4_def = table.copy(template_def)
_b_4_def.tiles = {"blank.png", texture_bottom_bottompart, texture_bottom_side_mirrored, texture_bottom_side_mirrored, texture_bottom_mirrored, texture_bottom}
_b_4_def.after_destruct = function(bottom, oldnode)
local meta_bottom = minetest_get_meta(bottom)
if meta_bottom:get_int("rotation") == 1 then
meta_bottom:set_int("rotation", 0)
@ -764,15 +628,12 @@ function mcl_doors:register_door(name, def)
minetest.remove_node(top)
end
end
end,
on_rightclick = on_rightclick,
mesecons = { effector = {
end
_b_4_def.on_rightclick = on_rightclick
_b_4_def.mesecons = { effector = {
action_off = on_mesecons_signal_close,
}},
on_rotate = function(bottom, node, user, mode, param2)
}}
_b_4_def.on_rotate = function(bottom, node, user, mode, param2)
if mode == screwdriver.ROTATE_FACE then
local meta_bottom = minetest_get_meta(bottom)
meta_bottom:set_int("rotation", 1)
@ -788,10 +649,9 @@ function mcl_doors:register_door(name, def)
return true
end
return false
end,
end
can_dig = check_player_priv,
})
minetest.register_node(name.."_b_4", _b_4_def)
if def.only_redstone_can_open then
on_rightclick = nil
@ -803,28 +663,9 @@ function mcl_doors:register_door(name, def)
end
end
minetest.register_node(name.."_t_4", {
tiles = {ttt, "blank.png", ttsm, ttsm, ttm, tt},
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true,
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
is_ground_content = false,
drop = "",
drawtype = "nodebox",
groups = def.groups,
_mcl_hardness = def._mcl_hardness,
_mcl_blast_resistance = def._mcl_blast_resistance,
sounds = def.sounds,
node_box = {
type = "fixed",
fixed = def.node_box_top
},
selection_box = {
type = "fixed",
fixed = def.selection_box_top
},
after_destruct = function(top, oldnode)
local _t_4_def = table.copy(template_def)
_t_4_def.tiles = {texture_top_toppart, "blank.png", texture_top_side_mirrored, texture_top_side_mirrored, texture_top_mirrored, texture_top}
_t_4_def.after_destruct = function(top, oldnode)
local meta_top = minetest_get_meta(top)
if meta_top:get_int("rotation") == 1 then
meta_top:set_int("rotation", 0)
@ -834,16 +675,13 @@ function mcl_doors:register_door(name, def)
minetest.dig_node(bottom)
end
end
end,
on_rightclick = on_rightclick,
mesecons = { effector = {
end
_t_4_def.on_rightclick = on_rightclick
_t_4_def.mesecons = { effector = {
action_off = on_mesecons_signal_close_top,
rules = mesecon.rules.flat,
}},
on_rotate = function(top, node, user, mode, param2)
}}
_t_4_def.on_rotate = function(top, node, user, mode, param2)
if mode == screwdriver.ROTATE_FACE then
local meta_top = minetest_get_meta(top)
meta_top:set_int("rotation", 1)
@ -859,10 +697,9 @@ function mcl_doors:register_door(name, def)
return true
end
return false
end,
end
can_dig = check_player_priv,
})
minetest.register_node(name.."_t_4", _t_4_def)
-- Add entry aliases for the Help