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