forked from nalc/homedecor_modpack
add an after_unexpand hook to allow beds to properly expand and unexpand, and update beds to use expansion in the process
This commit is contained in:
parent
e9bfc337d4
commit
306a6798b3
@ -198,7 +198,7 @@ end
|
|||||||
|
|
||||||
for _, color in ipairs(bedcolors) do
|
for _, color in ipairs(bedcolors) do
|
||||||
|
|
||||||
minetest.register_node("homedecor:bed_"..color.."_head", {
|
homedecor.register("bed_"..color.."_head", {
|
||||||
tiles = {
|
tiles = {
|
||||||
"homedecor_bed_"..color.."_top1.png",
|
"homedecor_bed_"..color.."_top1.png",
|
||||||
"homedecor_bed_bottom1.png",
|
"homedecor_bed_bottom1.png",
|
||||||
@ -207,9 +207,6 @@ for _, color in ipairs(bedcolors) do
|
|||||||
"homedecor_bed_head1.png",
|
"homedecor_bed_head1.png",
|
||||||
"homedecor_bed_"..color.."_head2.png"
|
"homedecor_bed_"..color.."_head2.png"
|
||||||
},
|
},
|
||||||
drawtype = "nodebox",
|
|
||||||
paramtype = "light",
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
groups = {snappy=3, not_in_creative_inventory=1},
|
groups = {snappy=3, not_in_creative_inventory=1},
|
||||||
node_box = {
|
node_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
@ -230,7 +227,7 @@ for _, color in ipairs(bedcolors) do
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("homedecor:bed_"..color.."_foot", {
|
homedecor.register("bed_"..color.."_foot", {
|
||||||
tiles = {
|
tiles = {
|
||||||
"homedecor_bed_"..color.."_top2.png",
|
"homedecor_bed_"..color.."_top2.png",
|
||||||
"homedecor_bed_bottom2.png",
|
"homedecor_bed_bottom2.png",
|
||||||
@ -241,9 +238,6 @@ for _, color in ipairs(bedcolors) do
|
|||||||
},
|
},
|
||||||
inventory_image = "homedecor_bed_"..color.."_inv.png",
|
inventory_image = "homedecor_bed_"..color.."_inv.png",
|
||||||
description = S("Bed (%s)"):format(color),
|
description = S("Bed (%s)"):format(color),
|
||||||
drawtype = "nodebox",
|
|
||||||
paramtype = "light",
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
groups = {snappy=3},
|
groups = {snappy=3},
|
||||||
node_box = {
|
node_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
@ -262,24 +256,13 @@ for _, color in ipairs(bedcolors) do
|
|||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
bed_extension(pos, color)
|
bed_extension(pos, color)
|
||||||
end,
|
end,
|
||||||
|
expand = { forward = "homedecor:bed_"..color.."_head" },
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
after_unexpand = function(pos)
|
||||||
return homedecor.stack_sideways(itemstack, placer, pointed_thing,
|
|
||||||
"homedecor:bed_"..color.."_foot", "homedecor:bed_"..color.."_head", false)
|
|
||||||
end,
|
|
||||||
|
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|
||||||
local fdir = oldnode.param2
|
|
||||||
if not fdir or fdir > 3 then return end
|
|
||||||
local pos2 = { 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(pos2).name == "homedecor:bed_"..color.."_head" then
|
|
||||||
minetest.remove_node(pos2)
|
|
||||||
end
|
|
||||||
unextend_bed(pos, color)
|
unextend_bed(pos, color)
|
||||||
end
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("homedecor:bed_"..color.."_footext", {
|
homedecor.register("bed_"..color.."_footext", {
|
||||||
tiles = {
|
tiles = {
|
||||||
"homedecor_bed_"..color.."_top2.png",
|
"homedecor_bed_"..color.."_top2.png",
|
||||||
"homedecor_bed_bottom2.png",
|
"homedecor_bed_bottom2.png",
|
||||||
@ -288,9 +271,6 @@ for _, color in ipairs(bedcolors) do
|
|||||||
"homedecor_bed_foot2ext.png",
|
"homedecor_bed_foot2ext.png",
|
||||||
"homedecor_bed_"..color.."_foot1ext.png"
|
"homedecor_bed_"..color.."_foot1ext.png"
|
||||||
},
|
},
|
||||||
drawtype = "nodebox",
|
|
||||||
paramtype = "light",
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
groups = {snappy=3, not_in_creative_inventory=1},
|
groups = {snappy=3, not_in_creative_inventory=1},
|
||||||
node_box = {
|
node_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
@ -306,13 +286,8 @@ for _, color in ipairs(bedcolors) do
|
|||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 1.5 }
|
fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 1.5 }
|
||||||
},
|
},
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
expand = { forward = "homedecor:bed_"..color.."_head" },
|
||||||
local fdir = oldnode.param2
|
after_unexpand = function(pos)
|
||||||
if not fdir or fdir > 3 then return end
|
|
||||||
local pos2 = { 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(pos2).name == "homedecor:bed_"..color.."_head" then
|
|
||||||
minetest.remove_node(pos2)
|
|
||||||
end
|
|
||||||
unextend_bed(pos, color)
|
unextend_bed(pos, color)
|
||||||
end,
|
end,
|
||||||
drop = "homedecor:bed_"..color.."_foot"
|
drop = "homedecor:bed_"..color.."_foot"
|
||||||
|
@ -79,6 +79,8 @@ function homedecor.register(name, def)
|
|||||||
|
|
||||||
local expand = def.expand
|
local expand = def.expand
|
||||||
def.expand = nil
|
def.expand = nil
|
||||||
|
local after_unexpand = def.after_unexpand
|
||||||
|
def.after_unexpand = nil
|
||||||
|
|
||||||
if expand then
|
if expand then
|
||||||
def.on_place = def.on_place or function(itemstack, placer, pointed_thing)
|
def.on_place = def.on_place or function(itemstack, placer, pointed_thing)
|
||||||
@ -115,6 +117,10 @@ function homedecor.register(name, def)
|
|||||||
minetest.remove_node(forward_pos)
|
minetest.remove_node(forward_pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if after_unexpand then
|
||||||
|
after_unexpand(pos)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user