[dryplants] Tidy code

This commit is contained in:
Sys Quatre 2020-07-23 22:45:28 +02:00
parent f661500cb3
commit d7b543f5d7
5 changed files with 22 additions and 16 deletions

View File

@ -11,8 +11,11 @@
-- support for i18n -- support for i18n
local S = minetest.get_translator("dryplants") local S = minetest.get_translator("dryplants")
local random = math.random
local sqrt = math.sqrt
abstract_dryplants.grow_juncus = function(pos) abstract_dryplants.grow_juncus = function(pos)
local juncus_type = math.random(2,3) local juncus_type = random(2,3)
local right_here = {x=pos.x, y=pos.y+1, z=pos.z} local right_here = {x=pos.x, y=pos.y+1, z=pos.z}
if minetest.get_node(right_here).name == "air" -- instead of check_air = true, if minetest.get_node(right_here).name == "air" -- instead of check_air = true,
or minetest.get_node(right_here).name == "default:junglegrass" then or minetest.get_node(right_here).name == "default:junglegrass" then
@ -27,7 +30,7 @@ end
minetest.register_node("dryplants:juncus", { minetest.register_node("dryplants:juncus", {
description = S("Juncus"), description = S("Juncus"),
drawtype = "plantlike", drawtype = "plantlike",
visual_scale = math.sqrt(8), visual_scale = sqrt(8),
paramtype = "light", paramtype = "light",
tiles = {"dryplants_juncus_03.png"}, tiles = {"dryplants_juncus_03.png"},
inventory_image = "dryplants_juncus_inv.png", inventory_image = "dryplants_juncus_inv.png",
@ -53,7 +56,7 @@ minetest.register_node("dryplants:juncus", {
return return
end end
local pos = pointed_thing.under local pos = pointed_thing.under
local juncus_type = math.random(2,3) local juncus_type = random(2,3)
local right_here = {x=pos.x, y=pos.y+1, z=pos.z} local right_here = {x=pos.x, y=pos.y+1, z=pos.z}
if juncus_type == 2 then if juncus_type == 2 then
minetest.swap_node(right_here, {name="dryplants:juncus_02"}) minetest.swap_node(right_here, {name="dryplants:juncus_02"})
@ -69,7 +72,7 @@ minetest.register_node("dryplants:juncus", {
minetest.register_node("dryplants:juncus_02", { minetest.register_node("dryplants:juncus_02", {
description = S("Juncus"), description = S("Juncus"),
drawtype = "plantlike", drawtype = "plantlike",
visual_scale = math.sqrt(8), visual_scale = sqrt(8),
paramtype = "light", paramtype = "light",
tiles = {"dryplants_juncus_02.png"}, tiles = {"dryplants_juncus_02.png"},
walkable = false, walkable = false,

View File

@ -8,8 +8,7 @@
----------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------
abstract_dryplants.grow_grass_variation = function(pos) abstract_dryplants.grow_grass_variation = function(pos)
local right_here = {x=pos.x, y=pos.y, z=pos.z} minetest.swap_node(pos, {name="dryplants:grass_short"})
minetest.swap_node(right_here, {name="dryplants:grass_short"})
end end
biome_lib:register_generate_plant({ biome_lib:register_generate_plant({

View File

@ -7,12 +7,13 @@
-- Looked at code from: default -- Looked at code from: default
----------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------
local random = math.random
abstract_dryplants.grow_grass = function(pos) abstract_dryplants.grow_grass = function(pos)
local right_here = {x=pos.x, y=pos.y+1, z=pos.z} local right_here = {x=pos.x, y=pos.y+1, z=pos.z}
local grass_size = math.random(1,5)
if minetest.get_node(right_here).name == "air" -- instead of check_air = true, if minetest.get_node(right_here).name == "air" -- instead of check_air = true,
or minetest.get_node(right_here).name == "default:junglegrass" then or minetest.get_node(right_here).name == "default:junglegrass" then
minetest.swap_node(right_here, {name="default:grass_"..grass_size}) minetest.swap_node(right_here, {name="default:grass_"..random(1,5)})
end end
end end

View File

@ -20,13 +20,16 @@
-- support for i18n -- support for i18n
local S = minetest.get_translator("dryplants") local S = minetest.get_translator("dryplants")
local random = math.random
local sqrt = math.sqrt
----------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------
-- REEDMACE SHAPES -- REEDMACE SHAPES
----------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------
abstract_dryplants.grow_reedmace = function(pos) abstract_dryplants.grow_reedmace = function(pos)
local size = math.random(1,3) local size = random(1,3)
local spikes = math.random(1,3) local spikes = random(1,3)
local pos_01 = {x = pos.x, y = pos.y + 1, z = pos.z} local pos_01 = {x = pos.x, y = pos.y + 1, z = pos.z}
local pos_02 = {x = pos.x, y = pos.y + 2, z = pos.z} local pos_02 = {x = pos.x, y = pos.y + 2, z = pos.z}
local pos_03 = {x = pos.x, y = pos.y + 3, z = pos.z} local pos_03 = {x = pos.x, y = pos.y + 3, z = pos.z}
@ -51,8 +54,8 @@ abstract_dryplants.grow_reedmace = function(pos)
end end
abstract_dryplants.grow_reedmace_water = function(pos) abstract_dryplants.grow_reedmace_water = function(pos)
local size = math.random(1,3) local size = random(1,3)
local spikes = math.random(1,3) local spikes = random(1,3)
local pos_01 = {x = pos.x, y = pos.y + 1, z = pos.z} local pos_01 = {x = pos.x, y = pos.y + 1, z = pos.z}
local pos_02 = {x = pos.x, y = pos.y + 2, z = pos.z} local pos_02 = {x = pos.x, y = pos.y + 2, z = pos.z}
local pos_03 = {x = pos.x, y = pos.y + 3, z = pos.z} local pos_03 = {x = pos.x, y = pos.y + 3, z = pos.z}
@ -127,7 +130,7 @@ minetest.register_node("dryplants:reedmace_top", {
minetest.register_node("dryplants:reedmace_height_2", { minetest.register_node("dryplants:reedmace_height_2", {
description = S("Reedmace, height: 2"), description = S("Reedmace, height: 2"),
drawtype = "plantlike", drawtype = "plantlike",
visual_scale = math.sqrt(8), visual_scale = sqrt(8),
paramtype = "light", paramtype = "light",
tiles = {"dryplants_reedmace_height_2.png"}, tiles = {"dryplants_reedmace_height_2.png"},
inventory_image = "dryplants_reedmace_top.png", inventory_image = "dryplants_reedmace_top.png",
@ -150,7 +153,7 @@ minetest.register_node("dryplants:reedmace_height_2", {
minetest.register_node("dryplants:reedmace_height_3", { minetest.register_node("dryplants:reedmace_height_3", {
description = S("Reedmace, height: 3"), description = S("Reedmace, height: 3"),
drawtype = "plantlike", drawtype = "plantlike",
visual_scale = math.sqrt(8), visual_scale = sqrt(8),
paramtype = "light", paramtype = "light",
tiles = {"dryplants_reedmace_height_3.png"}, tiles = {"dryplants_reedmace_height_3.png"},
inventory_image = "dryplants_reedmace_top.png", inventory_image = "dryplants_reedmace_top.png",
@ -173,7 +176,7 @@ minetest.register_node("dryplants:reedmace_height_3", {
minetest.register_node("dryplants:reedmace_height_3_spikes", { minetest.register_node("dryplants:reedmace_height_3_spikes", {
description = S("Reedmace, height: 3 & Spikes"), description = S("Reedmace, height: 3 & Spikes"),
drawtype = "plantlike", drawtype = "plantlike",
visual_scale = math.sqrt(8), visual_scale = sqrt(8),
paramtype = "light", paramtype = "light",
tiles = {"dryplants_reedmace_height_3_spikes.png"}, tiles = {"dryplants_reedmace_height_3_spikes.png"},
inventory_image = "dryplants_reedmace_top.png", inventory_image = "dryplants_reedmace_top.png",

View File

@ -48,5 +48,5 @@ HAY_DRYING_TIME = 3600 -- seconds
REED_WILL_DRY = false -- wet reed nodes will become dry reed nodes REED_WILL_DRY = false -- wet reed nodes will become dry reed nodes
REED_DRYING_TIME = 3600 -- seconds REED_DRYING_TIME = 3600 -- seconds
AUTO_ROOF_CORNER = true AUTO_ROOF_CORNER = false