Tweak lily/seaweed selboxes
[minetest_hades/hades_revisited.git] / mods / plantlife / flowers_plus / init.lua
blob01f723d225c02c1cf1f5ee0ba69a2861fe4790de
1 local S = minetest.get_translator("flowers_plus")
3 -- This file supplies seaweed and waterlilies
5 flowers_plus = {}
8 local SPAWN_DELAY = 1000
9 local SPAWN_CHANCE = 200
10 local flowers_seed_diff = 329
11 local lilies_max_count = 12
12 local lilies_rarity = 33
13 local seaweed_max_count = 20
14 local seaweed_rarity = 33
15 -- globals
16 local lilypads_max_count = {}
17 local lilypads_rarity = {}
18 -- register the various rotations of waterlilies
21 local lilies_list = {
22 { nil , nil , 1 },
23 { "225", "22.5" , 2 },
24 { "45" , "45" , 3 },
25 { "675", "67.5" , 4 },
26 { "s1" , "small_1" , 5 },
27 { "s2" , "small_2" , 6 },
28 { "s3" , "small_3" , 7 },
29 { "s4" , "small_4" , 8 },
33 for i in ipairs(lilies_list) do
34 local deg1 = ""
35 local deg2 = ""
36 local lily_groups = {snappy = 3,flammable=2,waterlily=1}
39 if lilies_list[i][1] ~= nil then
40 deg1 = "_"..lilies_list[i][1]
41 deg2 = "_"..lilies_list[i][2]
42 lily_groups = { snappy = 3,flammable=2,waterlily=1, not_in_creative_inventory=1 }
43 end
46 minetest.register_node(":flowers:waterlily"..deg1, {
47 description = S("Waterlily"),
48 drawtype = "nodebox",
49 tiles = {
50 "flowers_waterlily"..deg2..".png",
51 "flowers_waterlily"..deg2..".png^[transformFY",
52 "blank.png",
54 inventory_image = "flowers_waterlily.png",
55 wield_image = "flowers_waterlily.png",
56 sunlight_propagates = true,
57 paramtype = "light",
58 paramtype2 = "facedir",
59 walkable = false,
60 groups = lily_groups,
61 sounds = hades_sounds.node_sound_leaves_defaults(),
62 selection_box = {
63 type = "fixed",
64 fixed = { -0.5, -0.5, -0.5, 0.5, -7/16, 0.5 },
66 node_box = {
67 type = "fixed",
68 fixed = { -0.5, -0.5, -0.5, 0.5, -0.49, 0.5 },
70 buildable_to = true,
73 liquids_pointable = true,
74 drop = "flowers:waterlily",
75 on_place = function(itemstack, placer, pointed_thing)
76 local keys=placer:get_player_control()
77 local pt = pointed_thing
80 local place_pos = nil
81 local top_pos = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z}
82 local under_node = minetest.get_node(pt.under)
83 local above_node = minetest.get_node(pt.above)
84 local top_node = minetest.get_node(top_pos)
87 if plantslib:get_nodedef_field(under_node.name, "buildable_to") then
88 if under_node.name ~= "hades_core:water_source" then
89 place_pos = pt.under
90 elseif top_node.name ~= "hades_core:water_source"
91 and plantslib:get_nodedef_field(top_node.name, "buildable_to") then
92 place_pos = top_pos
93 else
94 return itemstack
95 end
96 elseif plantslib:get_nodedef_field(above_node.name, "buildable_to") then
97 place_pos = pt.above
98 end
100 if not place_pos then
101 return itemstack
104 if not plantslib:node_is_owned(place_pos, placer) then
106 local nodename = "hades_core:cobble" -- if this block appears, something went....wrong :-)
108 if not keys["sneak"] then
109 local node = minetest.get_node(pt.under)
110 local waterlily = math.random(1,8)
111 if waterlily == 1 then
112 nodename = "flowers:waterlily"
113 elseif waterlily == 2 then
114 nodename = "flowers:waterlily_225"
115 elseif waterlily == 3 then
116 nodename = "flowers:waterlily_45"
117 elseif waterlily == 4 then
118 nodename = "flowers:waterlily_675"
119 elseif waterlily == 5 then
120 nodename = "flowers:waterlily_s1"
121 elseif waterlily == 6 then
122 nodename = "flowers:waterlily_s2"
123 elseif waterlily == 7 then
124 nodename = "flowers:waterlily_s3"
125 elseif waterlily == 8 then
126 nodename = "flowers:waterlily_s4"
128 minetest.add_node(place_pos, {name = nodename, param2 = math.random(0,3) })
129 else
130 local fdir = minetest.dir_to_facedir(placer:get_look_dir())
131 minetest.add_node(place_pos, {name = "flowers:waterlily", param2 = fdir})
135 if not minetest.is_creative_enabled(placer:get_player_name()) then
136 itemstack:take_item()
138 return itemstack
140 end,
141 on_rotate = "simple",
146 local algae_list = { {nil}, {2}, {3}, {4} }
149 for i in ipairs(algae_list) do
150 local num = ""
151 local algae_groups = {snappy = 3,flammable=2,seaweed=1}
154 if algae_list[i][1] ~= nil then
155 num = "_"..algae_list[i][1]
156 algae_groups = { snappy = 3,flammable=2,seaweed=1, not_in_creative_inventory=1 }
160 minetest.register_node(":flowers:seaweed"..num, {
161 description = S("Seaweed"),
162 drawtype = "nodebox",
163 tiles = {
164 "flowers_seaweed"..num..".png",
165 "flowers_seaweed"..num..".png^[transformFY",
166 "blank.png",
168 inventory_image = "flowers_seaweed_2.png",
169 wield_image = "flowers_seaweed_2.png",
170 sunlight_propagates = true,
171 paramtype = "light",
172 paramtype2 = "facedir",
173 walkable = false,
174 groups = algae_groups,
175 sounds = hades_sounds.node_sound_leaves_defaults(),
176 node_box = {
177 type = "fixed",
178 fixed = { -0.5, -0.5, -0.5, 0.5, -7/16, 0.5 },
180 node_box = {
181 type = "fixed",
182 fixed = { -0.5, -0.5, -0.5, 0.5, -0.49, 0.5 },
184 buildable_to = true,
187 liquids_pointable = true,
188 drop = "flowers:seaweed",
189 on_place = function(itemstack, placer, pointed_thing)
190 local keys=placer:get_player_control()
191 local pt = pointed_thing
194 local place_pos = nil
195 local top_pos = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z}
196 local under_node = minetest.get_node(pt.under)
197 local above_node = minetest.get_node(pt.above)
198 local top_node = minetest.get_node(top_pos)
201 if plantslib:get_nodedef_field(under_node.name, "buildable_to") then
202 if under_node.name ~= "hades_core:water_source" then
203 place_pos = pt.under
204 elseif top_node.name ~= "hades_core:water_source"
205 and plantslib:get_nodedef_field(top_node.name, "buildable_to") then
206 place_pos = top_pos
207 else
208 return itemstack
210 elseif plantslib:get_nodedef_field(above_node.name, "buildable_to") then
211 place_pos = pt.above
213 if not place_pos then
214 return itemstack
217 if not plantslib:node_is_owned(place_pos, placer) then
220 local nodename = "hades_core:cobble" -- :D
222 if not keys["sneak"] then
223 local node = minetest.get_node(pt.under)
224 local seaweed = math.random(1,4)
225 if seaweed == 1 then
226 nodename = "flowers:seaweed"
227 elseif seaweed == 2 then
228 nodename = "flowers:seaweed_2"
229 elseif seaweed == 3 then
230 nodename = "flowers:seaweed_3"
231 elseif seaweed == 4 then
232 nodename = "flowers:seaweed_4"
234 minetest.add_node(place_pos, {name = nodename, param2 = math.random(0,3) })
235 else
236 local fdir = minetest.dir_to_facedir(placer:get_look_dir())
237 minetest.add_node(place_pos, {name = "flowers:seaweed", param2 = fdir})
241 if not minetest.is_creative_enabled(placer:get_player_name()) then
242 itemstack:take_item()
244 return itemstack
246 end,
247 on_rotate = "simple",
252 -- ongen registrations
255 flowers_plus.grow_waterlily = function(pos)
256 local right_here = {x=pos.x, y=pos.y+1, z=pos.z}
257 for i in ipairs(lilies_list) do
258 local chance = math.random(1,8)
259 local ext = ""
260 local num = lilies_list[i][3]
263 if lilies_list[i][1] ~= nil then
264 ext = "_"..lilies_list[i][1]
268 if chance == num then
269 minetest.add_node(right_here, {name="flowers:waterlily"..ext, param2=math.random(0,3)})
275 plantslib:register_generate_plant({
276 surface = {"hades_core:water_source"},
277 max_count = lilypads_max_count,
278 rarity = lilypads_rarity,
279 min_elevation = -30,
280 max_elevation = 100,
281 near_nodes = {"hades_core:dirt_with_grass"},
282 near_nodes_size = 4,
283 near_nodes_vertical = 1,
284 near_nodes_count = 1,
285 plantlife_limit = -0.9,
286 temp_max = -0.22,
287 temp_min = 0.22,
289 "flowers_plus.grow_waterlily"
293 flowers_plus.grow_seaweed = function(pos)
294 local right_here = {x=pos.x, y=pos.y+1, z=pos.z}
295 minetest.add_node(right_here, {name="along_shore:seaweed_"..math.random(1,4), param2=math.random(1,3)})
299 plantslib:register_generate_plant({
300 surface = {"hades_core:water_source"},
301 max_count = seaweed_max_count,
302 rarity = seaweed_rarity,
303 -- min_elevation = 1,
304 max_elevation = 100,
305 near_nodes = {"hades_core:mossystone", "hades_core:dirt_with_grass"},
306 near_nodes_size = 3,
307 near_nodes_vertical = 2,
308 near_nodes_count = 1,
309 plantlife_limit = -1.0,
311 "flowers_plus.grow_seaweed"
314 plantslib:spawn_on_surfaces({
315 spawn_delay = SPAWN_DELAY/2,
316 spawn_plants = {
317 "flowers:waterlily",
318 "flowers:waterlily_225",
319 "flowers:waterlily_45",
320 "flowers:waterlily_675",
321 "flowers:waterlily_s1",
322 "flowers:waterlily_s2",
323 "flowers:waterlily_s3",
324 "flowers:waterlily_s4"
326 avoid_radius = 2.5,
327 spawn_chance = SPAWN_CHANCE*4,
328 spawn_surfaces = {"hades_core:water_source"},
329 avoid_nodes = {"group:flower", "group:flora" },
330 seed_diff = flowers_seed_diff,
331 light_min = 9,
332 depth_max = 2,
333 random_facedir = {0,3}
337 plantslib:spawn_on_surfaces({
338 spawn_delay = SPAWN_DELAY*2,
339 spawn_plants = {"flowers:seaweed"},
340 spawn_chance = SPAWN_CHANCE*2,
341 spawn_surfaces = {"hades_core:water_source"},
342 avoid_nodes = {"group:flower", "group:flora"},
343 seed_diff = flowers_seed_diff,
344 light_min = 4,
345 light_max = 10,
346 neighbors = {"hades_core:dirt_with_grass"},
347 facedir = 1
351 plantslib:spawn_on_surfaces({
352 spawn_delay = SPAWN_DELAY*2,
353 spawn_plants = {"flowers:seaweed"},
354 spawn_chance = SPAWN_CHANCE*2,
355 spawn_surfaces = {"hades_core:dirt_with_grass"},
356 avoid_nodes = {"group:flower", "group:flora" },
357 seed_diff = flowers_seed_diff,
358 light_min = 4,
359 light_max = 10,
360 neighbors = {"hades_core:water_source"},
361 ncount = 1,
362 facedir = 1
365 -- crafting recipes!
368 minetest.register_craft({
369 output = 'flowers:seaweed 3',
370 recipe = {{'flowers:waterlily'},}
373 minetest.register_abm({
374 label = "Turn seaweed to waterlily",
375 nodenames = {"flowers:seaweed"},
376 interval = 500,
377 chance = 75,
378 action = function(pos, node)
379 minetest.set_node(pos, {name="flowers:waterlily"})
380 end,
383 minetest.log("action", "[flowers_plus] loaded.")