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