mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-12-24 17:50:37 +01:00
Update homedecor with node placeholders
This commit is contained in:
parent
faaa3afb0e
commit
ff7f8e64cd
@ -164,7 +164,7 @@ minetest.register_node("building_blocks:Fireplace", {
|
||||
},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
light_source = LIGHT_MAX,
|
||||
light_source = default.LIGHT_MAX,
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = true,
|
||||
groups = {cracky=2},
|
||||
|
@ -91,7 +91,7 @@ homedecor.register("grandfather_clock", {
|
||||
selection_box = gf_cbox,
|
||||
collision_box = gf_cbox,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
expand = { top="air" },
|
||||
expand = { top="placeholder" },
|
||||
on_rotate = screwdriver.rotate_simple
|
||||
})
|
||||
|
||||
|
@ -448,14 +448,6 @@ function homedecor.flip_door(pos, node, player, name, side, isClosed)
|
||||
local rside = nil
|
||||
local nfdir = nil
|
||||
local ofdir = node.param2 or 0
|
||||
-- //MFF_BEGIN(Mg|09/06/15)
|
||||
local upnode = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name
|
||||
|
||||
if upnode ~= "air" then
|
||||
minetest.add_item(pos, upnode)
|
||||
end
|
||||
-- //MFF_END(Mg|06/09/15)
|
||||
|
||||
if side == "left" then
|
||||
rside = "right"
|
||||
nfdir=ofdir - 1
|
||||
@ -612,21 +604,18 @@ homedecor.register("door_japanese_closed", {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, -0.0625, 0.5, 1.5, 0},
|
||||
},
|
||||
expand = { top = "air" },
|
||||
expand = { top = "placeholder" },
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
minetest.set_node(pos, {name = "homedecor:door_japanese_open", param2 = node.param2})
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node("homedecor:door_japanese_open", {
|
||||
homedecor.register("door_japanese_open", {
|
||||
tiles = {
|
||||
"homedecor_generic_wood_luxury.png",
|
||||
"homedecor_japanese_paper.png"
|
||||
},
|
||||
drawtype = "mesh",
|
||||
mesh = "homedecor_door_japanese_open.obj",
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
groups = { snappy = 3, not_in_creative_inventory = 1 },
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_rotate = screwdriver.disallow,
|
||||
@ -638,6 +627,7 @@ minetest.register_node("homedecor:door_japanese_open", {
|
||||
type = "fixed",
|
||||
fixed = {-1.5, -0.5, -0.0625, -0.5, 1.5, 0},
|
||||
},
|
||||
expand = { top = "placeholder" },
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
minetest.set_node(pos, {name = "homedecor:door_japanese_closed", param2 = node.param2})
|
||||
end,
|
||||
|
@ -94,7 +94,7 @@ homedecor.register("television", {
|
||||
}
|
||||
}
|
||||
},
|
||||
light_source = LIGHT_MAX - 1,
|
||||
light_source = default.LIGHT_MAX - 1,
|
||||
groups = { snappy = 3 },
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
})
|
||||
|
@ -25,6 +25,7 @@ homedecor.register("barbecue", {
|
||||
selection_box = bbq_cbox,
|
||||
collision_box = bbq_cbox,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
-- no need for placeholder it appears
|
||||
expand = { top="air" },
|
||||
})
|
||||
|
||||
@ -52,7 +53,7 @@ homedecor.register("bench_large_1", {
|
||||
description = "Garden Bench (style 1)",
|
||||
inventory_image = "homedecor_bench_large_1_inv.png",
|
||||
groups = { snappy = 3 },
|
||||
expand = { right="air" },
|
||||
expand = { right="placeholder" },
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
selection_box = bl1_sbox,
|
||||
node_box = bl1_cbox,
|
||||
@ -83,7 +84,7 @@ homedecor.register("bench_large_2", {
|
||||
groups = {snappy=3},
|
||||
selection_box = bl2_sbox,
|
||||
node_box = bl2_cbox,
|
||||
expand = { right="air" },
|
||||
expand = { right="placeholder" },
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_rotate = screwdriver.disallow
|
||||
})
|
||||
@ -101,7 +102,7 @@ homedecor.register("deckchair", {
|
||||
tiles = {"homedecor_deckchair.png"},
|
||||
description = "Deck Chair",
|
||||
groups = { snappy = 3 },
|
||||
expand = { forward="air" },
|
||||
expand = { forward="placeholder" },
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
selection_box = dc_cbox,
|
||||
collision_box = dc_cbox,
|
||||
@ -116,7 +117,7 @@ homedecor.register("deckchair_striped_blue", {
|
||||
tiles = {"homedecor_deckchair_striped_blue.png"},
|
||||
description = "Deck Chair",
|
||||
groups = { snappy = 3 },
|
||||
expand = { forward="air" },
|
||||
expand = { forward="placeholder" },
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
selection_box = dc_cbox,
|
||||
collision_box = dc_cbox,
|
||||
@ -135,7 +136,7 @@ homedecor.register("doghouse", {
|
||||
selection_box = homedecor.nodebox.slab_y(1.5),
|
||||
collision_box = homedecor.nodebox.slab_y(1.5),
|
||||
groups = {snappy=3},
|
||||
expand = { top="air" },
|
||||
expand = { top="placeholder" },
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_rotate = screwdriver.rotate_simple
|
||||
})
|
||||
@ -323,7 +324,7 @@ homedecor.register("well", {
|
||||
groups = { snappy = 3 },
|
||||
selection_box = homedecor.nodebox.slab_y(2),
|
||||
collision_box = homedecor.nodebox.slab_y(2),
|
||||
expand = { top="air" },
|
||||
expand = { top="placeholder" },
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
on_rotate = screwdriver.rotate_simple
|
||||
})
|
||||
|
@ -32,7 +32,7 @@ homedecor.register("coat_tree", {
|
||||
description = "Coat tree",
|
||||
groups = {snappy=3},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
expand = { top="air" },
|
||||
expand = { top="placeholder" },
|
||||
walkable = false,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
|
@ -185,7 +185,7 @@ homedecor.register("soda_machine", {
|
||||
groups = {snappy=3},
|
||||
selection_box = svm_cbox,
|
||||
collision_box = svm_cbox,
|
||||
expand = { top="air" },
|
||||
expand = { top="placeholder" },
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_rotate = screwdriver.rotate_simple,
|
||||
on_punch = function(pos, node, puncher, pointed_thing)
|
||||
|
@ -23,36 +23,60 @@ homedecor.fdir_to_fwd = {
|
||||
{ -1, 0 },
|
||||
}
|
||||
|
||||
-- selects which node was pointed at based on it being known, and either clickable or buildable_to
|
||||
local placeholder_node = "homedecor:expansion_placeholder"
|
||||
minetest.register_node(placeholder_node, {
|
||||
description = "Expansion placeholder (you hacker you!)",
|
||||
groups = { not_in_creative_inventory=1 },
|
||||
drawtype = "airlike",
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
selection_box = { type = "fixed", fixed = { 0, 0, 0, 0, 0, 0 } },
|
||||
is_ground_content = false,
|
||||
sunlight_propagates = true,
|
||||
buildable_to = false,
|
||||
})
|
||||
|
||||
--- select which node was pointed at based on it being known, not ignored, buildable_to
|
||||
-- returns nil if no node could be selected
|
||||
local function select_node(pointed_thing)
|
||||
local pos = pointed_thing.under
|
||||
local def = minetest.registered_nodes[minetest.get_node(pos).name]
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
local def = node and minetest.registered_nodes[node.name]
|
||||
|
||||
if not def or (not def.on_rightclick and not def.buildable_to) then
|
||||
if not def or not def.buildable_to then
|
||||
pos = pointed_thing.above
|
||||
def = minetest.registered_nodes[minetest.get_node(pos).name]
|
||||
node = minetest.get_node_or_nil(pos)
|
||||
def = node and minetest.registered_nodes[node.name]
|
||||
end
|
||||
return pos, def
|
||||
return def and pos, def
|
||||
end
|
||||
|
||||
-- abstract function checking if 2 given nodes can and may be build to a place
|
||||
local function is_buildable_to(placer_name, pos, def, pos2)
|
||||
local def = def or minetest.registered_nodes[minetest.get_node(pos).name]
|
||||
local def2 = minetest.registered_nodes[minetest.get_node(pos2).name]
|
||||
|
||||
return def and def.buildable_to and def2 and def2.buildable_to
|
||||
and not minetest.is_protected(pos, placer_name)
|
||||
and not minetest.is_protected(pos2, placer_name)
|
||||
--- check if all nodes can and may be build to
|
||||
local function is_buildable_to(placer_name, ...)
|
||||
for _, pos in ipairs({...}) do
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
local def = node and minetest.registered_nodes[node.name]
|
||||
if not (def and def.buildable_to) or minetest.is_protected(pos, placer_name) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
-- place one or two nodes if and only if both can be placed
|
||||
local function stack(itemstack, placer, fdir, pos, def, pos2, node1, node2)
|
||||
local placer_name = placer:get_player_name() or ""
|
||||
if is_buildable_to(placer_name, pos, def, pos2) then
|
||||
if is_buildable_to(placer_name, pos, pos2) then
|
||||
local fdir = fdir or minetest.dir_to_facedir(placer:get_look_dir())
|
||||
minetest.set_node(pos, { name = node1, param2 = fdir })
|
||||
node2 = node2 or "air" -- this can be used to clear buildable_to nodes even though we are using a multinode mesh
|
||||
minetest.set_node(pos2, { name = node2, param2 = (node2 ~= "air" and fdir) or nil })
|
||||
-- do not assume by default, as we still might want to allow overlapping in some cases
|
||||
local has_facedir = node2 ~= "air"
|
||||
if node2 == "placeholder" then
|
||||
has_facedir = false
|
||||
node2 = placeholder_node
|
||||
end
|
||||
minetest.set_node(pos2, { name = node2, param2 = (has_facedir and fdir) or nil })
|
||||
|
||||
-- call after_place_node of the placed node if available
|
||||
local ctrl_node_def = minetest.registered_nodes[node1]
|
||||
@ -62,20 +86,27 @@ local function stack(itemstack, placer, fdir, pos, def, pos2, node1, node2)
|
||||
|
||||
if not homedecor.expect_infinite_stacks then
|
||||
itemstack:take_item()
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local function rightclick_pointed_thing(pos, placer, itemstack)
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
if not node then return false end
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
if not def or not def.on_rightclick then return false end
|
||||
return def.on_rightclick(pos, node, placer, itemstack) or itemstack
|
||||
end
|
||||
|
||||
-- Stack one node above another
|
||||
-- leave the last argument nil if it's one 2m high node
|
||||
function homedecor.stack_vertically(itemstack, placer, pointed_thing, node1, node2)
|
||||
local pos, def = select_node(pointed_thing)
|
||||
if not def then return end -- rare corner case, but happened in #205
|
||||
local rightclick_result = rightclick_pointed_thing(pointed_thing.under, placer, itemstack)
|
||||
if rightclick_result then return rightclick_result end
|
||||
|
||||
if def.on_rightclick then
|
||||
return def.on_rightclick(pointed_thing.under, minetest.get_node(pos), placer, itemstack)
|
||||
end
|
||||
local pos, def = select_node(pointed_thing)
|
||||
if not pos then return itemstack end
|
||||
|
||||
local top_pos = { x=pos.x, y=pos.y+1, z=pos.z }
|
||||
|
||||
@ -86,12 +117,11 @@ end
|
||||
-- like homedecor.stack_vertically but tests first if it was placed as a right wing, then uses node1_right and node2_right instead
|
||||
|
||||
function homedecor.stack_wing(itemstack, placer, pointed_thing, node1, node2, node1_right, node2_right)
|
||||
local pos, def = select_node(pointed_thing)
|
||||
if not def then return end -- rare corner case, but happened in #205
|
||||
local rightclick_result = rightclick_pointed_thing(pointed_thing.under, placer, itemstack)
|
||||
if rightclick_result then return rightclick_result end
|
||||
|
||||
if def.on_rightclick then
|
||||
return def.on_rightclick(pointed_thing.under, minetest.get_node(pos), placer, itemstack)
|
||||
end
|
||||
local pos, def = select_node(pointed_thing)
|
||||
if not pos then return itemstack end
|
||||
|
||||
local forceright = placer:get_player_control()["sneak"]
|
||||
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
|
||||
@ -106,12 +136,11 @@ function homedecor.stack_wing(itemstack, placer, pointed_thing, node1, node2, no
|
||||
end
|
||||
|
||||
function homedecor.stack_sideways(itemstack, placer, pointed_thing, node1, node2, dir)
|
||||
local pos, def = select_node(pointed_thing)
|
||||
if not def then return end -- rare corner case, but happened in #205
|
||||
local rightclick_result = rightclick_pointed_thing(pointed_thing.under, placer, itemstack)
|
||||
if rightclick_result then return rightclick_result end
|
||||
|
||||
if def.on_rightclick then
|
||||
return def.on_rightclick(pointed_thing.under, minetest.get_node(pos), placer, itemstack)
|
||||
end
|
||||
local pos, def = select_node(pointed_thing)
|
||||
if not pos then return itemstack end
|
||||
|
||||
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
|
||||
local fdir_transform = dir and homedecor.fdir_to_right or homedecor.fdir_to_fwd
|
||||
@ -196,11 +225,11 @@ function homedecor.unextend_bed(pos, color)
|
||||
end
|
||||
|
||||
function homedecor.place_banister(itemstack, placer, pointed_thing)
|
||||
local pos, def = select_node(pointed_thing)
|
||||
local rightclick_result = rightclick_pointed_thing(pointed_thing.under, placer, itemstack)
|
||||
if rightclick_result then return rightclick_result end
|
||||
|
||||
if def.on_rightclick then
|
||||
return def.on_rightclick(pointed_thing.under, minetest.get_node(pos), placer, itemstack)
|
||||
end
|
||||
local pos, def = select_node(pointed_thing)
|
||||
if not pos then return itemstack end
|
||||
|
||||
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
|
||||
|
||||
@ -212,12 +241,12 @@ function homedecor.place_banister(itemstack, placer, pointed_thing)
|
||||
|
||||
if not (adef and adef.buildable_to) then
|
||||
minetest.chat_send_player(placer_name, "Not enough room - the upper space is occupied!" )
|
||||
return
|
||||
return itemstack
|
||||
end
|
||||
|
||||
if minetest.is_protected(abovepos, placer_name) then
|
||||
minetest.chat_send_player(placer_name, "Someone already owns that spot." )
|
||||
return
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local lxd = homedecor.fdir_to_left[fdir+1][1]
|
||||
@ -259,12 +288,12 @@ function homedecor.place_banister(itemstack, placer, pointed_thing)
|
||||
-- try to place a diagonal one on the side of blocks stacked like stairs
|
||||
-- or follow an existing diagonal with another.
|
||||
if (left_below_node and string.find(left_below_node.name, "banister_.-_diagonal_right")
|
||||
and below_node and is_buildable_to(placer_name, below_pos, nil, below_pos))
|
||||
or not is_buildable_to(placer_name, right_fwd_above_pos, nil, right_fwd_above_pos) then
|
||||
and below_node and is_buildable_to(placer_name, below_pos, below_pos))
|
||||
or not is_buildable_to(placer_name, right_fwd_above_pos, right_fwd_above_pos) then
|
||||
new_place_name = string.gsub(new_place_name, "_horizontal", "_diagonal_right")
|
||||
elseif (right_below_node and string.find(right_below_node.name, "banister_.-_diagonal_left")
|
||||
and below_node and is_buildable_to(placer_name, below_pos, nil, below_pos))
|
||||
or not is_buildable_to(placer_name, left_fwd_above_pos, nil, left_fwd_above_pos) then
|
||||
and below_node and is_buildable_to(placer_name, below_pos, below_pos))
|
||||
or not is_buildable_to(placer_name, left_fwd_above_pos, left_fwd_above_pos) then
|
||||
new_place_name = string.gsub(new_place_name, "_horizontal", "_diagonal_left")
|
||||
|
||||
-- try to follow a diagonal with the corresponding horizontal
|
||||
@ -278,12 +307,12 @@ function homedecor.place_banister(itemstack, placer, pointed_thing)
|
||||
|
||||
-- try to place a horizontal in-line with the nearest diagonal, at the top
|
||||
elseif left_fwd_below_node and string.find(left_fwd_below_node.name, "homedecor:banister_.*_diagonal")
|
||||
and is_buildable_to(placer_name, fwd_pos, nil, fwd_pos) then
|
||||
and is_buildable_to(placer_name, fwd_pos, fwd_pos) then
|
||||
fdir = left_fwd_below_node.param2
|
||||
pos = fwd_pos
|
||||
new_place_name = string.gsub(left_fwd_below_node.name, "_diagonal_.-$", "_horizontal")
|
||||
elseif right_fwd_below_node and string.find(right_fwd_below_node.name, "homedecor:banister_.*_diagonal")
|
||||
and is_buildable_to(placer_name, fwd_pos, nil, fwd_pos) then
|
||||
and is_buildable_to(placer_name, fwd_pos, fwd_pos) then
|
||||
fdir = right_fwd_below_node.param2
|
||||
pos = fwd_pos
|
||||
new_place_name = string.gsub(right_fwd_below_node.name, "_diagonal_.-$", "_horizontal")
|
||||
@ -298,12 +327,12 @@ function homedecor.place_banister(itemstack, placer, pointed_thing)
|
||||
|
||||
-- try to place a horizontal in-line with the nearest diagonal, at the bottom
|
||||
elseif left_fwd_node and string.find(left_fwd_node.name, "homedecor:banister_.*_diagonal")
|
||||
and is_buildable_to(placer_name, fwd_pos, nil, fwd_pos) then
|
||||
and is_buildable_to(placer_name, fwd_pos, fwd_pos) then
|
||||
fdir = left_fwd_node.param2
|
||||
pos = fwd_pos
|
||||
new_place_name = string.gsub(left_fwd_node.name, "_diagonal_.-$", "_horizontal")
|
||||
elseif right_fwd_node and string.find(right_fwd_node.name, "homedecor:banister_.*_diagonal")
|
||||
and is_buildable_to(placer_name, fwd_pos, nil, fwd_pos) then
|
||||
and is_buildable_to(placer_name, fwd_pos, fwd_pos) then
|
||||
fdir = right_fwd_node.param2
|
||||
pos = fwd_pos
|
||||
new_place_name = string.gsub(right_fwd_node.name, "_diagonal_.-$", "_horizontal")
|
||||
|
173
mods/homedecor_modpack/homedecor/handlers/inventory.lua
Normal file
173
mods/homedecor_modpack/homedecor/handlers/inventory.lua
Normal file
@ -0,0 +1,173 @@
|
||||
local S = homedecor.gettext
|
||||
|
||||
local default_can_dig = function(pos,player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
return meta:get_inventory():is_empty("main")
|
||||
end
|
||||
|
||||
local background = default.gui_bg .. default.gui_bg_img .. default.gui_slots
|
||||
local default_inventory_formspecs = {
|
||||
["4"]="size[8,6]".. background ..
|
||||
"list[context;main;2,0;4,1;]"..
|
||||
"list[current_player;main;0,2;8,4;]",
|
||||
|
||||
["6"]="size[8,6]".. background ..
|
||||
"list[context;main;1,0;6,1;]"..
|
||||
"list[current_player;main;0,2;8,4;]",
|
||||
|
||||
["8"]="size[8,6]".. background ..
|
||||
"list[context;main;0,0;8,1;]"..
|
||||
"list[current_player;main;0,2;8,4;]",
|
||||
|
||||
["12"]="size[8,7]".. background ..
|
||||
"list[context;main;1,0;6,2;]"..
|
||||
"list[current_player;main;0,3;8,4;]",
|
||||
|
||||
["16"]="size[8,7]".. background ..
|
||||
"list[context;main;0,0;8,2;]"..
|
||||
"list[current_player;main;0,3;8,4;]",
|
||||
|
||||
["24"]="size[8,8]".. background ..
|
||||
"list[context;main;0,0;8,3;]"..
|
||||
"list[current_player;main;0,4;8,4;]",
|
||||
|
||||
["32"]="size[8,9]".. background ..
|
||||
"list[context;main;0,0.3;8,4;]"..
|
||||
"list[current_player;main;0,4.85;8,1;]"..
|
||||
"list[current_player;main;0,6.08;8,3;8]"..
|
||||
default.get_hotbar_bg(0,4.85),
|
||||
|
||||
["50"]="size[10,10]".. background ..
|
||||
"list[context;main;0,0;10,5;]"..
|
||||
"list[current_player;main;1,6;8,4;]",
|
||||
}
|
||||
|
||||
local function get_formspec_by_size(size)
|
||||
--TODO heuristic to use the "next best size"
|
||||
local formspec = default_inventory_formspecs[tostring(size)]
|
||||
return formspec or default_inventory_formspecs
|
||||
end
|
||||
|
||||
----
|
||||
-- handle inventory setting
|
||||
-- inventory = {
|
||||
-- size = 16,
|
||||
-- formspec = …,
|
||||
-- locked = false,
|
||||
-- lockable = true,
|
||||
-- }
|
||||
--
|
||||
function homedecor.handle_inventory(name, def, original_def)
|
||||
local inventory = def.inventory
|
||||
if not inventory then return end
|
||||
def.inventory = nil
|
||||
|
||||
if inventory.size then
|
||||
local on_construct = def.on_construct
|
||||
def.on_construct = function(pos)
|
||||
local size = inventory.size
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:get_inventory():set_size("main", size)
|
||||
meta:set_string("formspec", inventory.formspec or get_formspec_by_size(size))
|
||||
if on_construct then on_construct(pos) end
|
||||
end
|
||||
end
|
||||
|
||||
def.can_dig = def.can_dig or default_can_dig
|
||||
def.on_metadata_inventory_move = def.on_metadata_inventory_move or function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
minetest.log("action", S("%s moves stuff in %s at %s"):format(
|
||||
player:get_player_name(), name, minetest.pos_to_string(pos)
|
||||
))
|
||||
end
|
||||
def.on_metadata_inventory_put = def.on_metadata_inventory_put or function(pos, listname, index, stack, player)
|
||||
minetest.log("action", S("%s moves stuff to %s at %s"):format(
|
||||
player:get_player_name(), name, minetest.pos_to_string(pos)
|
||||
))
|
||||
end
|
||||
def.on_metadata_inventory_take = def.on_metadata_inventory_take or function(pos, listname, index, stack, player)
|
||||
minetest.log("action", S("%s takes stuff from %s at %s"):format(
|
||||
player:get_player_name(), name, minetest.pos_to_string(pos)
|
||||
))
|
||||
end
|
||||
|
||||
local locked = inventory.locked
|
||||
if locked then
|
||||
local after_place_node = def.after_place_node
|
||||
def.after_place_node = function(pos, placer)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local owner = placer:get_player_name() or ""
|
||||
|
||||
meta:set_string("owner", owner)
|
||||
meta:set_string("infotext", S("%s (owned by %s)"):format(def.infotext or def.description, owner))
|
||||
return after_place_node and after_place_node(pos, placer)
|
||||
end
|
||||
|
||||
local allow_move = def.allow_metadata_inventory_move
|
||||
def.allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local owner = meta:get_string("owner")
|
||||
local playername = player:get_player_name()
|
||||
|
||||
if (playername ~= owner) then
|
||||
minetest.log("action", string.format("%s tried to access a %s belonging to %s at %s",
|
||||
playername, name, owner, minetest.pos_to_string(pos)
|
||||
))
|
||||
return 0
|
||||
end
|
||||
|
||||
return allow_move and allow_move(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
or count
|
||||
end
|
||||
|
||||
local allow_put = def.allow_metadata_inventory_put
|
||||
def.allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local owner = meta:get_string("owner")
|
||||
local playername = player:get_player_name()
|
||||
|
||||
if (playername ~= owner) then
|
||||
minetest.log("action", string.format("%s tried to access a %s belonging to %s at %s",
|
||||
playername, name, owner, minetest.pos_to_string(pos)
|
||||
))
|
||||
return 0
|
||||
end
|
||||
return allow_put and allow_put(pos, listname, index, stack, player)
|
||||
or stack:get_count()
|
||||
end
|
||||
|
||||
local allow_take = def.allow_metadata_inventory_take
|
||||
def.allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local owner = meta:get_string("owner")
|
||||
local playername = player:get_player_name()
|
||||
|
||||
if (playername ~= owner) then
|
||||
minetest.log("action", string.format("%s tried to access a %s belonging to %s at %s",
|
||||
playername, name, owner, minetest.pos_to_string(pos)
|
||||
))
|
||||
return 0
|
||||
end
|
||||
return allow_take and allow_take(pos, listname, index, stack, player)
|
||||
or stack:get_count()
|
||||
end
|
||||
end
|
||||
|
||||
local lockable = inventory.lockable
|
||||
if lockable then
|
||||
local locked_def = table.copy(original_def)
|
||||
locked_def.description = S("Locked %s"):format(def.description or name)
|
||||
|
||||
local locked_inventory = locked_def.inventory
|
||||
locked_inventory.locked = true
|
||||
locked_inventory.lockable = nil -- avoid loops of locked locked stuff
|
||||
|
||||
local locked_name = name .. "_locked"
|
||||
homedecor.register(locked_name, locked_def)
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "homedecor:" .. locked_name,
|
||||
recipe = { "homedecor:" .. name, "default:steel_ingot" }
|
||||
})
|
||||
end
|
||||
|
||||
end
|
@ -1,5 +1,6 @@
|
||||
homedecor = homedecor or {}
|
||||
local S = homedecor.gettext
|
||||
local placeholder_node = "homedecor:expansion_placeholder"
|
||||
|
||||
--wrapper around minetest.register_node that sets sane defaults and interprets some specialized settings
|
||||
function homedecor.register(name, original_def)
|
||||
@ -41,6 +42,12 @@ function homedecor.register(name, original_def)
|
||||
def.after_unexpand = nil
|
||||
|
||||
if expand then
|
||||
-- dissallow rotating only half the expanded node by default
|
||||
-- unless we know better
|
||||
def.on_rotate = def.on_rotate
|
||||
or (def.mesh and expand.top and screwdriver.rotate_simple)
|
||||
or screwdriver.disallow
|
||||
|
||||
def.on_place = def.on_place or function(itemstack, placer, pointed_thing)
|
||||
if expand.top then
|
||||
return homedecor.stack_vertically(itemstack, placer, pointed_thing, itemstack:get_name(), expand.top)
|
||||
@ -53,7 +60,8 @@ function homedecor.register(name, original_def)
|
||||
def.after_dig_node = def.after_dig_node or function(pos, oldnode, oldmetadata, digger)
|
||||
if expand.top and expand.forward ~= "air" then
|
||||
local top_pos = { x=pos.x, y=pos.y+1, z=pos.z }
|
||||
if minetest.get_node(top_pos).name == expand.top then
|
||||
local node = minetest.get_node(top_pos).name
|
||||
if node == expand.top or node == placeholder_node then
|
||||
minetest.remove_node(top_pos)
|
||||
end
|
||||
end
|
||||
@ -63,13 +71,15 @@ function homedecor.register(name, original_def)
|
||||
|
||||
if expand.right and expand.forward ~= "air" 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
|
||||
local node = minetest.get_node(right_pos).name
|
||||
if node == expand.right or node == placeholder_node then
|
||||
minetest.remove_node(right_pos)
|
||||
end
|
||||
end
|
||||
if expand.forward and expand.forward ~= "air" 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
|
||||
local node = minetest.get_node(forward_pos).name
|
||||
if node == expand.forward or node == placeholder_node then
|
||||
minetest.remove_node(forward_pos)
|
||||
end
|
||||
end
|
||||
|
@ -12,7 +12,7 @@ homedecor.register("refrigerator_steel", {
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
selection_box = homedecor.nodebox.slab_y(2),
|
||||
collision_box = homedecor.nodebox.slab_y(2),
|
||||
expand = { top="air" },
|
||||
expand = { top="placeholder" },
|
||||
infotext=S("Refrigerator"),
|
||||
inventory = {
|
||||
size=50,
|
||||
@ -31,7 +31,7 @@ homedecor.register("refrigerator_white", {
|
||||
selection_box = homedecor.nodebox.slab_y(2),
|
||||
collision_box = homedecor.nodebox.slab_y(2),
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
expand = { top="air" },
|
||||
expand = { top="placeholder" },
|
||||
infotext=S("Refrigerator"),
|
||||
inventory = {
|
||||
size=50,
|
||||
|
@ -54,7 +54,7 @@ homedecor.register("ironing_board", {
|
||||
"wool_grey.png",
|
||||
"homedecor_generic_metal_black.png^[brighten"
|
||||
},
|
||||
expand = {right = "air"},
|
||||
expand = {right = "placeholder"},
|
||||
groups = { snappy = 3 },
|
||||
selection_box = ib_cbox,
|
||||
collision_box = ib_cbox
|
||||
|
@ -477,7 +477,7 @@ local function reg_lamp(suffix, nxt, tilesuffix, light, color)
|
||||
node.name = "homedecor:standing_lamp"..lampcolor.."_"..repl[suffix]
|
||||
minetest.set_node(pos, node)
|
||||
end,
|
||||
expand = { top="air" },
|
||||
expand = { top="placeholder" },
|
||||
})
|
||||
|
||||
minetest.register_alias("homedecor:standing_lamp_bottom"..lampcolor.."_"..suffix, "homedecor:standing_lamp"..lampcolor.."_"..suffix)
|
||||
|
@ -273,7 +273,7 @@ homedecor.register("pool_table", {
|
||||
groups = {snappy=3},
|
||||
selection_box = pooltable_cbox,
|
||||
collision_box = pooltable_cbox,
|
||||
expand = { forward="air" },
|
||||
expand = { forward="placeholder" },
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_rotate = screwdriver.disallow
|
||||
})
|
||||
@ -297,7 +297,7 @@ homedecor.register("piano", {
|
||||
groups = { snappy = 3 },
|
||||
selection_box = piano_cbox,
|
||||
collision_box = piano_cbox,
|
||||
expand = { right="air" },
|
||||
expand = { right="placeholder" },
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_rotate = screwdriver.disallow
|
||||
})
|
||||
@ -377,7 +377,7 @@ homedecor.register("tool_cabinet", {
|
||||
on_rotate = screwdriver.rotate_simple,
|
||||
groups = { snappy=3 },
|
||||
selection_box = homedecor.nodebox.slab_y(2),
|
||||
expand = { top="air" },
|
||||
expand = { top="placeholder" },
|
||||
inventory = {
|
||||
size=24,
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ homedecor.register("desk", {
|
||||
collision_box = desk_cbox,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
groups = { snappy = 3 },
|
||||
expand = { right="air" },
|
||||
expand = { right="placeholder" },
|
||||
inventory = {
|
||||
size=24,
|
||||
lockable=true,
|
||||
@ -112,7 +112,7 @@ for _, c in pairs({"basic", "upscale"}) do
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
selection_box = ofchairs_sbox,
|
||||
collision_box = ofchairs_cbox,
|
||||
expand = { top = "air" },
|
||||
expand = { top = "placeholder" },
|
||||
on_rotate = screwdriver.rotate_simple
|
||||
})
|
||||
end
|
||||
|
@ -18,7 +18,7 @@ homedecor.register("wardrobe", {
|
||||
selection_box = wd_cbox,
|
||||
collision_box = wd_cbox,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
expand = { top="air" },
|
||||
expand = { top="placeholder" },
|
||||
on_rotate = screwdriver.rotate_simple,
|
||||
infotext = "Wardrobe",
|
||||
inventory = {
|
||||
|
Loading…
Reference in New Issue
Block a user