mirror of
https://github.com/mt-mods/homedecor_modpack.git
synced 2024-12-22 16:10:18 +01:00
refactor doors code (#21)
This commit is contained in:
parent
16bcc35ba2
commit
769e14fd11
@ -4,208 +4,137 @@ local S = minetest.get_translator("homedecor_doors_and_gates")
|
|||||||
local mesecons_mp = minetest.get_modpath("mesecons")
|
local mesecons_mp = minetest.get_modpath("mesecons")
|
||||||
homedecor_doors_and_gates = {}
|
homedecor_doors_and_gates = {}
|
||||||
|
|
||||||
-- new doors using minetest_game doors API
|
|
||||||
|
|
||||||
local door_list = {
|
local door_list = {
|
||||||
{
|
{
|
||||||
name = "wood_plain",
|
name = "wood_plain",
|
||||||
description = S("Plain Wooden Door"),
|
description = S("Plain Wooden Door"),
|
||||||
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
|
sounds = default.node_sound_wood_defaults(),
|
||||||
sounds = {
|
sound_open = "homedecor_door_open",
|
||||||
main = default.node_sound_wood_defaults(),
|
sound_close = "homedecor_door_close",
|
||||||
open = "homedecor_door_open",
|
|
||||||
close = "homedecor_door_close",
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name = "exterior_fancy",
|
name = "exterior_fancy",
|
||||||
description = S("Fancy Wood/Glass Door"),
|
description = S("Fancy Wood/Glass Door"),
|
||||||
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
|
sounds = default.node_sound_wood_defaults(),
|
||||||
sounds = {
|
sound_open = "homedecor_door_open",
|
||||||
main = default.node_sound_wood_defaults(),
|
sound_close = "homedecor_door_close",
|
||||||
open = "homedecor_door_open",
|
mesh = "homedecor_door_fancy.obj"
|
||||||
close = "homedecor_door_close",
|
|
||||||
},
|
|
||||||
backface = true,
|
|
||||||
alpha = true,
|
|
||||||
custom_model = "homedecor_door_fancy"
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name = "french_oak",
|
name = "french_oak",
|
||||||
description = S("French door, Oak-colored"),
|
description = S("French door, Oak-colored"),
|
||||||
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
|
sounds = default.node_sound_glass_defaults(),
|
||||||
sounds = {
|
mesh = "homedecor_door_french.obj"
|
||||||
main = default.node_sound_glass_defaults(),
|
|
||||||
},
|
|
||||||
backface = true,
|
|
||||||
alpha = true,
|
|
||||||
custom_model = "homedecor_door_french"
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name = "french_mahogany",
|
name = "french_mahogany",
|
||||||
description = S("French door, Mahogany-colored"),
|
description = S("French door, Mahogany-colored"),
|
||||||
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
|
sounds = default.node_sound_glass_defaults(),
|
||||||
sounds = {
|
mesh = "homedecor_door_french.obj"
|
||||||
main = default.node_sound_glass_defaults(),
|
|
||||||
},
|
|
||||||
backface = true,
|
|
||||||
alpha = true,
|
|
||||||
custom_model = "homedecor_door_french"
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name = "french_white",
|
name = "french_white",
|
||||||
description = S("French door, White"),
|
description = S("French door, White"),
|
||||||
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
|
sounds = default.node_sound_glass_defaults(),
|
||||||
sounds = {
|
mesh = "homedecor_door_french.obj"
|
||||||
main = default.node_sound_glass_defaults(),
|
|
||||||
},
|
|
||||||
backface = true,
|
|
||||||
alpha = true,
|
|
||||||
custom_model = "homedecor_door_french"
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name = "basic_panel",
|
name = "basic_panel",
|
||||||
description = S("Basic white panel Door"),
|
description = S("Basic white panel Door"),
|
||||||
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
|
sounds = default.node_sound_wood_defaults(),
|
||||||
sounds = {
|
sound_open = "homedecor_door_open",
|
||||||
main = default.node_sound_wood_defaults(),
|
sound_close = "homedecor_door_close",
|
||||||
open = "homedecor_door_open",
|
|
||||||
close = "homedecor_door_close",
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name = "wrought_iron",
|
name = "wrought_iron",
|
||||||
description = S("Wrought Iron Gate/Door"),
|
description = S("Wrought Iron Gate/Door"),
|
||||||
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
|
sounds = default.node_sound_metal_defaults(),
|
||||||
sounds = {
|
sound_open = "doors_steel_door_open",
|
||||||
main = default.node_sound_metal_defaults(),
|
sound_close = "doors_steel_door_close",
|
||||||
open = "doors_steel_door_open",
|
mesh = "homedecor_door_wrought_iron.obj"
|
||||||
close = "doors_steel_door_close",
|
|
||||||
},
|
|
||||||
backface = true,
|
|
||||||
custom_model = "homedecor_door_wrought_iron"
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name = "carolina",
|
name = "carolina",
|
||||||
description = S("Wooden Carolina door"),
|
description = S("Wooden Carolina door"),
|
||||||
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
|
sounds = default.node_sound_wood_defaults(),
|
||||||
sounds = {
|
sound_open = "homedecor_door_open",
|
||||||
main = default.node_sound_wood_defaults(),
|
sound_close = "homedecor_door_close",
|
||||||
open = "homedecor_door_open",
|
|
||||||
close = "homedecor_door_close",
|
|
||||||
},
|
|
||||||
backface = true,
|
|
||||||
alpha = true
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name = "woodglass",
|
name = "woodglass",
|
||||||
description = S("Wooden door with glass insert, type 3"),
|
description = S("Wooden door with glass insert, type 3"),
|
||||||
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
|
sounds = default.node_sound_wood_defaults(),
|
||||||
sounds = {
|
sound_open = "homedecor_door_open",
|
||||||
main = default.node_sound_wood_defaults(),
|
sound_close = "homedecor_door_close",
|
||||||
open = "homedecor_door_open",
|
mesh = "homedecor_door_wood_glass_3.obj"
|
||||||
close = "homedecor_door_close",
|
|
||||||
},
|
|
||||||
backface = true,
|
|
||||||
alpha = true,
|
|
||||||
custom_model = "homedecor_door_wood_glass_3"
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name = "closet_mahogany",
|
name = "closet_mahogany",
|
||||||
description = S("Mahogany Closet Door"),
|
description = S("Mahogany Closet Door"),
|
||||||
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
|
sounds = default.node_sound_wood_defaults(),
|
||||||
sounds = {
|
mesh = "homedecor_door_closet.obj"
|
||||||
main = default.node_sound_wood_defaults(),
|
|
||||||
},
|
|
||||||
custom_model = "homedecor_door_closet"
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name = "closet_oak",
|
name = "closet_oak",
|
||||||
description = S("Oak Closet Door"),
|
description = S("Oak Closet Door"),
|
||||||
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
|
sounds = default.node_sound_wood_defaults(),
|
||||||
sounds = {
|
mesh = "homedecor_door_closet"
|
||||||
main = default.node_sound_wood_defaults(),
|
|
||||||
},
|
|
||||||
custom_model = "homedecor_door_closet"
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local old_doors = {}
|
local old_doors = {}
|
||||||
local mesecons
|
|
||||||
|
|
||||||
-- This part blatantly copied from Mesecons, and modified :-)
|
local door_types = {"_a", "_b", "_c", "_d"}
|
||||||
if mesecons_mp then
|
|
||||||
mesecons = {
|
local function generate_door(def)
|
||||||
effector = {
|
local default_settings = {
|
||||||
action_on = function(pos, node)
|
tiles = {{ name = "homedecor_door_" .. def.name .. ".png", backface_culling = true }},
|
||||||
local door = doors.get(pos)
|
inventory_image = "homedecor_door_" .. def.name .. "_inv.png",
|
||||||
if door then
|
use_texture_alpha = "blend",
|
||||||
door:open()
|
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
|
||||||
end
|
mesecons = {
|
||||||
end,
|
effector = {
|
||||||
action_off = function(pos, node)
|
action_on = function(pos, node)
|
||||||
local door = doors.get(pos)
|
local door = doors.get(pos)
|
||||||
if door then
|
if door then door:open() end
|
||||||
door:close()
|
end,
|
||||||
end
|
action_off = function(pos, node)
|
||||||
end,
|
local door = doors.get(pos)
|
||||||
rules = mesecon.rules.pplate
|
if door then door:close() end
|
||||||
}
|
end,
|
||||||
|
rules = mesecon and mesecon.rules.pplate or nil
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for k, v in pairs(default_settings) do
|
||||||
|
if not def[k] then def[k] = v end
|
||||||
|
end
|
||||||
|
|
||||||
|
def.name = nil
|
||||||
|
|
||||||
|
return def
|
||||||
end
|
end
|
||||||
|
|
||||||
local hd_3d = minetest.get_modpath("homedecor_3d_extras")
|
|
||||||
|
|
||||||
for _, door in ipairs(door_list) do
|
for _, door in ipairs(door_list) do
|
||||||
doors.register("homedecor_"..door.name, {
|
local name = door.name
|
||||||
tiles = {{ name = "homedecor_door_"..door.name..".png", backface_culling = door.backface }},
|
doors.register("homedecor_" .. name, generate_door(door))
|
||||||
description = door.description,
|
|
||||||
inventory_image = "homedecor_door_"..door.name.."_inv.png",
|
|
||||||
groups = table.copy(door.groups),
|
|
||||||
sounds = door.sounds.main,
|
|
||||||
sound_open = door.sounds.open,
|
|
||||||
sound_close = door.sounds.close,
|
|
||||||
mesecons = mesecons
|
|
||||||
})
|
|
||||||
|
|
||||||
local nn_a = "doors:homedecor_"..door.name.."_a"
|
--hack to get around doors not allowing custom meshes
|
||||||
local nn_b = "doors:homedecor_"..door.name.."_b"
|
if door.mesh then
|
||||||
|
for _, v in pairs(door_types) do
|
||||||
if door.alpha then
|
minetest.override_item("doors:homedecor_" .. name .. v, {
|
||||||
local def = table.copy(minetest.registered_nodes[nn_a])
|
mesh = door.mesh
|
||||||
def.use_texture_alpha = "blend"
|
})
|
||||||
minetest.register_node(":"..nn_a, def) -- assignment when the override takes place
|
end
|
||||||
|
|
||||||
def = table.copy(minetest.registered_nodes[nn_b])
|
|
||||||
def.use_texture_alpha = "blend"
|
|
||||||
minetest.register_node(":"..nn_b, def)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if door.custom_model and hd_3d then
|
--compatibility
|
||||||
def = table.copy(minetest.registered_nodes[nn_a])
|
old_doors[#old_doors + 1] = "homedecor:door_"..name.."_left"
|
||||||
def.mesh = door.custom_model.."_a.obj"
|
old_doors[#old_doors + 1] = "homedecor:door_"..name.."_right"
|
||||||
minetest.register_node(":"..nn_a, def)
|
|
||||||
|
|
||||||
def = table.copy(minetest.registered_nodes[nn_b])
|
minetest.register_alias("doors:"..name.."_a", "doors:homedecor_"..name.."_a")
|
||||||
def.mesh = door.custom_model.."_b.obj"
|
minetest.register_alias("doors:"..name.."_b", "doors:homedecor_"..name.."_b")
|
||||||
minetest.register_node(":"..nn_b, def)
|
|
||||||
end
|
|
||||||
|
|
||||||
old_doors[#old_doors + 1] = "homedecor:door_"..door.name.."_left"
|
|
||||||
old_doors[#old_doors + 1] = "homedecor:door_"..door.name.."_right"
|
|
||||||
|
|
||||||
minetest.register_alias("doors:"..door.name.."_a", "doors:homedecor_"..door.name.."_a")
|
|
||||||
minetest.register_alias("doors:"..door.name.."_b", "doors:homedecor_"..door.name.."_b")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Gates
|
-- Gates
|
||||||
@ -769,4 +698,4 @@ minetest.register_lbm({
|
|||||||
end
|
end
|
||||||
minetest.set_node({x=pos.x, y=pos.y+1, z=pos.z}, {name = "doors:hidden"})
|
minetest.set_node({x=pos.x, y=pos.y+1, z=pos.z}, {name = "doors:hidden"})
|
||||||
end
|
end
|
||||||
})
|
})
|
Loading…
Reference in New Issue
Block a user