diff --git a/init.lua b/init.lua index 68ff9a6..9d87fd4 100755 --- a/init.lua +++ b/init.lua @@ -1,6 +1,32 @@ ts_doors = {} +local function copytable(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[copytable(orig_key)] = copytable(orig_value) + end + setmetatable(copy, copytable(getmetatable(orig))) + else + copy = orig + end + return copy +end + +local function register_alias(name, convert_to) + minetest.register_alias(name , convert_to ) + minetest.register_alias(name .. "_a", convert_to .. "_a") + minetest.register_alias(name .. "_b", convert_to .. "_b") +end + function ts_doors.register_door(recipe, description, texture) + register_alias("doors:ts_door_" .. recipe:gsub(":", "_"), "ts_doors:door_" .. recipe:gsub(":", "_")) + register_alias("doors:ts_door_full_" .. recipe:gsub(":", "_"), "ts_doors:door_full_" .. recipe:gsub(":", "_")) + register_alias("doors:ts_door_locked_" .. recipe:gsub(":", "_"), "ts_doors:door_locked_" .. recipe:gsub(":", "_")) + register_alias("doors:ts_door_full_locked_" .. recipe:gsub(":", "_"), "ts_doors:door_full_locked_" .. recipe:gsub(":", "_")) + local groups = minetest.registered_nodes[recipe].groups local door_groups = {} for k,v in pairs(groups) do @@ -8,7 +34,10 @@ function ts_doors.register_door(recipe, description, texture) door_groups[k] = v end end - doors.register("ts_door_" .. recipe:gsub(":", "_"), { + + trapdoor_groups = copytable(door_groups) + + doors.register("ts_doors:door_" .. recipe:gsub(":", "_"), { tiles = {{ name = "[combine:32x38:0,0=" .. texture .. ":0,16=" .. texture .. ":0,32=" .. texture .. ":16,0=" .. texture .. ":16,16=" .. texture .. ":16,32=" .. texture .. "^[transformR270^[colorize:#fff:30^ts_doors_base.png^[noalpha^[makealpha:0,255,0", backface_culling = true }}, description = description .. " Door", inventory_image = "[combine:32x38:0,0=" .. texture .. ":0,16=" .. texture .. ":16,0=" .. texture .. ":16,16=" .. texture .. "^[transformR270^[colorize:#fff:30^ts_doors_base_inv.png^[noalpha^[makealpha:0,255,0", @@ -20,22 +49,55 @@ function ts_doors.register_door(recipe, description, texture) } }) - doors.register("ts_door_full_" .. recipe:gsub(":", "_"), { + doors.register("ts_doors:door_full_" .. recipe:gsub(":", "_"), { tiles = {{ name = "[combine:32x38:0,0=" .. texture .. ":0,16=" .. texture .. ":0,32=" .. texture .. ":16,0=" .. texture .. ":16,16=" .. texture .. ":16,32=" .. texture .. "^[transformR270^[colorize:#fff:30^ts_doors_base_full.png^[noalpha", backface_culling = true }}, description = description .. " Door", inventory_image = "[combine:32x38:0,0=" .. texture .. ":0,16=" .. texture .. ":16,0=" .. texture .. ":16,16=" .. texture .. "^[transformR270^[colorize:#fff:30^ts_doors_base_full_inv.png^[noalpha^[makealpha:0,255,0", groups = door_groups, recipe = { {recipe}, - {"doors:ts_door_" .. recipe:gsub(":", "_")}, + {"ts_doors:door_" .. recipe:gsub(":", "_")}, } }) + doors.register_trapdoor("ts_doors:trapdoor_" .. recipe:gsub(":", "_"), { + description = description .. " Trapdoor", + inventory_image = texture .. "^[transformR270^[colorize:#fff:30^ts_doors_base_trapdoor.png^[noalpha^[makealpha:0,255,0", + wield_image = texture .. "^[transformR270^[colorize:#fff:30^ts_doors_base_trapdoor.png^[noalpha^[makealpha:0,255,0", + tile_front = texture .. "^[transformR270^[colorize:#fff:30^ts_doors_base_trapdoor.png^[noalpha^[makealpha:0,255,0", + tile_side = texture .. "^[colorize:#fff:30", + groups = trapdoor_groups, + }) + doors.register_trapdoor("ts_doors:trapdoor_full_" .. recipe:gsub(":", "_"), { + description = description .. " Trapdoor", + inventory_image = texture .. "^[transformR270^[colorize:#fff:30^ts_doors_base_trapdoor_full.png^[noalpha", + wield_image = texture .. "^[transformR270^[colorize:#fff:30^ts_doors_base_trapdoor_full.png^[noalpha", + tile_front = texture .. "^[transformR270^[colorize:#fff:30^ts_doors_base_trapdoor_full.png^[noalpha", + tile_side = texture .. "^[colorize:#fff:30", + groups = trapdoor_groups, + }) + + minetest.register_craft({ + output = "ts_doors:trapdoor_" .. recipe:gsub(":", "_"), + recipe = { + {recipe, recipe}, + {recipe, recipe}, + } + }) + + minetest.register_craft({ + output = "ts_doors:trapdoor_full_" .. recipe:gsub(":", "_"), + recipe = { + {recipe}, + {"ts_doors:trapdoor_" .. recipe:gsub(":", "_")}, + } + }) door_groups.level = 2 + trapdoor_groups.level = 2 - doors.register("ts_door_locked_" .. recipe:gsub(":", "_"), { + doors.register("ts_doors:door_locked_" .. recipe:gsub(":", "_"), { tiles = {{ name = "[combine:32x38:0,0=" .. texture .. ":0,16=" .. texture .. ":0,32=" .. texture .. ":16,0=" .. texture .. ":16,16=" .. texture .. ":16,32=" .. texture .. "^[transformR270^[colorize:#fff:30^ts_doors_base_locked.png^[noalpha^[makealpha:0,255,0", backface_culling = true }}, description = description .. " Locked Door", inventory_image = "[combine:32x38:0,0=" .. texture .. ":0,16=" .. texture .. ":16,0=" .. texture .. ":16,16=" .. texture .. "^[transformR270^[colorize:#fff:30^ts_doors_base_locked_inv.png^[noalpha^[makealpha:0,255,0", @@ -50,7 +112,7 @@ function ts_doors.register_door(recipe, description, texture) } }) - doors.register("ts_door_full_locked_" .. recipe:gsub(":", "_"), { + doors.register("ts_doors:door_full_locked_" .. recipe:gsub(":", "_"), { tiles = {{ name = "[combine:32x38:0,0=" .. texture .. ":0,16=" .. texture .. ":0,32=" .. texture .. ":16,0=" .. texture .. ":16,16=" .. texture .. ":16,32=" .. texture .. "^[transformR270^[colorize:#fff:30^ts_doors_base_full_locked.png^[noalpha", backface_culling = true }}, description = description .. " Locked Door", inventory_image = "[combine:32x38:0,0=" .. texture .. ":0,16=" .. texture .. ":16,0=" .. texture .. ":16,16=" .. texture .. "^[transformR270^[colorize:#fff:30^ts_doors_base_full_locked_inv.png^[noalpha^[makealpha:0,255,0", @@ -60,7 +122,49 @@ function ts_doors.register_door(recipe, description, texture) sound_close = "doors_steel_door_close", recipe = { {recipe}, - {"doors:ts_door_locked_" .. recipe:gsub(":", "_")}, + {"ts_doors:door_locked_" .. recipe:gsub(":", "_")}, + } + }) + + doors.register_trapdoor("ts_doors:trapdoor_locked_" .. recipe:gsub(":", "_"), { + description = description .. " Locked Trapdoor", + inventory_image = texture .. "^[transformR270^[colorize:#fff:30^ts_doors_base_trapdoor_locked.png^[noalpha^[makealpha:0,255,0", + wield_image = texture .. "^[transformR270^[colorize:#fff:30^ts_doors_base_trapdoor_locked.png^[noalpha^[makealpha:0,255,0", + tile_front = texture .. "^[transformR270^[colorize:#fff:30^ts_doors_base_trapdoor_locked.png^[noalpha^[makealpha:0,255,0", + tile_side = texture .. "^[colorize:#fff:30", + protected = true, + sounds = default.node_sound_stone_defaults(), + sound_open = "doors_steel_door_open", + sound_close = "doors_steel_door_close", + groups = trapdoor_groups + }) + + doors.register_trapdoor("ts_doors:trapdoor_full_locked_" .. recipe:gsub(":", "_"), { + description = description .. " Locked Trapdoor", + inventory_image = texture .. "^[transformR270^[colorize:#fff:30^ts_doors_base_trapdoor_full_locked.png^[noalpha", + wield_image = texture .. "^[transformR270^[colorize:#fff:30^ts_doors_base_trapdoor_full_locked.png^[noalpha", + tile_front = texture .. "^[transformR270^[colorize:#fff:30^ts_doors_base_trapdoor_full_locked.png^[noalpha", + tile_side = texture .. "^[colorize:#fff:30", + protected = true, + sounds = default.node_sound_stone_defaults(), + sound_open = "doors_steel_door_open", + sound_close = "doors_steel_door_close", + groups = trapdoor_groups + }) + + minetest.register_craft({ + output = "ts_doors:trapdoor_locked_" .. recipe:gsub(":", "_"), + recipe = { + {"default:steel_ingot"}, + {"ts_doors:trapdoor_" .. recipe:gsub(":", "_")}, + } + }) + + minetest.register_craft({ + output = "ts_doors:trapdoor_full_locked_" .. recipe:gsub(":", "_"), + recipe = { + {recipe}, + {"ts_doors:trapdoor_locked_" .. recipe:gsub(":", "_")}, } }) end diff --git a/textures/ts_doors_base_trapdoor.png b/textures/ts_doors_base_trapdoor.png new file mode 100644 index 0000000..dcfe61d Binary files /dev/null and b/textures/ts_doors_base_trapdoor.png differ diff --git a/textures/ts_doors_base_trapdoor_full.png b/textures/ts_doors_base_trapdoor_full.png new file mode 100644 index 0000000..84da220 Binary files /dev/null and b/textures/ts_doors_base_trapdoor_full.png differ diff --git a/textures/ts_doors_base_trapdoor_full_locked.png b/textures/ts_doors_base_trapdoor_full_locked.png new file mode 100644 index 0000000..68cd8f2 Binary files /dev/null and b/textures/ts_doors_base_trapdoor_full_locked.png differ diff --git a/textures/ts_doors_base_trapdoor_locked.png b/textures/ts_doors_base_trapdoor_locked.png new file mode 100644 index 0000000..109220e Binary files /dev/null and b/textures/ts_doors_base_trapdoor_locked.png differ