From d4e83d7e78c23faecffd26a6d7bdc2f87b5027c1 Mon Sep 17 00:00:00 2001 From: sys4 Date: Fri, 24 Jul 2020 00:03:48 +0200 Subject: [PATCH] [trunks] Tidy code and disable auto roof corners ABM --- trunks/generating.lua | 52 ++++++++++++++++++++------------------ trunks/nodes.lua | 4 ++- trunks/trunks_settings.txt | 4 +-- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/trunks/generating.lua b/trunks/generating.lua index 699baf9..f077f67 100644 --- a/trunks/generating.lua +++ b/trunks/generating.lua @@ -4,8 +4,10 @@ -- TWiGS ----------------------------------------------------------------------------------------------- +local random = math.random + abstract_trunks.place_twig = function(pos) - local twig_size = math.random(1,27) + local twig_size = random(1,27) local right_here = {x=pos.x , y=pos.y+1, z=pos.z } local north = {x=pos.x , y=pos.y+1, z=pos.z+1} @@ -28,7 +30,7 @@ abstract_trunks.place_twig = function(pos) local node_n_w = minetest.get_node(north_west) -- small twigs if twig_size <= 16 then - minetest.swap_node(right_here, {name="trunks:twig_"..math.random(1,4), param2=math.random(0,3)}) + minetest.swap_node(right_here, {name="trunks:twig_"..random(1,4), param2=random(0,3)}) end -- big twigs if Big_Twigs == true then @@ -147,7 +149,7 @@ abstract_trunks.place_twig = function(pos) end end elseif twig_size <= 25 then - minetest.swap_node(right_here, {name="trunks:twig_"..math.random(12,13), param2=math.random(0,3)}) + minetest.swap_node(right_here, {name="trunks:twig_"..random(12,13), param2=random(0,3)}) end end end @@ -254,10 +256,10 @@ abstract_trunks.place_trunk = function(pos) local MoD = TRuNKS[i][1] local TRuNK = TRuNKS[i][2] local NR = TRuNKS[i][3] - local chance = math.random(1, 17) - local length = math.random(3,5) + local chance = random(1, 17) + local length = random(3,5) if chance == NR then - local trunk_type = math.random(1,3) + local trunk_type = random(1,3) if trunk_type == 1 then if minetest.get_modpath(MoD) ~= nil then minetest.swap_node(right_here, {name=MoD..":"..TRuNK}) @@ -355,12 +357,12 @@ biome_lib:register_generate_plant({ if Moss_on_ground == true then abstract_trunks.grow_moss_on_ground = function(pos) local on_ground = {x=pos.x, y=pos.y+1, z=pos.z} - local moss_type = math.random(1,21) + local moss_type = random(1,21) if moss_type == 1 then - minetest.swap_node(on_ground, {name="trunks:moss_fungus", param2=math.random(0,3)}) + minetest.swap_node(on_ground, {name="trunks:moss_fungus", param2=random(0,3)}) else - minetest.swap_node(on_ground, {name="trunks:moss", param2=math.random(0,3)}) + minetest.swap_node(on_ground, {name="trunks:moss", param2=random(0,3)}) end end @@ -406,44 +408,44 @@ abstract_trunks.grow_moss_on_trunk = function(pos) local node_under = minetest.get_node(undrneath) --if minetest.get_item_group(node_under.name, "tree") < 1 then - local moss_type = math.random(1,41) + local moss_type = random(1,41) if minetest.registered_nodes[node_here.name].buildable_to then -- instead of check_air = true, if moss_type == 1 then - minetest.swap_node(on_ground, {name="trunks:moss_fungus", param2=math.random(0,3) --[[1]]}) + minetest.swap_node(on_ground, {name="trunks:moss_fungus", param2=random(0,3) --[[1]]}) elseif moss_type < 22 then - minetest.swap_node(on_ground, {name="trunks:moss", param2=math.random(0,3) --[[1]]}) + minetest.swap_node(on_ground, {name="trunks:moss", param2=random(0,3) --[[1]]}) end end - local moss_type = math.random(1,31) -- cliche of more moss at north + local moss_type = random(1,31) -- cliche of more moss at north if minetest.registered_nodes[node_north.name].buildable_to then -- instead of check_air = true, if moss_type == 1 then - minetest.swap_node(at_side_n, {name="trunks:moss_fungus", param2=math.random(4,7)}) -- 5,4,6,7 + minetest.swap_node(at_side_n, {name="trunks:moss_fungus", param2=random(4,7)}) -- 5,4,6,7 elseif moss_type < 22 then - minetest.swap_node(at_side_n, {name="trunks:moss", param2=math.random(4,7)}) + minetest.swap_node(at_side_n, {name="trunks:moss", param2=random(4,7)}) end end - local moss_type = math.random(1,41) + local moss_type = random(1,41) if minetest.registered_nodes[node_east.name].buildable_to then -- instead of check_air = true, if moss_type == 1 then - minetest.swap_node(at_side_e, {name="trunks:moss_fungus", param2=math.random(12,15)}) + minetest.swap_node(at_side_e, {name="trunks:moss_fungus", param2=random(12,15)}) elseif moss_type < 22 then - minetest.swap_node(at_side_e, {name="trunks:moss", param2=math.random(12,15)}) + minetest.swap_node(at_side_e, {name="trunks:moss", param2=random(12,15)}) end end - local moss_type = math.random(1,41) + local moss_type = random(1,41) if minetest.registered_nodes[node_south.name].buildable_to then -- instead of check_air = true, if moss_type == 1 then - minetest.swap_node(at_side_s, {name="trunks:moss_fungus", param2=math.random(8,11)}) + minetest.swap_node(at_side_s, {name="trunks:moss_fungus", param2=random(8,11)}) elseif moss_type < 22 then - minetest.swap_node(at_side_s, {name="trunks:moss", param2=math.random(8,11)}) + minetest.swap_node(at_side_s, {name="trunks:moss", param2=random(8,11)}) end end - local moss_type = math.random(1,41) + local moss_type = random(1,41) if minetest.registered_nodes[node_west.name].buildable_to then -- instead of check_air = true, if moss_type == 1 then - minetest.swap_node(at_side_w, {name="trunks:moss_fungus", param2=math.random(16,19)}) + minetest.swap_node(at_side_w, {name="trunks:moss_fungus", param2=random(16,19)}) elseif moss_type < 22 then - minetest.swap_node(at_side_w, {name="trunks:moss", param2=math.random(16,19)}) + minetest.swap_node(at_side_w, {name="trunks:moss", param2=random(16,19)}) end end --end @@ -487,7 +489,7 @@ end if Roots == true then -- see settings.txt abstract_trunks.grow_roots = function(pos) - local twig_size = math.random(1,27) + local twig_size = random(1,27) local right_here = {x=pos.x , y=pos.y , z=pos.z } local below = {x=pos.x , y=pos.y-1, z=pos.z } diff --git a/trunks/nodes.lua b/trunks/nodes.lua index 04352dd..71a8f9f 100644 --- a/trunks/nodes.lua +++ b/trunks/nodes.lua @@ -1,6 +1,8 @@ -- Code by Mossmanikin & Neuromancer -- support for i18n local S = minetest.get_translator("trunks") + +local random = math.random ----------------------------------------------------------------------------------------------- -- TWiGS ----------------------------------------------------------------------------------------------- @@ -44,7 +46,7 @@ for i in pairs(NoDe) do local pt = pointed_thing local direction = minetest.dir_to_facedir(placer:get_look_dir()) if minetest.get_node(pt.above).name=="air" then - minetest.swap_node(pt.above, {name="trunks:twig_"..math.random(1,4), param2=direction}) + minetest.swap_node(pt.above, {name="trunks:twig_"..random(1,4), param2=direction}) if not minetest.setting_getbool("creative_mode") then itemstack:take_item() end diff --git a/trunks/trunks_settings.txt b/trunks/trunks_settings.txt index 7fe8822..9c79318 100644 --- a/trunks/trunks_settings.txt +++ b/trunks/trunks_settings.txt @@ -64,7 +64,7 @@ Moss_on_trunk_Max_Count = 640 -- absolute maximum number in an area of 80x80x80 Moss_on_trunk_Rarity = 24 -- larger values makes moss more rare (100 means chance of 0 %) -Auto_Roof_Corner = true -- behavior is similar (not the same!) to the one of minecraft stairs +Auto_Roof_Corner = false -- behavior is similar (not the same!) to the one of minecraft stairs -Roots = true \ No newline at end of file +Roots = true