From d7b543f5d7f0c44e81772a4d6afe07ff6f69c4c1 Mon Sep 17 00:00:00 2001 From: sys4 Date: Thu, 23 Jul 2020 22:45:28 +0200 Subject: [PATCH] [dryplants] Tidy code --- dryplants/juncus.lua | 11 +++++++---- dryplants/meadowvariation.lua | 3 +-- dryplants/moregrass.lua | 5 +++-- dryplants/reedmace.lua | 17 ++++++++++------- dryplants/settings.txt | 2 +- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/dryplants/juncus.lua b/dryplants/juncus.lua index c945dcf..15d45e5 100644 --- a/dryplants/juncus.lua +++ b/dryplants/juncus.lua @@ -11,8 +11,11 @@ -- support for i18n local S = minetest.get_translator("dryplants") +local random = math.random +local sqrt = math.sqrt + 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} if minetest.get_node(right_here).name == "air" -- instead of check_air = true, or minetest.get_node(right_here).name == "default:junglegrass" then @@ -27,7 +30,7 @@ end minetest.register_node("dryplants:juncus", { description = S("Juncus"), drawtype = "plantlike", - visual_scale = math.sqrt(8), + visual_scale = sqrt(8), paramtype = "light", tiles = {"dryplants_juncus_03.png"}, inventory_image = "dryplants_juncus_inv.png", @@ -53,7 +56,7 @@ minetest.register_node("dryplants:juncus", { return end 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} if juncus_type == 2 then minetest.swap_node(right_here, {name="dryplants:juncus_02"}) @@ -69,7 +72,7 @@ minetest.register_node("dryplants:juncus", { minetest.register_node("dryplants:juncus_02", { description = S("Juncus"), drawtype = "plantlike", - visual_scale = math.sqrt(8), + visual_scale = sqrt(8), paramtype = "light", tiles = {"dryplants_juncus_02.png"}, walkable = false, diff --git a/dryplants/meadowvariation.lua b/dryplants/meadowvariation.lua index 9a3c3bc..090eaed 100644 --- a/dryplants/meadowvariation.lua +++ b/dryplants/meadowvariation.lua @@ -8,8 +8,7 @@ ----------------------------------------------------------------------------------------------- abstract_dryplants.grow_grass_variation = function(pos) - local right_here = {x=pos.x, y=pos.y, z=pos.z} - minetest.swap_node(right_here, {name="dryplants:grass_short"}) + minetest.swap_node(pos, {name="dryplants:grass_short"}) end biome_lib:register_generate_plant({ diff --git a/dryplants/moregrass.lua b/dryplants/moregrass.lua index b8d5f82..1ea9299 100644 --- a/dryplants/moregrass.lua +++ b/dryplants/moregrass.lua @@ -7,12 +7,13 @@ -- Looked at code from: default ----------------------------------------------------------------------------------------------- +local random = math.random + abstract_dryplants.grow_grass = function(pos) 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, 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 diff --git a/dryplants/reedmace.lua b/dryplants/reedmace.lua index 49a1022..4f61820 100644 --- a/dryplants/reedmace.lua +++ b/dryplants/reedmace.lua @@ -20,13 +20,16 @@ -- support for i18n local S = minetest.get_translator("dryplants") +local random = math.random +local sqrt = math.sqrt + ----------------------------------------------------------------------------------------------- -- REEDMACE SHAPES ----------------------------------------------------------------------------------------------- abstract_dryplants.grow_reedmace = function(pos) - local size = math.random(1,3) - local spikes = math.random(1,3) + local size = random(1,3) + local spikes = random(1,3) 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_03 = {x = pos.x, y = pos.y + 3, z = pos.z} @@ -51,8 +54,8 @@ abstract_dryplants.grow_reedmace = function(pos) end abstract_dryplants.grow_reedmace_water = function(pos) - local size = math.random(1,3) - local spikes = math.random(1,3) + local size = random(1,3) + local spikes = random(1,3) 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_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", { description = S("Reedmace, height: 2"), drawtype = "plantlike", - visual_scale = math.sqrt(8), + visual_scale = sqrt(8), paramtype = "light", tiles = {"dryplants_reedmace_height_2.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", { description = S("Reedmace, height: 3"), drawtype = "plantlike", - visual_scale = math.sqrt(8), + visual_scale = sqrt(8), paramtype = "light", tiles = {"dryplants_reedmace_height_3.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", { description = S("Reedmace, height: 3 & Spikes"), drawtype = "plantlike", - visual_scale = math.sqrt(8), + visual_scale = sqrt(8), paramtype = "light", tiles = {"dryplants_reedmace_height_3_spikes.png"}, inventory_image = "dryplants_reedmace_top.png", diff --git a/dryplants/settings.txt b/dryplants/settings.txt index cc12a9c..114929b 100644 --- a/dryplants/settings.txt +++ b/dryplants/settings.txt @@ -48,5 +48,5 @@ HAY_DRYING_TIME = 3600 -- seconds REED_WILL_DRY = false -- wet reed nodes will become dry reed nodes REED_DRYING_TIME = 3600 -- seconds -AUTO_ROOF_CORNER = true +AUTO_ROOF_CORNER = false