1 --this is a really lazy way to make a door and I'll improve it in the future
2 for _,material in pairs({"wood","iron"}) do
3 --this is the function that makes the door open and close when rightclicked
4 local door_rightclick = function(pos)
5 local node = minetest.get_node(pos)
7 local opened = minetest.get_node_group(name, "door_open")
8 local closed = minetest.get_node_group(name, "door_closed")
9 local closed = minetest.get_node_group(name, "door_closed")
10 local top = minetest.get_node_group(name, "top")
11 local bottom = minetest.get_node_group(name, "bottom")
12 local param2 = node.param2
13 local pos2 = table.copy(pos)
17 minetest.sound_play("door_close", {pos=pos,pitch=math.random(80,100)/100})
20 minetest.set_node(pos,{name="door:top_"..material.."_closed",param2=param2})
21 minetest.set_node(pos2,{name="door:bottom_"..material.."_closed",param2=param2})
22 elseif bottom > 0 then
24 minetest.set_node(pos,{name="door:bottom_"..material.."_closed",param2=param2})
25 minetest.set_node(pos2,{name="door:top_"..material.."_closed",param2=param2})
28 elseif closed > 0 then
29 minetest.sound_play("door_open", {pos=pos,pitch=math.random(80,100)/100})
32 minetest.set_node(pos,{name="door:top_"..material.."_open",param2=param2})
33 minetest.set_node(pos2,{name="door:bottom_"..material.."_open",param2=param2})
34 elseif bottom > 0 then
36 minetest.set_node(pos,{name="door:bottom_"..material.."_open",param2=param2})
37 minetest.set_node(pos2,{name="door:top_"..material.."_open",param2=param2})
42 --this is where the top and bottom of the door are created
43 for _,door in pairs({"top","bottom"}) do
44 for _,state in pairs({"open","closed"}) do
45 local door_node_box = {}
46 if state == "closed" then
47 door_node_box = {-0.5, -0.5, -0.5, 0.5, 0.5, -0.3}
48 elseif state == "open" then
49 door_node_box = {5/16, -0.5, -0.5, 0.5, 0.5, 0.5}
56 local redstone_deactivation
57 local redstone_activation
58 --make it so only the bottom activates
60 if material == "wood" then
61 sounds = main.woodSound()
62 on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
66 if door == "bottom" then
68 groups = {wood = 2, tree = 1, hard = 1, axe = 1, hand = 3, redstone_activation = 1,bottom = 1,door_open = ((state == "open" and 1) or 0),door_closed = ((state == "closed" and 1) or 0)}
70 if state == "open" then
71 redstone_deactivation = function(pos)
74 elseif state == "closed" then
75 redstone_activation = function(pos)
81 if state == "closed" then
82 tiles = {"wood.png","wood.png","wood.png","wood.png","wood_door_top.png","wood_door_top.png"}
83 elseif state == "open" then
84 tiles = {"wood.png","wood.png","wood_door_top.png","wood_door_top.png","wood.png","wood.png"}
86 groups = {wood = 2, tree = 1, hard = 1, axe = 1, hand = 3,top = 1,door_open = ((state == "open" and 1) or 0),door_closed = ((state == "closed" and 1) or 0)}
88 elseif material == "iron" then
89 sounds = main.stoneSound()
93 if door == "bottom" then
94 tiles = {"iron_block.png"}
95 groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4, redstone_activation = 1,bottom = 1,door_open = ((state == "open" and 1) or 0),door_closed = ((state == "closed" and 1) or 0)}
97 if state == "open" then
98 redstone_deactivation = function(pos)
101 elseif state == "closed" then
102 redstone_activation = function(pos)
107 if state == "closed" then
108 tiles = {"iron_block.png","iron_block.png","iron_block.png","iron_block.png","iron_door_top.png","iron_door_top.png"}
109 elseif state == "open" then
110 tiles = {"iron_block.png","iron_block.png","iron_door_top.png","iron_door_top.png","iron_block.png","iron_block.png"}
114 groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,top = 1,door_open = ((state == "open" and 1) or 0),door_closed = ((state == "closed" and 1) or 0)}
117 minetest.register_node("door:"..door.."_"..material.."_"..state, {
118 description = material:gsub("^%l", string.upper).." Door",
120 wield_image = "door_inv_"..material..".png",
121 inventory_image = "door_inv_"..material..".png",
122 drawtype = "nodebox",
124 paramtype2 = "facedir",
127 drop = "door:bottom_"..material.."_closed",
128 node_placement_prediction = "",
132 --left front bottom right back top
136 --redstone activation is in both because only the bottom is defined as an activator and it's easier to do it like this
137 redstone_activation = redstone_activation,
138 redstone_deactivation = redstone_deactivation,
139 on_rightclick = on_rightclick,
140 after_place_node = function(pos, placer, itemstack, pointed_thing)
141 local node = minetest.get_node(pos)
142 local param2 = node.param2
143 local pos2 = table.copy(pos)
145 if minetest.get_node(pos2).name == "air" then
146 minetest.set_node(pos2,{name="door:top_"..material.."_closed",param2=param2})
148 minetest.remove_node(pos)
149 itemstack:add_item(ItemStack("door:bottom_"..material.."_closed"))
152 after_dig_node = function(pos, oldnode, oldmetadata, digger)
153 if string.match(oldnode.name, ":bottom") then
155 minetest.remove_node(pos)
158 minetest.remove_node(pos)
164 minetest.register_craft({
165 output = "door:bottom_"..material.."_closed",
167 {"main:"..material,"main:"..material},
168 {"main:"..material,"main:"..material},
169 {"main:"..material,"main:"..material}