1 local init
= os
.clock()
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
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
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
27 cgroups
.deco_block
= 1
28 if connects_to
== nil then
31 connects_to
= table.copy(connects_to
)
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.",
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",
44 is_ground_content
= false,
47 sunlight_propagates
= true,
49 connect_sides
= { "front", "back", "left", "right" },
50 connects_to
= connects_to
,
54 connect_front
= {z1
,z12
},
55 connect_back
= {z2
,z22
,},
56 connect_left
= {x1
,x12
},
57 connect_right
= {x2
,x22
},
62 connect_front
= {cz1
},
63 connect_back
= {cz2
,},
65 connect_right
= {cx2
},
68 _mcl_blast_resistance
= blast_resistance
,
69 _mcl_hardness
= hardness
,
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
)
79 local function update_gate(pos
, node
)
80 minetest
.set_node(pos
, node
)
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"
88 if not sound_close
then
89 sound_close
= "doors_fencegate_close"
91 if not sound_gain_open
then
94 if not sound_gain_close
then
95 sound_gain_close
= 0.3
97 local function punch_gate(pos
, node
)
98 meta2
= minetest
.get_meta(pos
)
99 state2
= meta2
:get_int("state")
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
}
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
)
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
, {
130 paramtype2
= "facedir",
131 is_ground_content
= false,
132 sunlight_propagates
= true,
136 drawtype
= "nodebox",
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
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
)
159 mesecons
= {effector
= {
160 action_off
= (function(pos
, node
)
161 punch_gate(pos
, node
)
164 on_rotate
= on_rotate
,
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.",
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",
181 is_ground_content
= false,
183 paramtype2
= "facedir",
184 sunlight_propagates
= true,
186 groups
= cgroups_closed
,
187 drawtype
= "nodebox",
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
204 {-0.5, -3/16, -2/16, 0.5, 1, 2/16}, --gate
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)
218 mesecons
= {effector
= {
219 action_on
= (function(pos
, node
)
220 punch_gate(pos
, node
)
223 on_rotate
= on_rotate
,
224 on_rightclick
= function(pos
, node
, clicker
)
225 punch_gate(pos
, node
)
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()
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"},
262 local wood
= woods
[w
]
264 if wood
[1] == "" then
266 id_gate
= "fence_gate"
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',
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
,
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',
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({
303 recipe
= "group:fence_wood",
307 local time_to_load
= os
.clock() - init
308 print(string.format("[MOD] "..minetest
.get_current_modname().." loaded in %.4f s", time_to_load
))