2015-01-21 19:19:14 +01:00
|
|
|
homedecor = homedecor or {}
|
2016-12-15 23:24:11 +01:00
|
|
|
|
2015-09-08 09:24:01 +02:00
|
|
|
local placeholder_node = "homedecor:expansion_placeholder"
|
2015-01-21 19:19:14 +01:00
|
|
|
|
|
|
|
--wrapper around minetest.register_node that sets sane defaults and interprets some specialized settings
|
2015-08-19 18:47:24 +02:00
|
|
|
function homedecor.register(name, original_def)
|
|
|
|
local def = table.copy(original_def)
|
|
|
|
|
2022-02-04 00:40:38 +01:00
|
|
|
def.is_furnace = nil
|
|
|
|
|
2022-11-30 23:48:28 +01:00
|
|
|
if def.groups and (def.groups.crumbly or def.groups.oddly_breakable_by_hand) then
|
|
|
|
def.groups["handy"]=1
|
|
|
|
def._mcl_hardness=0.6
|
|
|
|
elseif def.groups and (def.groups.snappy or def.groups.choppy) then
|
|
|
|
def.groups["axey"]=5
|
|
|
|
def._mcl_hardness=1.6
|
|
|
|
elseif def.groups and (def.groups.cracky or def.groups.crumbly) then
|
|
|
|
def.groups["pickaxey"]=5
|
|
|
|
def._mcl_hardness=1.6
|
2022-11-27 03:00:02 +01:00
|
|
|
end
|
|
|
|
|
2024-03-01 00:49:24 +01:00
|
|
|
def.is_ground_content = def.is_ground_content == true
|
|
|
|
|
2015-01-21 19:19:14 +01:00
|
|
|
def.drawtype = def.drawtype
|
2015-08-19 16:14:17 +02:00
|
|
|
or (def.mesh and "mesh")
|
|
|
|
or (def.node_box and "nodebox")
|
2015-01-21 19:19:14 +01:00
|
|
|
|
2015-02-05 10:34:17 +01:00
|
|
|
def.paramtype = def.paramtype or "light"
|
2015-02-05 10:51:34 +01:00
|
|
|
|
|
|
|
-- avoid facedir for some drawtypes as they might be used internally for something else
|
|
|
|
-- even if undocumented
|
|
|
|
if not (def.drawtype == "glasslike_framed"
|
|
|
|
or def.drawtype == "raillike"
|
|
|
|
or def.drawtype == "plantlike"
|
|
|
|
or def.drawtype == "firelike") then
|
|
|
|
|
2015-02-05 10:34:17 +01:00
|
|
|
def.paramtype2 = def.paramtype2 or "facedir"
|
|
|
|
end
|
|
|
|
|
2015-08-19 18:47:24 +02:00
|
|
|
homedecor.handle_inventory(name, def, original_def)
|
2015-08-19 16:14:17 +02:00
|
|
|
|
2015-01-21 19:19:14 +01:00
|
|
|
local infotext = def.infotext
|
2015-01-22 22:54:08 +01:00
|
|
|
--def.infotext = nil -- currently used to set locked refrigerator infotexts
|
2015-01-21 19:19:14 +01:00
|
|
|
|
2015-08-19 17:30:37 +02:00
|
|
|
if infotext then
|
|
|
|
local on_construct = def.on_construct
|
2015-01-21 19:19:14 +01:00
|
|
|
def.on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("infotext", infotext)
|
2015-08-19 17:30:37 +02:00
|
|
|
if on_construct then on_construct(pos) end
|
2015-01-21 19:19:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-23 00:48:53 +01:00
|
|
|
local expand = def.expand
|
2015-01-23 00:01:08 +01:00
|
|
|
def.expand = nil
|
2015-01-23 00:48:53 +01:00
|
|
|
local after_unexpand = def.after_unexpand
|
|
|
|
def.after_unexpand = nil
|
2015-01-23 00:01:08 +01:00
|
|
|
|
|
|
|
if expand then
|
2015-09-08 09:10:25 +02:00
|
|
|
-- dissallow rotating only half the expanded node by default
|
|
|
|
-- unless we know better
|
2022-05-03 21:21:14 +02:00
|
|
|
def.on_rotate = def.on_rotate or (
|
|
|
|
minetest.get_modpath("screwdriver") and (
|
|
|
|
(def.mesh and expand.top and screwdriver.rotate_simple) or
|
|
|
|
screwdriver.disallow
|
|
|
|
)
|
|
|
|
)
|
2015-09-08 09:10:25 +02:00
|
|
|
|
2015-01-23 00:01:08 +01:00
|
|
|
def.on_place = def.on_place or function(itemstack, placer, pointed_thing)
|
|
|
|
if expand.top then
|
2015-01-26 15:58:37 +01:00
|
|
|
return homedecor.stack_vertically(itemstack, placer, pointed_thing, itemstack:get_name(), expand.top)
|
|
|
|
elseif expand.right then
|
|
|
|
return homedecor.stack_sideways(itemstack, placer, pointed_thing, itemstack:get_name(), expand.right, true)
|
|
|
|
elseif expand.forward then
|
|
|
|
return homedecor.stack_sideways(itemstack, placer, pointed_thing, itemstack:get_name(), expand.forward, false)
|
2015-01-23 00:01:08 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
def.after_dig_node = def.after_dig_node or function(pos, oldnode, oldmetadata, digger)
|
2015-01-23 00:08:06 +01:00
|
|
|
if expand.top and expand.forward ~= "air" then
|
2015-01-23 00:01:08 +01:00
|
|
|
local top_pos = { x=pos.x, y=pos.y+1, z=pos.z }
|
2015-09-08 09:24:01 +02:00
|
|
|
local node = minetest.get_node(top_pos).name
|
|
|
|
if node == expand.top or node == placeholder_node then
|
2015-01-23 00:01:08 +01:00
|
|
|
minetest.remove_node(top_pos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local fdir = oldnode.param2
|
|
|
|
if not fdir or fdir > 3 then return end
|
|
|
|
|
2015-01-23 00:08:06 +01:00
|
|
|
if expand.right and expand.forward ~= "air" then
|
2020-08-04 16:12:47 +02:00
|
|
|
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]
|
|
|
|
}
|
2015-09-08 09:24:01 +02:00
|
|
|
local node = minetest.get_node(right_pos).name
|
|
|
|
if node == expand.right or node == placeholder_node then
|
2015-01-23 00:01:08 +01:00
|
|
|
minetest.remove_node(right_pos)
|
|
|
|
end
|
|
|
|
end
|
2015-01-23 00:08:06 +01:00
|
|
|
if expand.forward and expand.forward ~= "air" then
|
2015-01-23 00:01:08 +01:00
|
|
|
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] }
|
2015-09-08 09:24:01 +02:00
|
|
|
local node = minetest.get_node(forward_pos).name
|
|
|
|
if node == expand.forward or node == placeholder_node then
|
2015-01-23 00:01:08 +01:00
|
|
|
minetest.remove_node(forward_pos)
|
|
|
|
end
|
|
|
|
end
|
2015-01-23 00:48:53 +01:00
|
|
|
|
|
|
|
if after_unexpand then
|
|
|
|
after_unexpand(pos)
|
|
|
|
end
|
2015-01-23 00:01:08 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-03 21:21:14 +02:00
|
|
|
local crafts = def.crafts and table.copy(def.crafts) or {}
|
|
|
|
def.crafts = nil
|
|
|
|
|
2015-01-21 19:19:14 +01:00
|
|
|
-- register the actual minetest node
|
2019-04-20 21:49:36 +02:00
|
|
|
minetest.register_node(":homedecor:" .. name, def)
|
2022-05-03 21:21:14 +02:00
|
|
|
|
|
|
|
for _, cdef in pairs(crafts) do
|
|
|
|
if cdef.recipe then
|
|
|
|
for k, row in pairs(cdef.recipe) do
|
|
|
|
if type(row) == "string" and homedecor.materials[row] then
|
|
|
|
cdef.recipe[k] = homedecor.materials[row]
|
|
|
|
elseif type(row) == "table" then
|
|
|
|
for i, item in pairs(row) do
|
|
|
|
if homedecor.materials[item] then
|
|
|
|
cdef.recipe[k][i] = homedecor.materials[item]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if cdef.type ~= "toolrepair" and not cdef.output then
|
2022-05-14 13:49:02 +02:00
|
|
|
cdef.output = "homedecor:" .. name
|
2022-05-03 21:21:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_craft(cdef)
|
|
|
|
end
|
2015-01-21 19:19:14 +01:00
|
|
|
end
|