2 minetest,math,pairs,table
4 minetest,math,pairs,table
5 --this is a really lazy way to make a door and I'll improve it in the future
6 for _,material in pairs({"wood","iron"}) do
7 --this is the function that makes the door open and close when rightclicked
8 local door_rightclick = function(pos)
9 local node = minetest.get_node(pos)
10 local name = node.name
11 local opened = minetest.get_item_group(name, "door_open")
12 local closed = minetest.get_item_group(name, "door_closed")
13 local closed = minetest.get_item_group(name, "door_closed")
14 local top = minetest.get_item_group(name, "top")
15 local bottom = minetest.get_item_group(name, "bottom")
16 local param2 = node.param2
17 local pos2 = table.copy(pos)
21 minetest.sound_play("door_close", {pos=pos,pitch=math.random(80,100)/100})
24 minetest.set_node(pos,{name="door:top_"..material.."_closed",param2=param2})
25 minetest.set_node(pos2,{name="door:bottom_"..material.."_closed",param2=param2})
26 elseif bottom > 0 then
28 minetest.set_node(pos,{name="door:bottom_"..material.."_closed",param2=param2})
29 minetest.set_node(pos2,{name="door:top_"..material.."_closed",param2=param2})
32 elseif closed > 0 then
33 minetest.sound_play("door_open", {pos=pos,pitch=math.random(80,100)/100})
36 minetest.set_node(pos,{name="door:top_"..material.."_open",param2=param2})
37 minetest.set_node(pos2,{name="door:bottom_"..material.."_open",param2=param2})
38 elseif bottom > 0 then
40 minetest.set_node(pos,{name="door:bottom_"..material.."_open",param2=param2})
41 minetest.set_node(pos2,{name="door:top_"..material.."_open",param2=param2})
46 --this is where the top and bottom of the door are created
47 for _,door in pairs({"top","bottom"}) do
48 for _,state in pairs({"open","closed"}) do
49 local door_node_box = {}
50 if state == "closed" then
51 door_node_box = {-0.5, -0.5, -0.5, 0.5, 0.5, -0.3}
52 elseif state == "open" then
53 door_node_box = {5/16, -0.5, -0.5, 0.5, 0.5, 0.5}
60 local redstone_deactivation
61 local redstone_activation
62 --make it so only the bottom activates
64 if material == "wood" then
65 sounds = main.woodSound()
66 on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
70 if door == "bottom" then
72 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)}
74 if state == "open" then
75 redstone_deactivation = function(pos)
78 elseif state == "closed" then
79 redstone_activation = function(pos)
85 if state == "closed" then
86 tiles = {"wood.png","wood.png","wood.png","wood.png","wood_door_top.png","wood_door_top.png"}
87 elseif state == "open" then
88 tiles = {"wood.png","wood.png","wood_door_top.png","wood_door_top.png","wood.png","wood.png"}
90 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)}
92 elseif material == "iron" then
93 sounds = main.stoneSound()
97 if door == "bottom" then
98 tiles = {"iron_block.png"}
99 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)}
101 if state == "open" then
102 redstone_deactivation = function(pos)
105 elseif state == "closed" then
106 redstone_activation = function(pos)
111 if state == "closed" then
112 tiles = {"iron_block.png","iron_block.png","iron_block.png","iron_block.png","iron_door_top.png","iron_door_top.png"}
113 elseif state == "open" then
114 tiles = {"iron_block.png","iron_block.png","iron_door_top.png","iron_door_top.png","iron_block.png","iron_block.png"}
118 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)}
121 minetest.register_node("door:"..door.."_"..material.."_"..state, {
122 description = material:gsub("^%l", string.upper).." Door",
124 wield_image = "door_inv_"..material..".png",
125 inventory_image = "door_inv_"..material..".png",
126 drawtype = "nodebox",
128 paramtype2 = "facedir",
131 drop = "door:bottom_"..material.."_closed",
132 node_placement_prediction = "",
136 --left front bottom right back top
140 --redstone activation is in both because only the bottom is defined as an activator and it's easier to do it like this
141 redstone_activation = redstone_activation,
142 redstone_deactivation = redstone_deactivation,
143 on_rightclick = on_rightclick,
144 after_place_node = function(pos, placer, itemstack, pointed_thing)
145 local node = minetest.get_node(pos)
146 local param2 = node.param2
147 local pos2 = table.copy(pos)
149 if minetest.get_node(pos2).name == "air" then
150 minetest.set_node(pos2,{name="door:top_"..material.."_closed",param2=param2})
152 minetest.remove_node(pos)
153 itemstack:add_item(ItemStack("door:bottom_"..material.."_closed"))
156 after_dig_node = function(pos, oldnode, oldmetadata, digger)
157 if string.match(oldnode.name, ":bottom") then
159 minetest.remove_node(pos)
162 minetest.remove_node(pos)
168 minetest.register_craft({
169 output = "door:bottom_"..material.."_closed",
171 {"main:"..material,"main:"..material},
172 {"main:"..material,"main:"..material},
173 {"main:"..material,"main:"..material}