1
0
mirror of https://github.com/mt-mods/homedecor_modpack.git synced 2025-07-13 03:20:19 +02:00

use an expand def-field to automaticly expand and unexpand the three available types of expansion and let nearly all decor use this form

example of usage:
	expand = { top="homedecor:newnode", right="homedecor:rightnode", forward="homedecor:forwardnode" }
This commit is contained in:
Tim
2015-01-23 00:01:08 +01:00
committed by Vanessa Ezekowitz
parent 9912f72de6
commit d6ce145f9c
5 changed files with 97 additions and 252 deletions

View File

@ -16,6 +16,10 @@ local default_inventory_formspec = "size[8,9]"..
"list[current_player;main;0,6.08;8,3;8]"..
default.get_hotbar_bg(0,4.85)
local function remove_node_if()
end
--wrapper around minetest.register_node that sets sane defaults and interprets some specialized settings
function homedecor.register(name, def)
def.paramtype = def.paramtype or "light"
@ -73,6 +77,47 @@ function homedecor.register(name, def)
end
end
local expand = def.expand
def.expand = nil
if expand then
def.on_place = def.on_place or function(itemstack, placer, pointed_thing)
if expand.top then
homedecor.stack_vertically(itemstack, placer, pointed_thing, itemstack:get_name(), expand.top)
end
if expand.right then
homedecor.stack_sideways(itemstack, placer, pointed_thing, itemstack:get_name(), expand.right, true)
end
if expand.forward then
homedecor.stack_sideways(itemstack, placer, pointed_thing, itemstack:get_name(), expand.forward, false)
end
end
def.after_dig_node = def.after_dig_node or function(pos, oldnode, oldmetadata, digger)
if expand.top then
local top_pos = { x=pos.x, y=pos.y+1, z=pos.z }
if minetest.get_node(top_pos).name == expand.top then
minetest.remove_node(top_pos)
end
end
local fdir = oldnode.param2
if not fdir or fdir > 3 then return end
if expand.right then
local right_pos = { x=pos.x+homedecor.fdir_to_right[fdir+1][1], y=pos.y, z=pos.z+homedecor.fdir_to_right[fdir+1][2] }
if minetest.get_node(right_pos).name == expand.right then
minetest.remove_node(right_pos)
end
end
if expand.forward then
local forward_pos = { x=pos.x+homedecor.fdir_to_fwd[fdir+1][1], y=pos.y, z=pos.z+homedecor.fdir_to_fwd[fdir+1][2] }
if minetest.get_node(forward_pos).name == expand.forward then
minetest.remove_node(forward_pos)
end
end
end
end
-- register the actual minetest node
minetest.register_node("homedecor:" .. name, def)
end