Remove inventory images of some internal nodes
[MineClone/MineClone2.git] / mods / ITEMS / mcl_fences / init.lua
blob90629d68a3d32dc2338e89a67bf337de6398bd5c
1 local init = os.clock()
3 -- Node box
4 local p = {-2/16, -0.5, -2/16, 2/16, 0.5, 2/16}
5 local x1 = {-0.5, 4/16, -1/16, -2/16, 7/16, 1/16} --oben(quer) -x
6 local x12 = {-0.5, -2/16, -1/16, -2/16, 1/16, 1/16} --unten(quer) -x
7 local x2 = {2/16, 4/16, -1/16, 0.5, 7/16, 1/16} --oben(quer) x
8 local x22 = {2/16, -2/16, -1/16, 0.5, 1/16, 1/16} --unten(quer) x
9 local z1 = {-1/16, 4/16, -0.5, 1/16, 7/16, -2/16} --oben(quer) -z
10 local z12 = {-1/16, -2/16, -0.5, 1/16, 1/16, -2/16} --unten(quer) -z
11 local z2 = {-1/16, 4/16, 2/16, 1/16, 7/16, 0.5} --oben(quer) z
12 local z22 = {-1/16, -2/16, 2/16, 1/16, 1/16, 0.5} --unten(quer) z
14 -- Collision box
15 local cp = {-2/16, -0.5, -2/16, 2/16, 1.01, 2/16}
16 local cx1 = {-0.5, -2/16, -2/16, -2/16, 1.01, 2/16} --unten(quer) -x
17 local cx2 = {2/16, -2/16, -2/16, 0.5, 1.01, 2/16} --unten(quer) x
18 local cz1 = {-2/16, -2/16, -0.5, 2/16, 1.01, -2/16} --unten(quer) -z
19 local cz2 = {-2/16, -2/16, 2/16, 2/16, 1.01, 0.5} --unten(quer) z
21 mcl_fences = {}
23 mcl_fences.register_fence = function(id, fence_name, texture, groups, hardness, blast_resistance, connects_to, sounds)
24 local cgroups = table.copy(groups)
25 if cgroups == nil then cgroups = {} end
26 cgroups.fence = 1
27 cgroups.deco_block = 1
28 if connects_to == nil then
29 connects_to = {}
30 else
31 connects_to = table.copy(connects_to)
32 end
33 local fence_id = minetest.get_current_modname()..":"..id
34 table.insert(connects_to, "group:solid")
35 table.insert(connects_to, "group:fence_gate")
36 table.insert(connects_to, fence_id)
37 minetest.register_node(fence_id, {
38 description = fence_name,
39 _doc_items_longdesc = "Fences are structures which block the way. Fences will connect to each other and solid blocks. They cannot be jumped over with a simple jump.",
40 tiles = {texture},
41 inventory_image = "mcl_fences_fence_mask.png^" .. texture .. "^mcl_fences_fence_mask.png^[makealpha:255,126,126",
42 wield_image = "mcl_fences_fence_mask.png^" .. texture .. "^mcl_fences_fence_mask.png^[makealpha:255,126,126",
43 paramtype = "light",
44 is_ground_content = false,
45 groups = cgroups,
46 stack_max = 64,
47 sunlight_propagates = true,
48 drawtype = "nodebox",
49 connect_sides = { "front", "back", "left", "right" },
50 connects_to = connects_to,
51 node_box = {
52 type = "connected",
53 fixed = {p},
54 connect_front = {z1,z12},
55 connect_back = {z2,z22,},
56 connect_left = {x1,x12},
57 connect_right = {x2,x22},
59 collision_box = {
60 type = "connected",
61 fixed = {cp},
62 connect_front = {cz1},
63 connect_back = {cz2,},
64 connect_left = {cx1},
65 connect_right = {cx2},
67 sounds = sounds,
68 _mcl_blast_resistance = blast_resistance,
69 _mcl_hardness = hardness,
72 return fence_id
73 end
75 mcl_fences.register_fence_gate = function(id, fence_gate_name, texture, groups, hardness, blast_resistance, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close)
76 local meta2
77 local state2 = 0
79 local function update_gate(pos, node)
80 minetest.set_node(pos, node)
81 end
83 local gate_id = minetest.get_current_modname()..":"..id.."_gate"
84 local open_gate_id = gate_id .. "_open"
85 if not sound_open then
86 sound_open = "doors_fencegate_open"
87 end
88 if not sound_close then
89 sound_close = "doors_fencegate_close"
90 end
91 if not sound_gain_open then
92 sound_gain_open = 0.3
93 end
94 if not sound_gain_close then
95 sound_gain_close = 0.3
96 end
97 local function punch_gate(pos, node)
98 meta2 = minetest.get_meta(pos)
99 state2 = meta2:get_int("state")
100 local tmp_node2
101 if state2 == 1 then
102 state2 = 0
103 minetest.sound_play(sound_close, {gain = sound_gain_close, max_hear_distance = 10, pos = pos})
104 tmp_node2 = {name=gate_id, param1=node.param1, param2=node.param2}
105 else
106 state2 = 1
107 minetest.sound_play(sound_open, {gain = sound_gain_open, max_hear_distance = 10, pos = pos})
108 tmp_node2 = {name=open_gate_id, param1=node.param1, param2=node.param2}
110 update_gate(pos, tmp_node2)
111 meta2:set_int("state", state2)
114 local on_rotate
115 if minetest.get_modpath("screwdriver") then
116 on_rotate = screwdriver.rotate_simple
119 local cgroups = table.copy(groups)
120 if cgroups == nil then cgroups = {} end
121 cgroups.fence_gate = 1
122 cgroups.deco_block = 1
124 cgroups.mesecon_ignore_opaque_dig = 1
125 cgroups.mesecon_effector_on = 1
126 cgroups.fence_gate = 1
127 minetest.register_node(open_gate_id, {
128 tiles = {texture},
129 paramtype = "light",
130 paramtype2 = "facedir",
131 is_ground_content = false,
132 sunlight_propagates = true,
133 walkable = false,
134 groups = cgroups,
135 drop = gate_id,
136 drawtype = "nodebox",
137 node_box = {
138 type = "fixed",
139 fixed = {
140 {-0.5, -3/16, -1/16, -6/16, 0.5, 1/16}, --links abschluss
141 {6/16, -3/16, -1/16, 0.5, 0.5, 1/16}, --rechts abschluss
142 {-0.5, 4/16, 1/16, -6/16, 7/16, 6/16}, --oben-links(quer) x
143 {-0.5, -2/16, 1/16, -6/16, 1/16, 6/16}, --unten-links(quer) x
144 {6/16, 4/16, 1/16, 0.5, 7/16, 0.5}, --oben-rechts(quer) x
145 {6/16, -2/16, 1/16, 0.5, 1/16, 0.5}, --unten-rechts(quer) x
146 {-0.5, -2/16, 6/16, -6/16, 7/16, 0.5}, --mitte links
147 {6/16, 1/16, 0.5, 0.5, 4/16, 6/16}, --mitte rechts
150 selection_box = {
151 type = "fixed",
152 fixed = {
153 {-0.5, -3/16, -1/16, 0.5, 0.5, 1/16}, --gate
156 on_rightclick = function(pos, node, clicker)
157 punch_gate(pos, node)
158 end,
159 mesecons = {effector = {
160 action_off = (function(pos, node)
161 punch_gate(pos, node)
162 end),
164 on_rotate = on_rotate,
165 sounds = sounds,
166 _mcl_blast_resistance = blast_resistance,
167 _mcl_hardness = hardness,
170 local cgroups_closed = table.copy(cgroups)
171 cgroups_closed.mesecon_effector_on = nil
172 cgroups_closed.mesecon_effector_off = nil
173 minetest.register_node(gate_id, {
174 description = fence_gate_name,
175 _doc_items_longdesc = "Fence gates can be opened or closed and can't be jumped over. Fences will connect nicely to fence gates.",
176 _doc_items_usagehelp = "Right-click the fence gate to open or close it.",
177 tiles = {texture},
178 inventory_image = "mcl_fences_fence_gate_mask.png^" .. texture .. "^mcl_fences_fence_gate_mask.png^[makealpha:255,126,126",
179 wield_image = "mcl_fences_fence_gate_mask.png^" .. texture .. "^mcl_fences_fence_gate_mask.png^[makealpha:255,126,126",
180 paramtype = "light",
181 is_ground_content = false,
182 stack_max = 64,
183 paramtype2 = "facedir",
184 sunlight_propagates = true,
185 walkable = true,
186 groups = cgroups_closed,
187 drawtype = "nodebox",
188 node_box = {
189 type = "fixed",
190 fixed = {
191 {-0.5, -3/16, -1/16, -6/16, 0.5, 1/16}, --links abschluss
192 {6/16, -3/16, -1/16, 0.5, 0.5, 1/16}, --rechts abschluss
193 {-2/16, -2/16, -1/16, 0, 7/16, 1/16}, --mitte links
194 {0, -2/16, -1/16, 2/16, 7/16, 1/16}, --mitte rechts
195 {-0.5, 4/16, -1/16, -2/16, 7/16, 1/16}, --oben(quer) -z
196 {-0.5, -2/16, -1/16, -2/16, 1/16, 1/16}, --unten(quer) -z
197 {2/16, 4/16, -1/16, 0.5, 7/16, 1/16}, --oben(quer) z
198 {2/16, -2/16, -1/16, 0.5, 1/16, 1/16}, --unten(quer) z
201 collision_box = {
202 type = "fixed",
203 fixed = {
204 {-0.5, -3/16, -2/16, 0.5, 1, 2/16}, --gate
207 selection_box = {
208 type = "fixed",
209 fixed = {
210 {-0.5, -3/16, -1/16, 0.5, 0.5, 1/16}, --gate
213 on_construct = function(pos)
214 meta2 = minetest.get_meta(pos)
215 meta2:set_int("state", 0)
216 state2 = 0
217 end,
218 mesecons = {effector = {
219 action_on = (function(pos, node)
220 punch_gate(pos, node)
221 end),
223 on_rotate = on_rotate,
224 on_rightclick = function(pos, node, clicker)
225 punch_gate(pos, node)
226 end,
227 sounds = sounds,
228 _mcl_blast_resistance = blast_resistance,
229 _mcl_hardness = hardness,
232 if minetest.get_modpath("doc") then
233 doc.add_entry_alias("nodes", gate_id, "nodes", open_gate_id)
236 return gate_id, open_gate_id
239 mcl_fences.register_fence_and_fence_gate = function(id, fence_name, fence_gate_name, texture_fence, groups, hardness, blast_resistance, connects_to, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close, texture_fence_gate)
240 if texture_fence_gate == nil then
241 texture_fence_gate = texture_fence
243 local fence_id = mcl_fences.register_fence(id, fence_name, texture_fence, groups, hardness, blast_resistance, connects_to, sounds)
244 local gate_id, open_gate_id = mcl_fences.register_fence_gate(id, fence_gate_name, texture_fence_gate, groups, hardness, blast_resistance, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close)
245 return fence_id, gate_id, open_gate_id
248 local wood_groups = {handy=1,axey=1, flammable=2,fence_wood=1}
249 local wood_connect = {"group:fence_wood"}
250 local wood_sounds = mcl_sounds.node_sound_wood_defaults()
252 local woods = {
253 {"", "Oak Fence", "Oak Fence Gate", "mcl_fences_fence_oak.png", "mcl_fences_fence_gate_oak.png", "mcl_core:wood"},
254 {"spruce", "Spruce Fence", "Spruce Fence Gate", "mcl_fences_fence_spruce.png", "mcl_fences_fence_gate_spruce.png", "mcl_core:sprucewood"},
255 {"birch", "Birch Fence", "Birch Fence Gate", "mcl_fences_fence_birch.png", "mcl_fences_fence_gate_birch.png", "mcl_core:birchwood"},
256 {"jungle", "Jungle Fence", "Jungle Fence Gate", "mcl_fences_fence_jungle.png", "mcl_fences_fence_gate_jungle.png", "mcl_core:junglewood"},
257 {"dark_oak", "Dark Oak Fence", "Dark Oak Fence Gate", "mcl_fences_fence_big_oak.png", "mcl_fences_fence_gate_big_oak.png", "mcl_core:darkwood"},
258 {"acacia", "Acacia Fence", "Acacia Fence Gate", "mcl_fences_fence_acacia.png", "mcl_fences_fence_gate_acacia.png", "mcl_core:acaciawood"},
261 for w=1, #woods do
262 local wood = woods[w]
263 local id, id_gate
264 if wood[1] == "" then
265 id = "fence"
266 id_gate = "fence_gate"
267 else
268 id = wood[1].."_fence"
269 id_gate = wood[1].."_fence_gate"
271 mcl_fences.register_fence_and_fence_gate(id, wood[2], wood[3], wood[4], wood_groups, 2, 15, wood_connect, wood_sounds)
273 minetest.register_craft({
274 output = 'mcl_fences:'..id..' 3',
275 recipe = {
276 {wood[6], 'mcl_core:stick', wood[6]},
277 {wood[6], 'mcl_core:stick', wood[6]},
280 minetest.register_craft({
281 output = 'mcl_fences:'..id_gate,
282 recipe = {
283 {'mcl_core:stick', wood[6], 'mcl_core:stick'},
284 {'mcl_core:stick', wood[6], 'mcl_core:stick'},
290 -- Nether Brick Fence (without fence gate!)
291 mcl_fences.register_fence("nether_brick_fence", "Nether Brick Fence", "mcl_fences_fence_nether_brick.png", {pickaxey=1, deco_block=1, fence_nether_brick=1}, 2, 30, {"group:fence_nether_brick"}, mcl_sounds.node_sound_stone_defaults())
293 minetest.register_craft({
294 output = 'mcl_fences:nether_brick_fence 6',
295 recipe = {
296 {"mcl_nether:nether_brick", "mcl_nether:nether_brick", "mcl_nether:nether_brick"},
297 {"mcl_nether:nether_brick", "mcl_nether:nether_brick", "mcl_nether:nether_brick"},
301 minetest.register_craft({
302 type = "fuel",
303 recipe = "group:fence_wood",
304 burntime = 15,
307 local time_to_load= os.clock() - init
308 print(string.format("[MOD] "..minetest.get_current_modname().." loaded in %.4f s", time_to_load))