From 1b7c41fc81d40cb43eee24631d65bba61b3dd98b Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 25 Mar 2019 09:22:08 +0100 Subject: [PATCH] Grass block: Change grass color depending on biome --- mods/ITEMS/mcl_core/functions.lua | 20 ++++++++++++++++++++ mods/ITEMS/mcl_core/nodes_base.lua | 15 +++------------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/mods/ITEMS/mcl_core/functions.lua b/mods/ITEMS/mcl_core/functions.lua index c040ce7e8..bad9f3bd2 100644 --- a/mods/ITEMS/mcl_core/functions.lua +++ b/mods/ITEMS/mcl_core/functions.lua @@ -639,6 +639,23 @@ end local grass_spread_randomizer = PseudoRandom(minetest.get_mapgen_setting("seed")) +-- Return appropriate grass block node for pos. Dry grass for dry/hot biomes, normal grass otherwise. +function mcl_core.get_grass_block_type(pos) + local biome_data = minetest.get_biome_data(pos) + local dry = false + if biome_data then + local biome = biome_data.biome + local biome_name = minetest.get_biome_name(biome) + local biome_type = minetest.registered_biomes[biome_name]._mcl_biome_type + dry = biome_type == "hot" + end + if dry then + return {name="mcl_core:dirt_with_dry_grass"} + else + return {name="mcl_core:dirt_with_grass"} + end +end + ------------------------------ -- Spread grass blocks and mycelium on neighbor dirt ------------------------------ @@ -681,6 +698,9 @@ minetest.register_abm({ if light_self >= 4 and light_source >= 9 then -- All checks passed! Let's spread the grass/mycelium! local n2 = minetest.get_node(p2) + if minetest.get_item_group(n2.name, "grass_block") ~= 0 then + n2 = mcl_core.get_grass_block_type(pos) + end minetest.set_node(pos, {name=n2.name}) -- If this was mycelium, uproot plant above diff --git a/mods/ITEMS/mcl_core/nodes_base.lua b/mods/ITEMS/mcl_core/nodes_base.lua index 0661bb43d..bcef7d74f 100644 --- a/mods/ITEMS/mcl_core/nodes_base.lua +++ b/mods/ITEMS/mcl_core/nodes_base.lua @@ -321,18 +321,9 @@ minetest.register_node("mcl_core:dirt_with_grass", { footstep = {name="default_grass_footstep", gain=0.4}, }), on_construct = function(pos) - local dim = mcl_worlds.pos_to_dimension(pos) - local dry - if dim == "nether" then - dry = true - else - local found_node = minetest.find_node_near(pos, 1, {"mcl_core:dirt_with_dry_grass", "mcl_core:dirt_with_dry_grass_snow"}) - if found_node then - dry = true - end - end - if dry then - minetest.set_node(pos, {name="mcl_core:dirt_with_dry_grass"}) + local new_node = mcl_core.get_grass_block_type(pos) + if new_node.name ~= "mcl_core:dirt_with_grass" then + minetest.set_node(pos, new_node) end return mcl_core.on_snowable_construct(pos) end,