Skip to content

Commit f92d49f

Browse files
committedJun 7, 2015
Default/functions: Fix cactus growing by rotation again. Cleanup code
1 parent 64fa8e6 commit f92d49f

File tree

1 file changed

+55
-52
lines changed

1 file changed

+55
-52
lines changed
 

‎mods/default/functions.lua

+55-52
Original file line numberDiff line numberDiff line change
@@ -7,78 +7,78 @@
77
function default.node_sound_defaults(table)
88
table = table or {}
99
table.footstep = table.footstep or
10-
{name="", gain=1.0}
10+
{name = "", gain = 1.0}
1111
table.dug = table.dug or
12-
{name="default_dug_node", gain=0.25}
12+
{name = "default_dug_node", gain = 0.25}
1313
table.place = table.place or
14-
{name="default_place_node_hard", gain=1.0}
14+
{name = "default_place_node_hard", gain = 1.0}
1515
return table
1616
end
1717

1818
function default.node_sound_stone_defaults(table)
1919
table = table or {}
2020
table.footstep = table.footstep or
21-
{name="default_hard_footstep", gain=0.5}
21+
{name = "default_hard_footstep", gain = 0.5}
2222
table.dug = table.dug or
23-
{name="default_hard_footstep", gain=1.0}
23+
{name = "default_hard_footstep", gain = 1.0}
2424
default.node_sound_defaults(table)
2525
return table
2626
end
2727

2828
function default.node_sound_dirt_defaults(table)
2929
table = table or {}
3030
table.footstep = table.footstep or
31-
{name="default_dirt_footstep", gain=1.0}
31+
{name = "default_dirt_footstep", gain = 1.0}
3232
table.dug = table.dug or
33-
{name="default_dirt_footstep", gain=1.5}
33+
{name = "default_dirt_footstep", gain = 1.5}
3434
table.place = table.place or
35-
{name="default_place_node", gain=1.0}
35+
{name = "default_place_node", gain = 1.0}
3636
default.node_sound_defaults(table)
3737
return table
3838
end
3939

4040
function default.node_sound_sand_defaults(table)
4141
table = table or {}
4242
table.footstep = table.footstep or
43-
{name="default_sand_footstep", gain=0.2}
43+
{name = "default_sand_footstep", gain = 0.2}
4444
table.dug = table.dug or
45-
{name="default_sand_footstep", gain=0.4}
45+
{name = "default_sand_footstep", gain = 0.4}
4646
table.place = table.place or
47-
{name="default_place_node", gain=1.0}
47+
{name = "default_place_node", gain = 1.0}
4848
default.node_sound_defaults(table)
4949
return table
5050
end
5151

5252
function default.node_sound_wood_defaults(table)
5353
table = table or {}
5454
table.footstep = table.footstep or
55-
{name="default_wood_footstep", gain=0.5}
55+
{name = "default_wood_footstep", gain = 0.5}
5656
table.dug = table.dug or
57-
{name="default_wood_footstep", gain=1.0}
57+
{name = "default_wood_footstep", gain = 1.0}
5858
default.node_sound_defaults(table)
5959
return table
6060
end
6161

6262
function default.node_sound_leaves_defaults(table)
6363
table = table or {}
6464
table.footstep = table.footstep or
65-
{name="default_grass_footstep", gain=0.35}
65+
{name = "default_grass_footstep", gain = 0.35}
6666
table.dug = table.dug or
67-
{name="default_grass_footstep", gain=0.7}
67+
{name = "default_grass_footstep", gain = 0.7}
6868
table.dig = table.dig or
69-
{name="default_dig_crumbly", gain=0.4}
69+
{name = "default_dig_crumbly", gain = 0.4}
7070
table.place = table.place or
71-
{name="default_place_node", gain=1.0}
71+
{name = "default_place_node", gain = 1.0}
7272
default.node_sound_defaults(table)
7373
return table
7474
end
7575

7676
function default.node_sound_glass_defaults(table)
7777
table = table or {}
7878
table.footstep = table.footstep or
79-
{name="default_glass_footstep", gain=0.5}
79+
{name = "default_glass_footstep", gain = 0.5}
8080
table.dug = table.dug or
81-
{name="default_break_glass", gain=1.0}
81+
{name = "default_break_glass", gain = 1.0}
8282
default.node_sound_defaults(table)
8383
return table
8484
end
@@ -89,13 +89,13 @@ end
8989
--
9090

9191
default.cool_lava_source = function(pos)
92-
minetest.set_node(pos, {name="default:obsidian"})
93-
minetest.sound_play("default_cool_lava", {pos = pos, gain = 0.25})
92+
minetest.set_node(pos, {name = "default:obsidian"})
93+
minetest.sound_play("default_cool_lava", {pos = pos, gain = 0.25})
9494
end
9595

9696
default.cool_lava_flowing = function(pos)
97-
minetest.set_node(pos, {name="default:stone"})
98-
minetest.sound_play("default_cool_lava", {pos = pos, gain = 0.25})
97+
minetest.set_node(pos, {name = "default:stone"})
98+
minetest.sound_play("default_cool_lava", {pos = pos, gain = 0.25})
9999
end
100100

101101
minetest.register_abm({
@@ -123,55 +123,53 @@ minetest.register_abm({
123123
-- Papyrus and cactus growing
124124
--
125125

126+
-- wrapping the functions in abm action is necessary to make overriding them possible
127+
126128
function default.grow_cactus(pos, node)
127129
if node.param2 >= 4 then
128130
return
129131
end
130-
pos.y = pos.y-1
132+
pos.y = pos.y - 1
131133
if minetest.get_item_group(minetest.get_node(pos).name, "sand") == 0 then
132134
return
133135
end
134-
pos.y = pos.y+1
136+
pos.y = pos.y + 1
135137
local height = 0
136-
while node.name == "default:cactus" and height < 4 and node.param2 == 0 do
137-
height = height+1
138-
pos.y = pos.y+1
138+
while node.name == "default:cactus" and height < 4 do
139+
height = height + 1
140+
pos.y = pos.y + 1
139141
node = minetest.get_node(pos)
140142
end
141-
if height == 4
142-
or node.name ~= "air" then
143+
if height == 4 or node.name ~= "air" then
143144
return
144145
end
145-
minetest.set_node(pos, {name="default:cactus"})
146+
minetest.set_node(pos, {name = "default:cactus"})
146147
return true
147148
end
148149

149150
function default.grow_papyrus(pos, node)
150-
pos.y = pos.y-1
151+
pos.y = pos.y - 1
151152
local name = minetest.get_node(pos).name
152-
if name ~= "default:dirt_with_grass"
153-
and name ~= "default:dirt" then
153+
if name ~= "default:dirt_with_grass" and name ~= "default:dirt" then
154154
return
155155
end
156156
if not minetest.find_node_near(pos, 3, {"group:water"}) then
157157
return
158158
end
159-
pos.y = pos.y+1
159+
pos.y = pos.y + 1
160160
local height = 0
161161
while node.name == "default:papyrus" and height < 4 do
162-
height = height+1
163-
pos.y = pos.y+1
162+
height = height + 1
163+
pos.y = pos.y + 1
164164
node = minetest.get_node(pos)
165165
end
166-
if height == 4
167-
or node.name ~= "air" then
166+
if height == 4 or node.name ~= "air" then
168167
return
169168
end
170-
minetest.set_node(pos, {name="default:papyrus"})
169+
minetest.set_node(pos, {name = "default:papyrus"})
171170
return true
172171
end
173172

174-
-- wrapping the functions in abm action is necessary to make overriding them possible
175173
minetest.register_abm({
176174
nodenames = {"default:cactus"},
177175
neighbors = {"group:sand"},
@@ -255,8 +253,10 @@ minetest.register_abm({
255253
if trunkp then
256254
local n = minetest.get_node(trunkp)
257255
local reg = minetest.registered_nodes[n.name]
258-
-- Assume ignore is a trunk, to make the thing work at the border of the active area
259-
if n.name == "ignore" or (reg and reg.groups.tree and reg.groups.tree ~= 0) then
256+
-- Assume ignore is a trunk, to make the thing
257+
-- work at the border of the active area
258+
if n.name == "ignore" or (reg and reg.groups.tree and
259+
reg.groups.tree ~= 0) then
260260
--print("cached trunk still exists")
261261
return
262262
end
@@ -270,7 +270,8 @@ minetest.register_abm({
270270
end
271271
default.leafdecay_trunk_find_allow_accumulator =
272272
default.leafdecay_trunk_find_allow_accumulator - 1
273-
-- Assume ignore is a trunk, to make the thing work at the border of the active area
273+
-- Assume ignore is a trunk, to make the thing
274+
-- work at the border of the active area
274275
local p1 = minetest.find_node_near(p0, d, {"ignore", "group:tree"})
275276
if p1 then
276277
do_preserve = true
@@ -301,6 +302,7 @@ minetest.register_abm({
301302
end
302303
})
303304

305+
304306
--
305307
-- Grass growing
306308
--
@@ -310,12 +312,12 @@ minetest.register_abm({
310312
interval = 2,
311313
chance = 200,
312314
action = function(pos, node)
313-
local above = {x=pos.x, y=pos.y+1, z=pos.z}
315+
local above = {x = pos.x, y = pos.y + 1, z = pos.z}
314316
local name = minetest.get_node(above).name
315317
local nodedef = minetest.registered_nodes[name]
316-
if nodedef and (nodedef.sunlight_propagates or nodedef.paramtype == "light")
317-
and nodedef.liquidtype == "none"
318-
and (minetest.get_node_light(above) or 0) >= 13 then
318+
if nodedef and (nodedef.sunlight_propagates or nodedef.paramtype == "light") and
319+
nodedef.liquidtype == "none" and
320+
(minetest.get_node_light(above) or 0) >= 13 then
319321
if name == "default:snow" or name == "default:snowblock" then
320322
minetest.set_node(pos, {name = "default:dirt_with_snow"})
321323
else
@@ -330,13 +332,14 @@ minetest.register_abm({
330332
interval = 2,
331333
chance = 20,
332334
action = function(pos, node)
333-
local above = {x=pos.x, y=pos.y+1, z=pos.z}
335+
local above = {x = pos.x, y = pos.y + 1, z = pos.z}
334336
local name = minetest.get_node(above).name
335337
local nodedef = minetest.registered_nodes[name]
336-
if name ~= "ignore" and nodedef
337-
and not ((nodedef.sunlight_propagates or nodedef.paramtype == "light")
338-
and nodedef.liquidtype == "none") then
338+
if name ~= "ignore" and nodedef and not ((nodedef.sunlight_propagates or
339+
nodedef.paramtype == "light") and
340+
nodedef.liquidtype == "none") then
339341
minetest.set_node(pos, {name = "default:dirt"})
340342
end
341343
end
342344
})
345+

0 commit comments

Comments
 (0)
Please sign in to comment.