2 minetest,math,pairs,table
4 minetest,math,pairs,table
6 local get_item_group = minetest.get_item_group
7 local get_node = minetest.get_node
8 local set_node = minetest.set_node
9 local play_sound = minetest.sound_play
10 local t_copy = table.copy
24 for _,material in pairs({"wood","iron"}) do
25 --this is the function that makes the door open and close when rightclicked
26 local door_rightclick = function(pos)
29 opened = get_item_group(name, "door_open")
30 closed = get_item_group(name, "door_closed")
31 closed = get_item_group(name, "door_closed")
32 top = get_item_group(name, "top")
33 bottom = get_item_group(name, "bottom")
39 play_sound("door_close", {pos=pos,pitch=math.random(80,100)/100})
42 set_node(pos,{name="door:top_"..material.."_closed",param2=param2})
43 set_node(pos2,{name="door:bottom_"..material.."_closed",param2=param2})
44 elseif bottom > 0 then
46 set_node(pos,{name="door:bottom_"..material.."_closed",param2=param2})
47 set_node(pos2,{name="door:top_"..material.."_closed",param2=param2})
50 elseif closed > 0 then
51 play_sound("door_open", {pos=pos,pitch=math.random(80,100)/100})
54 set_node(pos,{name="door:top_"..material.."_open",param2=param2})
55 set_node(pos2,{name="door:bottom_"..material.."_open",param2=param2})
56 elseif bottom > 0 then
58 set_node(pos,{name="door:bottom_"..material.."_open",param2=param2})
59 set_node(pos2,{name="door:top_"..material.."_open",param2=param2})
64 --this is where the top and bottom of the door are created
65 for _,door in pairs({"top","bottom"}) do
66 for _,state in pairs({"open","closed"}) do
67 local door_node_box = {}
68 if state == "closed" then
69 door_node_box = {-0.5, -0.5, -0.5, 0.5, 0.5, -0.3}
70 elseif state == "open" then
71 door_node_box = {5/16, -0.5, -0.5, 0.5, 0.5, 0.5}
78 local redstone_deactivation
79 local redstone_activation
80 --make it so only the bottom activates
82 if material == "wood" then
83 sounds = main.woodSound()
84 on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
88 if door == "bottom" then
90 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)}
92 if state == "open" then
93 redstone_deactivation = function(pos)
96 elseif state == "closed" then
97 redstone_activation = function(pos)
103 if state == "closed" then
104 tiles = {"wood.png","wood.png","wood.png","wood.png","wood_door_top.png","wood_door_top.png"}
105 elseif state == "open" then
106 tiles = {"wood.png","wood.png","wood_door_top.png","wood_door_top.png","wood.png","wood.png"}
108 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)}
110 elseif material == "iron" then
111 sounds = main.stoneSound()
115 if door == "bottom" then
116 tiles = {"iron_block.png"}
117 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)}
119 if state == "open" then
120 redstone_deactivation = function(pos)
123 elseif state == "closed" then
124 redstone_activation = function(pos)
129 if state == "closed" then
130 tiles = {"iron_block.png","iron_block.png","iron_block.png","iron_block.png","iron_door_top.png","iron_door_top.png"}
131 elseif state == "open" then
132 tiles = {"iron_block.png","iron_block.png","iron_door_top.png","iron_door_top.png","iron_block.png","iron_block.png"}
136 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)}
139 minetest.register_node("door:"..door.."_"..material.."_"..state, {
140 description = material:gsub("^%l", string.upper).." Door",
142 wield_image = "door_inv_"..material..".png",
143 inventory_image = "door_inv_"..material..".png",
144 drawtype = "nodebox",
146 paramtype2 = "facedir",
149 drop = "door:bottom_"..material.."_closed",
150 node_placement_prediction = "",
154 --left front bottom right back top
158 --redstone activation is in both because only the bottom is defined as an activator and it's easier to do it like this
159 redstone_activation = redstone_activation,
160 redstone_deactivation = redstone_deactivation,
161 on_rightclick = on_rightclick,
162 after_place_node = function(pos, placer, itemstack, pointed_thing)
163 local node = get_node(pos)
164 local param2 = node.param2
165 local pos2 = t_copy(pos)
167 if get_node(pos2).name == "air" then
168 set_node(pos2,{name="door:top_"..material.."_closed",param2=param2})
170 minetest.remove_node(pos)
171 itemstack:add_item(ItemStack("door:bottom_"..material.."_closed"))
174 after_dig_node = function(pos, oldnode, oldmetadata, digger)
175 if string.match(oldnode.name, ":bottom") then
177 minetest.remove_node(pos)
180 minetest.remove_node(pos)
186 minetest.register_craft({
187 output = "door:bottom_"..material.."_closed",
189 {"main:"..material,"main:"..material},
190 {"main:"..material,"main:"..material},
191 {"main:"..material,"main:"..material}