From 9fb148f8bf2b8a2c6592962e694aa3785c770995 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 6 Sep 2017 19:33:39 +0200 Subject: [PATCH] Make grass block and friends snowed if placed below snow cover --- mods/ITEMS/mcl_core/functions.lua | 26 ++++++++++++++++++++++++-- mods/ITEMS/mcl_core/nodes_base.lua | 3 +++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_core/functions.lua b/mods/ITEMS/mcl_core/functions.lua index 904c03dd4b..1ff0babdc2 100644 --- a/mods/ITEMS/mcl_core/functions.lua +++ b/mods/ITEMS/mcl_core/functions.lua @@ -1107,7 +1107,8 @@ minetest.register_abm({ end }) ----- Functions for snowed dirt-like blocks. ---- +---- FUNCTIONS FOR SNOWED NODES ---- +-- These are nodes which change their appearence when they are below a snow cover. -- Lookup tables mcl_core.snowed_nodes = {} @@ -1153,14 +1154,35 @@ mcl_core.clear_snow_dirt = function(pos, node) end end +---- [[[[[ Functions for snowable nodes (nodes that can become snowed). ]]]]] ---- +-- Always add these for snowable nodes. --- Functions for snow cover nodes. A snow cover node is a node which turns a snowed dirtlike +-- on_construct +-- Makes constructed snowable node snowed if placed below a snow cover node. +mcl_core.on_snowable_construct = function(pos) + -- Myself + local node = minetest.get_node(pos) + + -- Above + local apos = {x=pos.x, y=pos.y+1, z=pos.z} + local anode = minetest.get_node(apos) + + -- Make snowed if needed + if minetest.get_item_group(anode.name, "snow_cover") == 1 then + minetest.swap_node(pos, {name=mcl_core.snowed_nodes_reverse[node.name]}) + end +end + +---- [[[[[ Functions for snow cover nodes. ]]]]] ---- + +-- A snow cover node is a node which turns a snowed dirtlike -- -- node into its snowed form while it is placed above. -- MCL2's snow cover nodes are Top Snow (mcl_core:snow) and Snow (mcl_core:snowblock). -- Always add the following functions to snow cover nodes: -- on_construct +-- Makes snowable node below snowed. mcl_core.on_snow_construct = function(pos) local npos = {x=pos.x, y=pos.y-1, z=pos.z} local node = minetest.get_node(npos) diff --git a/mods/ITEMS/mcl_core/nodes_base.lua b/mods/ITEMS/mcl_core/nodes_base.lua index b22a8a78d0..08cd9807fb 100644 --- a/mods/ITEMS/mcl_core/nodes_base.lua +++ b/mods/ITEMS/mcl_core/nodes_base.lua @@ -307,6 +307,7 @@ minetest.register_node("mcl_core:dirt_with_grass", { sounds = mcl_sounds.node_sound_dirt_defaults({ footstep = {name="default_grass_footstep", gain=0.4}, }), + on_construct = mcl_core.on_snowable_construct, _mcl_blast_resistance = 3, _mcl_hardness = 0.6, }) @@ -347,6 +348,7 @@ minetest.register_node("mcl_core:mycelium", { sounds = mcl_sounds.node_sound_dirt_defaults({ footstep = {name="default_grass_footstep", gain=0.4}, }), + on_construct = mcl_core.on_snowable_construct, _mcl_blast_resistance = 2.5, _mcl_hardness = 0.6, }) @@ -361,6 +363,7 @@ minetest.register_node("mcl_core:podzol", { groups = {handy=1,shovely=3, soil=1, soil_sapling=2, soil_sugarcane=1, enderman_takable=1, building_block=1}, drop = 'mcl_core:dirt', sounds = mcl_sounds.node_sound_dirt_defaults(), + on_construct = mcl_core.on_snowable_construct, _mcl_blast_resistance = 2.5, _mcl_hardness = 0.6, })