Refactor code of snowed nodes
This commit is contained in:
parent
b88ae2f1e4
commit
576af661b1
2 changed files with 84 additions and 94 deletions
|
@ -1107,3 +1107,77 @@ minetest.register_abm({
|
|||
end
|
||||
})
|
||||
|
||||
---- Functions for snowed dirt-like blocks. ----
|
||||
|
||||
-- Lookup tables
|
||||
mcl_core.snowed_nodes = {}
|
||||
mcl_core.snowed_nodes_reverse = {}
|
||||
|
||||
-- Registers a snowed variant of a dirtlike node (e.g. grass block, podzol, mycelium).
|
||||
-- * itemstring_snowed: Itemstring of the snowed node to add
|
||||
-- * itemstring_clear: Itemstring of the original “clear” node without snow
|
||||
-- * tiles: Optional custom tiles
|
||||
mcl_core.register_snowed_node = function(itemstring_snowed, itemstring_clear, tiles)
|
||||
local def = table.copy(minetest.registered_nodes[itemstring_clear])
|
||||
-- Just some group clearing
|
||||
def.description = nil
|
||||
def._doc_items_longdesc = nil
|
||||
def._doc_items_usagehelp = nil
|
||||
def._doc_items_create_entry = false
|
||||
def.groups.not_in_creative_inventory = 1
|
||||
|
||||
-- Enderman must never take this because this block is supposed to be always buried below snow.
|
||||
def.groups.enderman_takable = nil
|
||||
|
||||
if not tiles then
|
||||
def.tiles = {"default_snow.png", "default_dirt.png", "mcl_core_grass_side_snowed.png"}
|
||||
end
|
||||
|
||||
-- Register stuff
|
||||
minetest.register_node(itemstring_snowed, def)
|
||||
|
||||
mcl_core.snowed_nodes[itemstring_snowed] = itemstring_clear
|
||||
mcl_core.snowed_nodes_reverse[itemstring_clear] = itemstring_snowed
|
||||
|
||||
if minetest.get_modpath("doc") then
|
||||
doc.add_entry_alias("nodes", itemstring_clear, "nodes", itemstring_snowed)
|
||||
end
|
||||
end
|
||||
|
||||
-- Reverts a snowed dirtlike node at pos to its original snow-less form.
|
||||
-- This function assumes there is no snow cover node above. This function
|
||||
-- MUST NOT be called if there is a snow cover node above pos.
|
||||
mcl_core.clear_snow_dirt = function(pos, node)
|
||||
if mcl_core.snowed_nodes[node.name] then
|
||||
minetest.swap_node(pos, {name=mcl_core.snowed_nodes[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
|
||||
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)
|
||||
if mcl_core.snowed_nodes_reverse[node.name] then
|
||||
minetest.swap_node(npos, {name=mcl_core.snowed_nodes_reverse[node.name]})
|
||||
end
|
||||
end
|
||||
-- after_destruct
|
||||
-- Clears snowed dirtlike node below.
|
||||
mcl_core.after_snow_destruct = function(pos)
|
||||
local nn = minetest.get_node(pos).name
|
||||
-- No-op if snow was replaced with snow
|
||||
if minetest.get_item_group(nn, "snow_cover") == 1 then
|
||||
return
|
||||
end
|
||||
local npos = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
local node = minetest.get_node(npos)
|
||||
mcl_core.clear_snow_dirt(npos, node)
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue