Jordan Snelling
2013-06-27 c687e8cb7b9e624474353b0cc10acc5db14192f8
commit | author | age
0ca19d 1 --Minetest 0.4.6 mod: concrete 
R 2 --(c) 2013 by RealBadAngel <mk@realbadangel.pl>
3
4 minetest.register_craft({
5     output = ':technic:rebar 6',
6     recipe = {
7         {'','', 'default:steel_ingot'},
8         {'','default:steel_ingot',''},
9         {'default:steel_ingot', '', ''},
10     }
11 })
12
13 minetest.register_craft({
14     output = ':technic:concrete 5',
15     recipe = {
16         {'default:stone','technic:rebar','default:stone'},
17         {'technic:rebar','default:stone','technic:rebar'},
18         {'default:stone','technic:rebar','default:stone'},
19     }
20 })
21
22 minetest.register_craft({
23     output = ':technic:concrete_post_platform 6',
24     recipe = {
25         {'technic:concrete','technic:concrete_post','technic:concrete'},
26     }
27 })
28
29 minetest.register_craft({
30     output = ':technic:concrete_post 12',
31     recipe = {
32         {'default:stone','technic:rebar','default:stone'},
33         {'default:stone','technic:rebar','default:stone'},
34         {'default:stone','technic:rebar','default:stone'},
35 }
36 })
37
38 platform_box = {-0.5 , 0.3 , -0.5 , 0.5 ,  0.5 , 0.5  }
39 post_str_y={ -0.15 , -0.5 , -0.15 , 0.15 ,  0.5 , 0.15  }
40 post_str_x1={ 0 , -0.3 , -0.1, 0.5 ,  0.3 , 0.1 }  -- x+
41 post_str_z1={ -0.1 , -0.3 , 0, 0.1 ,  0.3 , 0.5 } -- z+
42 post_str_x2={ 0 , -0.3 , -0.1, -0.5 ,  0.3 , 0.1 } -- x-
43 post_str_z2={ -0.1 , -0.3 , 0, 0.1 ,  0.3 , -0.5 } -- z-
44
45 minetest.register_craftitem(":technic:rebar", {
46     description = "Rebar",
47     inventory_image = "technic_rebar.png",
48     stack_max = 99,
49 })
50
51 minetest.register_craftitem(":technic:concrete", {
52     description = "Concrete Block",
53     inventory_image = "technic_concrete_block.png",
54     stack_max = 99,
55 })
56
57 minetest.register_craftitem(":technic:concrete_post", {
58     description = "Concrete Post",
59     stack_max = 99,
60 })
61
62 minetest.register_craftitem(":technic:concrete_post_platform", {
63     description = "Concrete Post Platform",
64     stack_max = 99,
65 })
66
67 minetest.register_node(":technic:concrete", {
68     description = "Concrete Block",
69     tile_images = {"technic_concrete_block.png",},
70     is_ground_content = true,
71     groups={cracky=1,level=2},
72     sounds = default.node_sound_stone_defaults(),
73     paramtype = "light",
74     light_source = 0,
75     sunlight_propagates = true,
76     on_construct = function(pos)
77         meta=minetest.env:get_meta(pos)
78         meta:set_float("postlike",1)
79         check_post_connections (pos,1)
80     end,
81     after_dig_node = function (pos, oldnode, oldmetadata, digger)
82         check_post_connections  (pos,0)
83     end,
84 })
85
86 minetest.register_node(":technic:concrete_post_platform", {
87     description = "Concrete Post Platform",
88     tile_images = {"technic_concrete_block.png",},
89     is_ground_content = true,
90     groups={cracky=1,level=2},
91     sounds = default.node_sound_stone_defaults(),
92     paramtype = "light",
93     light_source = 0,
94     sunlight_propagates = true,
95     drawtype = "nodebox", 
96     selection_box = {
97         type = "fixed",
98         fixed = {platform_box}
99         },
100     node_box = {
101         type = "fixed",
102         fixed = {platform_box}
103         },
104     on_place=function (itemstack, placer, pointed_thing)
105     local node=minetest.env:get_node(pointed_thing.under)
106     if minetest.get_item_group(node.name, "concrete_post")==0 then 
107         return minetest.item_place_node(itemstack, placer, pointed_thing) 
108     end
109     local meta=minetest.env:get_meta(pointed_thing.under)
110     y1=meta:get_float("y1")
111     platform=meta:get_float("platform")
112     if y1==1 or platform==1 then 
113         return minetest.item_place_node(itemstack, placer, pointed_thing) 
114     end
115     y2=meta:get_float("y2")
116     x1=meta:get_float("x1")
117     x2=meta:get_float("x2")
118     z1=meta:get_float("z1")
119     z2=meta:get_float("z2")
120     rule=make_post_rule_number(x1,x2,y1,y2,z1,z2,1)
121     meta:set_float("platform",1)
122     hacky_swap_posts(pointed_thing.under,"technic:concrete_post"..rule)
123     itemstack:take_item()
124     placer:set_wielded_item(itemstack)
125     return itemstack
126     end,
127 })
128
129
130 minetest.register_node(":technic:concrete_post", {
131     description = "Concrete Post",
132     tiles = {"technic_concrete_block.png"},
133     groups={cracky=1,level=2,concrete_post=1},
134     sounds = default.node_sound_stone_defaults(),
135     paramtype = "light",
136     light_source = 0,
137     sunlight_propagates = true,
138     drawtype = "nodebox", 
139     selection_box = {
140         type = "fixed",
141         fixed = { -0.15 , -0.5 , -0.15 , 0.15 ,  0.5 , 0.15 }},
142     node_box = {
143         type = "fixed",
144         fixed = {-0.15 , -0.5 , -0.15 , 0.15 ,  0.5 , 0.15  }},
145     on_construct = function(pos)
146     meta=minetest.env:get_meta(pos)
147     meta:set_int("postlike",1)
148     meta:set_int("platform",0)
149     meta:set_int("x1",0)
150     meta:set_int("x2",0)
151     meta:set_int("y1",0)
152     meta:set_int("y2",0)
153     meta:set_int("z1",0)
154     meta:set_int("z2",0)
155     check_post_connections (pos,1)
156     end,
157
158     after_dig_node = function (pos, oldnode, oldmetadata, digger)
159     check_post_connections  (pos,0)
160     end,
161
162 })
163
164 local x1,x2,y1,z1,z2
165 local count=0
166
167 for x1 = 0, 1, 1 do    --x-
168 for x2 = 0, 1, 1 do    --x+
169 for z1 = 0, 1, 1 do    --z-
170 for z2 = 0, 1, 1 do    --z+
171      
172 temp_x1={} temp_x2={} temp_z1={} temp_z2={}
173
174 if x1==1 then     temp_x1=post_str_x1  end 
175 if x2==1 then     temp_x2=post_str_x2  end 
176 if z1==1 then     temp_z1=post_str_z1  end 
177 if z2==1 then     temp_z2=post_str_z2  end 
178
179
180 minetest.register_node(":technic:concrete_post"..count, {
181     description = "Concrete Post",
182     tiles = {"technic_concrete_block.png"},
183     groups={cracky=1,level=2,not_in_creative_inventory=1,concrete_post=1},
184     sounds = default.node_sound_stone_defaults(),
185     drop = "technic:concrete_post",
186     paramtype = "light",
187     light_source = 0,
188     sunlight_propagates = true,
189     drawtype = "nodebox", 
190     selection_box = {
191         type = "fixed",
192         fixed = {
193         temp_x1,temp_x2,post_str_y,temp_z1,temp_z2,
194         }},
195
196     node_box = {
197         type = "fixed",
198         fixed = {
199         temp_x1,temp_x2,post_str_y,temp_z1,temp_z2,
200         }},
201
202     after_dig_node = function (pos, oldnode, oldmetadata, digger)
203     check_post_connections  (pos,0)
204     end,
205
206 })
207
208 minetest.register_node(":technic:concrete_post"..count+16, {
209     description = "Concrete Post",
210     tiles = {"technic_concrete_block.png"},
211     groups={cracky=1,level=2,not_in_creative_inventory=1,concrete_post=1},
212     sounds = default.node_sound_stone_defaults(),
213     drop = "technic:concrete_post_platform",
214     paramtype = "light",
215     light_source = 0,
216     sunlight_propagates = true,
217     drawtype = "nodebox", 
218     selection_box = {
219         type = "fixed",
220         fixed = {
221         platform_box,temp_x1,temp_x2,post_str_y,temp_z1,temp_z2,
222         }},
223
224     node_box = {
225         type = "fixed",
226         fixed = {
227         platform_box,temp_x1,temp_x2,post_str_y,temp_z1,temp_z2,
228         }},
229
230     after_dig_node = function (pos, oldnode, oldmetadata, digger)
231         dig_post_with_platform (pos,oldnode,oldmetadata)
232     end,
233 })
234
235 count=count+1 end end end end
236
237 minetest.register_node(":technic:concrete_post32", {
238     description = "Concrete Post",
239     tiles = {"technic_concrete_block.png"},
240     groups={cracky=1,level=2,not_in_creative_inventory=1,concrete_post=1},
241     sounds = default.node_sound_stone_defaults(),
242     drop = "technic:concrete_post",
243     paramtype = "light",
244     light_source = 0,
245     sunlight_propagates = true,
246     drawtype = "nodebox", 
247     selection_box = {
248         type = "fixed",
249         fixed = {-0.5,-0.3,-0.1,0.5,0.3,0.1},
250         },
251     node_box = {
252         type = "fixed",
253         fixed = {
254         post_str_x1,post_str_x2,
255         }},
256
257     after_dig_node = function (pos, oldnode, oldmetadata, digger)
258         check_post_connections  (pos,0)
259     end,
260 })
261 minetest.register_node(":technic:concrete_post33", {
262     description = "Concrete Post",
263     tiles = {"technic_concrete_block.png"},
264     groups={cracky=1,level=2,not_in_creative_inventory=1,concrete_post=1},
265     sounds = default.node_sound_stone_defaults(),
266     drop = "technic:concrete_post",
267     paramtype = "light",
268     light_source = 0,
269     sunlight_propagates = true,
270     drawtype = "nodebox", 
271     selection_box = {
272         type = "fixed",
273         fixed = {
274         post_str_z1,post_str_z2,
275         }},
276     node_box = {
277         type = "fixed",
278         fixed = {
279         post_str_z1,post_str_z2,
280         }},
281
282     after_dig_node = function (pos, oldnode, oldmetadata, digger)
283     check_post_connections  (pos,0)
284     end,
285 })
286
287 minetest.register_node(":technic:concrete_post34", {
288     description = "Concrete Post",
289     tiles = {"technic_concrete_block.png"},
290     groups={cracky=1,level=2,not_in_creative_inventory=1,concrete_post=1},
291     sounds = default.node_sound_stone_defaults(),
292     drop = "technic:concrete_post_platform",
293     paramtype = "light",
294     light_source = 0,
295     sunlight_propagates = true,
296     drawtype = "nodebox", 
297     selection_box = {
298         type = "fixed",
299         fixed = {
300         platform_box,post_str_x1,post_str_x2,
301         }},
302     node_box = {
303         type = "fixed",
304         fixed = {
305         platform_box,post_str_x1,post_str_x2,
306         }},
307
308     after_dig_node = function (pos, oldnode, oldmetadata, digger)
309         dig_post_with_platform (pos,oldnode,oldmetadata)
310     end,
311 })
312 minetest.register_node(":technic:concrete_post35", {
313     description = "Concrete Post",
314     tiles = {"technic_concrete_block.png"},
315     groups={cracky=1,level=2,not_in_creative_inventory=1,concrete_post=1},
316     sounds = default.node_sound_stone_defaults(),
317     drop = "technic:concrete_post_platform",
318     paramtype = "light",
319     light_source = 0,
320     sunlight_propagates = true,
321     drawtype = "nodebox", 
322     selection_box = {
323         type = "fixed",
324         fixed = {
325         platform_box,post_str_z1,post_str_z2,
326         }},
327     node_box = {
328         type = "fixed",
329         fixed = {
330         platform_box,post_str_z1,post_str_z2,
331         }},
332     after_dig_node = function (pos, oldnode, oldmetadata, digger)
333         dig_post_with_platform (pos,oldnode,oldmetadata)
334     end,
335 })
336
337 dig_post_with_platform = function (pos,oldnode,oldmetadata)
338     x1=tonumber(oldmetadata.fields["x1"])
339     x2=tonumber(oldmetadata.fields["x2"])
340     y1=tonumber(oldmetadata.fields["y1"])
341     y2=tonumber(oldmetadata.fields["y2"])
342     z1=tonumber(oldmetadata.fields["z1"])
343     z2=tonumber(oldmetadata.fields["z2"])
344     print(dump(x1))
345     oldmetadata.fields["platform"]="0"
346     local rule=make_post_rule_number(x1,x2,y1,y2,z1,z2,0)
347     print(dump(rule))
348     oldnode.name="technic:concrete_post"..rule
349     minetest.env:set_node(pos,oldnode)
350     meta = minetest.env:get_meta(pos)
351     meta:from_table(oldmetadata)
352 end    
353
354 check_post_connections = function(pos,mode)
355         local pos1={}
356         pos1.x=pos.x
357         pos1.y=pos.y
358         pos1.z=pos.z
359         tempx1=0
360         tempx2=0
361         tempy1=0
362         tempy2=0
363         tempz1=0
364         tempz2=0
365         
366         pos1.x=pos1.x+1
367         if minetest.env:get_meta(pos1):get_int("postlike")==1 then
368         x2=mode
369         x1=minetest.env:get_meta(pos1):get_int("x1")
370         y1=minetest.env:get_meta(pos1):get_int("y1")
371         y2=minetest.env:get_meta(pos1):get_int("y2")
372         z1=minetest.env:get_meta(pos1):get_int("z1")
373         z2=minetest.env:get_meta(pos1):get_int("z2")
374         platform=minetest.env:get_meta(pos1):get_int("platform")
375         rule=make_post_rule_number(x1,x2,y1,y2,z1,z2,platform)
376         hacky_swap_posts(pos1,"technic:concrete_post"..rule)
377         meta=minetest.env:get_meta(pos1)
378         meta:set_int("x2",x2)
379         tempx1=mode
380         end
381
382         pos1.x=pos1.x-2
383         if minetest.env:get_meta(pos1):get_int("postlike")==1 then
384         x1=mode
385         x2=minetest.env:get_meta(pos1):get_int("x2")
386         y1=minetest.env:get_meta(pos1):get_int("y1")
387         y2=minetest.env:get_meta(pos1):get_int("y2")
388         z1=minetest.env:get_meta(pos1):get_int("z1")
389         z2=minetest.env:get_meta(pos1):get_int("z2")
390         platform=minetest.env:get_meta(pos1):get_int("platform")
391         rule=make_post_rule_number(x1,x2,y1,y2,z1,z2,platform)
392         hacky_swap_posts(pos1,"technic:concrete_post"..rule)
393         meta=minetest.env:get_meta(pos1)
394         meta:set_int("x1",x1)
395         tempx2=mode
396         end
397
398         pos1.x=pos1.x+1
399         
400         pos1.y=pos1.y+1
401         if minetest.env:get_meta(pos1):get_int("postlike")==1 then
402         y2=mode
403         x1=minetest.env:get_meta(pos1):get_int("x1")
404         x2=minetest.env:get_meta(pos1):get_int("x2")
405         y1=minetest.env:get_meta(pos1):get_int("y1")
406         z1=minetest.env:get_meta(pos1):get_int("z1")
407         z2=minetest.env:get_meta(pos1):get_int("z2")
408         platform=minetest.env:get_meta(pos1):get_int("platform")
409         rule=make_post_rule_number(x1,x2,y1,y2,z1,z2,platform)
410         hacky_swap_posts(pos1,"technic:concrete_post"..rule)
411         meta=minetest.env:get_meta(pos1)
412         meta:set_int("y2",y2)
413         tempy1=mode
414         end
415
416         pos1.y=pos1.y-2
417         if minetest.env:get_meta(pos1):get_int("postlike")==1 then
418         y1=mode
419         x1=minetest.env:get_meta(pos1):get_int("x1")
420         x2=minetest.env:get_meta(pos1):get_int("x2")
421         y2=minetest.env:get_meta(pos1):get_int("y2")
422         z1=minetest.env:get_meta(pos1):get_int("z1")
423         z2=minetest.env:get_meta(pos1):get_int("z2")
424         platform=minetest.env:get_meta(pos1):get_int("platform")
425         rule=make_post_rule_number(x1,x2,y1,y2,z1,z2,platform)
426         hacky_swap_posts(pos1,"technic:concrete_post"..rule)
427         meta=minetest.env:get_meta(pos1)
428         meta:set_int("y1",y1)
429         tempy2=mode
430         end
431         pos1.y=pos1.y+1
432
433         pos1.z=pos1.z+1
434         if minetest.env:get_meta(pos1):get_int("postlike")==1 then
435         z2=mode
436         x1=minetest.env:get_meta(pos1):get_int("x1")
437         x2=minetest.env:get_meta(pos1):get_int("x2")
438         y1=minetest.env:get_meta(pos1):get_int("y1")
439         y2=minetest.env:get_meta(pos1):get_int("y2")
440         z1=minetest.env:get_meta(pos1):get_int("z1")
441         platform=minetest.env:get_meta(pos1):get_int("platform")
442         rule=make_post_rule_number(x1,x2,y1,y2,z1,z2,platform)
443         hacky_swap_posts(pos1,"technic:concrete_post"..rule)
444         meta=minetest.env:get_meta(pos1)
445         meta:set_int("z2",z2)
446         tempz1=mode
447         end
448         pos1.z=pos1.z-2
449         
450         if minetest.env:get_meta(pos1):get_int("postlike")==1 then
451         z1=mode
452         x1=minetest.env:get_meta(pos1):get_int("x1")
453         x2=minetest.env:get_meta(pos1):get_int("x2")
454         y1=minetest.env:get_meta(pos1):get_int("y1")
455         y2=minetest.env:get_meta(pos1):get_int("y2")
456         z2=minetest.env:get_meta(pos1):get_int("z2")
457         platform=minetest.env:get_meta(pos1):get_int("platform")
458         rule=make_post_rule_number(x1,x2,y1,y2,z1,z2,platform)
459         hacky_swap_posts(pos1,"technic:concrete_post"..rule)
460         meta=minetest.env:get_meta(pos1)
461         meta:set_int("z1",z1)
462         tempz2=mode
463         end
464         pos1.z=pos1.z+1
465         if mode==1 then 
466             meta=minetest.env:get_meta(pos)
467             meta:set_int("x1",tempx1)
468             meta:set_int("x2",tempx2)
469             meta:set_int("y1",tempy1)
470             meta:set_int("y2",tempy2)
471             meta:set_int("z1",tempz1)
472             meta:set_int("z2",tempz2)
473             rule=make_post_rule_number(tempx1,tempx2,tempy1,tempy2,tempz1,tempz2,0)
474             hacky_swap_posts(pos,"technic:concrete_post"..rule)
475         end
476 end    
477
478 function make_post_rule_number (x1,x2,y1,y2,z1,z2,platform)
479 local tempy=y1+y2
480 local tempx=x1+x2
481 local tempz=z1+z2
482 if platform==0 then 
483     if tempy==0 and tempx==0 and tempz==0 then return 0 end
484     if x1==1 and x2==1 and tempz==0 and tempy==0 then return 32 end
485     if z1==1 and z2==1 and tempx==0 and tempy==0 then return 33 end
486     return z2+z1*2+x2*4+x1*8
487 else
488     if tempy==0 and tempx==0 and tempz==0 then return 16 end
489     if x1==1 and x2==1 and tempz==0 and tempy==0 then return 34 end
490     if z1==1 and z2==1 and tempx==0 and tempy==0 then return 35 end
491     return z2+z1*2+x2*4+x1*8+16
492 end
493 end
494
495 function hacky_swap_posts(pos,name)
496     local node = minetest.env:get_node(pos)
497         if node.name == "technic:concrete" then
498         return nil
499     end
500     local meta = minetest.env:get_meta(pos)
501     local meta0 = meta:to_table()
502     node.name = name
503     local meta0 = meta:to_table()
504     minetest.env:set_node(pos,node)
505     meta = minetest.env:get_meta(pos)
506     meta:from_table(meta0)
507     return 1
508 end