ShadowNinja
2013-07-17 ee0765804c0a21deeb2f33c22ac1a36cb0db5f43
commit | author | age
f4302f 1 --Minetest 0.4.7 mod: concrete 
0ca19d 2 --(c) 2013 by RealBadAngel <mk@realbadangel.pl>
R 3
ee0765 4 local technic = technic or {}
S 5 technic.concrete_posts = {}
6
7 minetest.register_alias("technic:concrete_post",   "technic:concrete_post0")
8 minetest.register_alias("technic:concrete_post32", "technic:concrete_post12")
9 minetest.register_alias("technic:concrete_post33", "technic:concrete_post3")
10 minetest.register_alias("technic:concrete_post34", "technic:concrete_post28")
11 minetest.register_alias("technic:concrete_post35", "technic:concrete_post19")
12
0ca19d 13 minetest.register_craft({
f4302f 14     output = 'technic:rebar 6',
0ca19d 15     recipe = {
R 16         {'','', 'default:steel_ingot'},
17         {'','default:steel_ingot',''},
18         {'default:steel_ingot', '', ''},
19     }
20 })
21
22 minetest.register_craft({
f4302f 23     output = 'technic:concrete 5',
0ca19d 24     recipe = {
R 25         {'default:stone','technic:rebar','default:stone'},
26         {'technic:rebar','default:stone','technic:rebar'},
27         {'default:stone','technic:rebar','default:stone'},
28     }
29 })
30
31 minetest.register_craft({
f4302f 32     output = 'technic:concrete_post_platform 6',
0ca19d 33     recipe = {
ee0765 34         {'technic:concrete','technic:concrete_post0','technic:concrete'},
0ca19d 35     }
R 36 })
37
38 minetest.register_craft({
ee0765 39     output = 'technic:concrete_post0 12',
0ca19d 40     recipe = {
R 41         {'default:stone','technic:rebar','default:stone'},
42         {'default:stone','technic:rebar','default:stone'},
43         {'default:stone','technic:rebar','default:stone'},
44 }
45 })
46
6055ed 47 minetest.register_craft({
R 48     output = 'technic:blast_resistant_concrete 5',
49     recipe = {
50         {'technic:concrete','technic:composite_plate','technic:concrete'},
51         {'technic:composite_plate','technic:concrete','technic:composite_plate'},
52         {'technic:concrete','technic:composite_plate','technic:concrete'},
53     }
54 })
55
ee0765 56 local box_platform = {-0.5,  0.3,  -0.5,  0.5,  0.5, 0.5}
S 57 local box_center   = {-0.15, -0.5, -0.15, 0.15, 0.5, 0.15}
58 local box_x1       = {0,     -0.3, -0.1,  0.5,  0.3, 0.1}
59 local box_z1       = {-0.1,  -0.3, 0,     0.1,  0.3, 0.5}
60 local box_x2       = {0,     -0.3, -0.1,  -0.5, 0.3, 0.1}
61 local box_z2       = {-0.1,  -0.3, 0,     0.1,  0.3, -0.5}
0ca19d 62
R 63 minetest.register_craftitem(":technic:rebar", {
64     description = "Rebar",
65     inventory_image = "technic_rebar.png",
66 })
67
68 minetest.register_node(":technic:concrete", {
69     description = "Concrete Block",
70     tile_images = {"technic_concrete_block.png",},
ee0765 71     groups = {cracky=1, level=2, concrete=1},
6055ed 72     sounds = default.node_sound_stone_defaults(),
ee0765 73     after_place_node = function(pos, placer, itemstack)
S 74         technic.update_posts(pos, false)
6055ed 75     end,
R 76     after_dig_node = function (pos, oldnode, oldmetadata, digger)
ee0765 77         technic.update_posts(pos, false)
6055ed 78     end,
R 79 })
80
81 minetest.register_node(":technic:blast_resistant_concrete", {
82     description = "Blast-resistant Concrete Block",
83     tile_images = {"technic_blast_resistant_concrete_block.png",},
ee0765 84     groups={cracky=1, level=3, concrete=1},
0ca19d 85     sounds = default.node_sound_stone_defaults(),
ee0765 86     after_place_node = function(pos, player, itemstack)
S 87         technic.update_posts(pos, false)
0ca19d 88     end,
R 89     after_dig_node = function (pos, oldnode, oldmetadata, digger)
ee0765 90         technic.update_posts(pos, false)
0ca19d 91     end,
R 92 })
93
94 minetest.register_node(":technic:concrete_post_platform", {
95     description = "Concrete Post Platform",
96     tile_images = {"technic_concrete_block.png",},
ee0765 97     groups={cracky=1, level=2},
0ca19d 98     sounds = default.node_sound_stone_defaults(),
R 99     paramtype = "light",
100     drawtype = "nodebox", 
101     node_box = {
102         type = "fixed",
ee0765 103         fixed = {box_platform}
S 104     },
105     on_place = function (itemstack, placer, pointed_thing)
106         local node = minetest.get_node(pointed_thing.under)
107         if not technic.concrete_posts[node.name] then 
108             return minetest.item_place_node(itemstack, placer, pointed_thing) 
109         end
110         local links = technic.concrete_posts[node.name]
111         if links[5] ~= 0 then -- The post already has a platform
112             return minetest.item_place_node(itemstack, placer, pointed_thing) 
113         end
114         local id = technic.get_post_id({links[1], links[2], links[3], links[4], 1})
115         minetest.set_node(pointed_thing.under, {name="technic:concrete_post"..id})
116         itemstack:take_item()
117         placer:set_wielded_item(itemstack)
118         return itemstack
119     end,
120 })
121
122 local function gen_post_nodebox(x1, x2, z1, z2, platform)
123     local box = {box_center}
124     if x1 ~= 0 then
125         table.insert(box, box_x1)
0ca19d 126     end
ee0765 127     if x2 ~= 0 then
S 128         table.insert(box, box_x2)
0ca19d 129     end
ee0765 130     if z1 ~= 0 then
S 131         table.insert(box, box_z1)
132     end
133     if z2 ~= 0 then
134         table.insert(box, box_z2)
135     end
136     if platform ~= 0 then
137         table.insert(box, box_platform)
138     end
139     return box
140 end
0ca19d 141
ee0765 142 local function dig_post_with_platform(pos, oldnode, oldmetadata)
S 143     oldnode.name = "technic:concrete_post0"
144     minetest.set_node(pos, oldnode)
145     technic.update_posts(pos, true)
146 end
0ca19d 147
ee0765 148 function technic.posts_should_connect(pos)
S 149     local node = minetest.get_node(pos)
150     if technic.concrete_posts[node.name] then
151         return "post"
152     elseif minetest.get_item_group(node.name, "concrete") ~= 0 then
153         return "block"
f4302f 154     end
0ca19d 155 end
R 156
ee0765 157 function technic.get_post_id(links)
S 158     return (links[4] * 1) + (links[3] * 2)
159         + (links[2] * 4) + (links[1] * 8)
160         + (links[5] * 16)
0ca19d 161 end
ee0765 162
S 163 function technic.update_posts(pos, set, secondrun)
164     local node = minetest.get_node(pos)
165     local link_positions = {
166         {x=pos.x+1, y=pos.y,   z=pos.z},
167         {x=pos.x-1, y=pos.y,   z=pos.z},
168         {x=pos.x,   y=pos.y,   z=pos.z+1},
169         {x=pos.x,   y=pos.y,   z=pos.z-1},
170     }
171
172     local links = {0, 0, 0, 0, 0}
173
174     for i, link_pos in pairs(link_positions) do
175         local connecttype = technic.posts_should_connect(link_pos)
176         if connecttype then
177             links[i] = 1
178             -- Have posts next to us update theirselves,
179             -- but only once. (We don't want to start an
180             -- infinite loop of updates)
181             if not secondrun and connecttype == "post" then
182                 technic.update_posts(link_pos, true, true)
183             end
184         end
185     end
186     -- We don't want to set ourselves if we have been removed or we are
187     -- updating a concrete node
188     if set then
189         -- Preserve platform
190         local oldlinks = technic.concrete_posts[node.name]
191         if oldlinks then
192             links[5] = oldlinks[5]
193         end
194         minetest.set_node(pos, {name="technic:concrete_post"
195                 ..technic.get_post_id(links)})
196     end
197 end
198
199 for x1 = 0, 1 do
200 for x2 = 0, 1 do
201 for z1 = 0, 1 do
202 for z2 = 0, 1 do
203 for platform = 0, 1 do
204     local links = {x1, x2, z1, z2, platform}
205     local id = technic.get_post_id(links)
206     technic.concrete_posts["technic:concrete_post"..id] = links
207
208     local groups = {cracky=1, level=2, concrete_post=1}
209     if id ~= 0 then
210         groups.not_in_creative_inventory = 1
211     end
212     
213     local drop = "technic:concrete_post0"
214     local after_dig_node = function(pos, oldnode, oldmetadata, digger)
215         technic.update_posts(pos, false)
216     end
217     if platform ~= 0 then
218         drop = "technic:concrete_post_platform"
219         after_dig_node = function(pos, oldnode, oldmetadata, digger)
220             dig_post_with_platform(pos, oldnode, oldmetadata)
221         end
222     end
223
224     minetest.register_node(":technic:concrete_post"..id, {
225         description = "Concrete Post",
226         tiles = {"technic_concrete_block.png"},
227         groups = groups,
228         sounds = default.node_sound_stone_defaults(),
229         drop = drop,
230         paramtype = "light",
231         sunlight_propagates = true,
232         drawtype = "nodebox", 
233         node_box = {
234             type = "fixed",
235             fixed = gen_post_nodebox(x1, x2, z1, z2, platform),
236         },
237         after_place_node = function(pos, placer, itemstack)
238             technic.update_posts(pos, true)
239         end,
240         after_dig_node = after_dig_node,
241     })
242 end
243 end
244 end
245 end
246 end
247