Add wooden jewelry box.
parent
90402b5ed3
commit
3930349168
|
@ -1,40 +1,46 @@
|
|||
-- TODO
|
||||
INVENTORY_W = 8
|
||||
INVENTORY_H = 4
|
||||
CHEST_W = 8
|
||||
CHEST_H = 4
|
||||
BIN_W = 6
|
||||
BIN_H = 3
|
||||
Y_OFFSET = 0.2
|
||||
INV_MARGIN = 0.72
|
||||
HOTBAR_MARGIN = 0.23
|
||||
|
||||
containers = {
|
||||
["containers:chest"] = { w = 8, h = 4 },
|
||||
["containers:chest_locked"] = { w = 8, h = 4 },
|
||||
["containers:wood_bin"] = { w = 6, h = 3 },
|
||||
["containers:wood_bin_locked"] = { w = 6, h = 3 },
|
||||
["containers:wood_jbox"] = { w = 4, h = 2 },
|
||||
["containers:wood_jbox_locked"] = { w = 4, h = 2 },
|
||||
y_offset = 0.2,
|
||||
inventory_margin = 0.72,
|
||||
hotbar_margin = 0.23,
|
||||
}
|
||||
|
||||
--{{{ Functions
|
||||
|
||||
local function get_container_formspec(pos, name)
|
||||
-- Prepare coord of metadata
|
||||
local spos = pos.x .. "," .. pos.y .. "," ..pos.z
|
||||
|
||||
local w,h = 0,0
|
||||
if name == "containers:chest" then
|
||||
w = CHEST_W
|
||||
h = CHEST_H
|
||||
elseif name == "containers:wood_bin" then
|
||||
w = BIN_W
|
||||
h = BIN_H
|
||||
end
|
||||
-- Add aliases for container inventory width and height
|
||||
local w,h = containers[name].w, containers[name].h
|
||||
|
||||
-- Get label for container inventory
|
||||
local label = minetest.registered_nodes[name].description
|
||||
|
||||
-- Calculate formspec width and height
|
||||
local form_w = math.max(INVENTORY_W, w)
|
||||
local form_h = INVENTORY_H + h + 1
|
||||
|
||||
-- Calculate offset for container inventory
|
||||
local x_offset = (INVENTORY_W - w)/2
|
||||
local y_offset = Y_OFFSET
|
||||
local y_offset = containers.y_offset
|
||||
|
||||
local inv_y = h + y_offset + INV_MARGIN
|
||||
-- Calculate player inventory position,
|
||||
-- player hotbar position and "Inventory" label position
|
||||
local inv_y = h + y_offset + containers.inventory_margin
|
||||
local label_y = inv_y - y_offset - 0.4
|
||||
local hb_y = inv_y + INVENTORY_H - 1 + HOTBAR_MARGIN
|
||||
local hb_y = inv_y + INVENTORY_H - 1 + containers.hotbar_margin
|
||||
|
||||
-- Construct formspec string
|
||||
local formspec =
|
||||
"size["..form_w..","..form_h.."]"..
|
||||
"label[0,-0.4;"..label.."]"..
|
||||
|
@ -54,16 +60,20 @@ local function get_container_formspec(pos, name)
|
|||
"0,"..hb_y..";"..
|
||||
INVENTORY_W..",1;24]"..
|
||||
default.get_hotbar_bg(0,hb_y)
|
||||
--local formspec =
|
||||
-- "size[8,"..h.."]"..
|
||||
-- default.gui_bg..
|
||||
-- default.gui_bg_img..
|
||||
-- default.gui_slots..
|
||||
-- "list[nodemeta:".. spos .. ";main;0,0.3;8,4;]"..
|
||||
-- "list[current_player;main;0,4.85;8,3;]"..
|
||||
-- "list[current_player;main;0,8.08;8,1;24]"..
|
||||
-- default.get_hotbar_bg(0,4.85)
|
||||
return formspec
|
||||
return formspec
|
||||
end
|
||||
|
||||
local function construct_container(pos)
|
||||
-- Get node name
|
||||
local name = minetest.get_node(pos).name
|
||||
|
||||
-- Set node infotext equal to it's description (name)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("infotext", minetest.registered_nodes[name].description)
|
||||
|
||||
-- Set node inventory size
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", containers[name].w * containers[name].h)
|
||||
end
|
||||
|
||||
local function handle_unlocked_container(pos, node, clicker, wield_item)
|
||||
|
@ -114,7 +124,7 @@ local function handle_locked_container(pos, node, clicker, wield_item)
|
|||
minetest.show_formspec(
|
||||
clicker:get_player_name(),
|
||||
node.name,
|
||||
get_chest_formspec(pos)
|
||||
get_container_formspec(pos, node.name)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
@ -174,12 +184,7 @@ minetest.register_node("containers:chest", {
|
|||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "",
|
||||
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("infotext", "Chest")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", CHEST_W * CHEST_H)
|
||||
end,
|
||||
on_construct = construct_container,
|
||||
after_dig_node = dig_container,
|
||||
on_rightclick = handle_unlocked_container,
|
||||
--{{{ Logging
|
||||
|
@ -213,12 +218,7 @@ minetest.register_node("containers:chest_locked", {
|
|||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "",
|
||||
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("infotext", "Locked chest")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", CHEST_W * CHEST_H)
|
||||
end,
|
||||
on_construct = construct_container,
|
||||
after_place_node = place_locked_container,
|
||||
after_dig_node = dig_container,
|
||||
on_rightclick = handle_locked_container,
|
||||
|
@ -250,12 +250,7 @@ minetest.register_node("containers:wood_bin", {
|
|||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "",
|
||||
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("infotext", "Chest")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", BIN_W * BIN_H)
|
||||
end,
|
||||
on_construct = construct_container,
|
||||
after_dig_node = dig_container,
|
||||
on_rightclick = handle_unlocked_container,
|
||||
--{{{ Logging
|
||||
|
@ -273,56 +268,158 @@ minetest.register_node("containers:wood_bin", {
|
|||
end,
|
||||
--}}}
|
||||
})
|
||||
--}}}
|
||||
|
||||
--{{{ Wooden barrow
|
||||
minetest.register_node("containers:barrow", {
|
||||
description = "Wooden barrow",
|
||||
tiles = {
|
||||
"default_chest_top.png", "default_chest_top.png",
|
||||
"default_chest_side.png", "default_chest_side.png",
|
||||
"default_chest_side.png", "default_chest_front.png"
|
||||
},
|
||||
minetest.register_node("containers:wood_bin_locked", {
|
||||
description = "Locked wooden bin",
|
||||
tiles = {"containers_wood_bin.png"},
|
||||
groups = {choppy=2,oddly_breakable_by_hand=2},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
-- Chest formspec
|
||||
meta:set_string("formspec",
|
||||
"size[8,9]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
[[
|
||||
list[current_name;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)
|
||||
)
|
||||
meta:set_string("infotext", "Barrow")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", 8*4)
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("main")
|
||||
end,
|
||||
drop = "",
|
||||
|
||||
on_construct = construct_container,
|
||||
after_place_node = place_locked_container,
|
||||
after_dig_node = dig_container,
|
||||
on_rightclick = handle_locked_container,
|
||||
--{{{ Logging
|
||||
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" moves stuff in barrow at "..minetest.pos_to_string(pos))
|
||||
" moves stuff in bin at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" moves stuff to barrow at "..minetest.pos_to_string(pos))
|
||||
" moves stuff to bin at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" takes stuff from barrow at "..minetest.pos_to_string(pos))
|
||||
" takes stuff from bin at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
--}}}
|
||||
})
|
||||
--}}}
|
||||
|
||||
--{{{ Wooden jewelry box
|
||||
minetest.register_node("containers:wood_jbox", {
|
||||
description = "Wooden jewelry box",
|
||||
--{{{ Tiles
|
||||
tiles = {
|
||||
"default_wood.png^containers_wood_jbox_top.png",
|
||||
"default_wood.png^containers_wood_jbox_top.png",
|
||||
"default_wood.png^containers_wood_jbox_side2.png",
|
||||
"default_wood.png^containers_wood_jbox_side.png",
|
||||
"default_wood.png^containers_wood_jbox_back.png",
|
||||
"default_wood.png^containers_wood_jbox_front.png"
|
||||
},
|
||||
--}}}
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
drawtype = "nodebox",
|
||||
--{{{ Node box
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
-- "legs"
|
||||
{-6/16, -8/16, -1/16, -4/16, -7/16, -3/16},
|
||||
{-6/16, -8/16, 2/16, -4/16, -7/16, 4/16},
|
||||
{4/16, -8/16, -1/16, 6/16, -7/16, -3/16},
|
||||
{4/16, -8/16, 2/16, 6/16, -7/16, 4/16},
|
||||
-- Box
|
||||
{-5/16, -7/16, -2/16, 5/16, -3/16, 3/16},
|
||||
-- "head"
|
||||
{-4/16, -3/16, -1/16, 4/16, -2/16, 2/16},
|
||||
{-3/16, -2/16, 0, 3/16, -1/16, 1/16},
|
||||
-- "horns"
|
||||
{-4/16, -1/16, 0, -3/16, 0, 1/16},
|
||||
{-3/16, 0, 0, -2/16, 1/16, 1/16},
|
||||
{3/16, -1/16, 0, 4/16, 0, 1/16},
|
||||
{2/16, 0, 0, 3/16, 1/16, 1/16},
|
||||
}
|
||||
},
|
||||
--}}}
|
||||
groups = {choppy=2,oddly_breakable_by_hand=2},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "",
|
||||
|
||||
on_construct = construct_container,
|
||||
after_dig_node = dig_container,
|
||||
on_rightclick = handle_unlocked_container,
|
||||
--{{{ Logging
|
||||
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" moves stuff in jewelry box at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" moves stuff to jewelry box at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" takes stuff from jewelry box at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
--}}}
|
||||
})
|
||||
|
||||
minetest.register_node("containers:wood_jbox_locked", {
|
||||
description = "Locked wooden jewelry box",
|
||||
--{{{ Tiles
|
||||
tiles = {
|
||||
"default_wood.png^containers_wood_jbox_top.png",
|
||||
"default_wood.png^containers_wood_jbox_top.png",
|
||||
"default_wood.png^containers_wood_jbox_side2.png",
|
||||
"default_wood.png^containers_wood_jbox_side.png",
|
||||
"default_wood.png^containers_wood_jbox_back.png",
|
||||
"default_wood.png^containers_wood_jbox_front.png"
|
||||
},
|
||||
--}}}
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
drawtype = "nodebox",
|
||||
--{{{ Node box
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
-- "legs"
|
||||
{-6/16, -8/16, -1/16, -4/16, -7/16, -3/16},
|
||||
{-6/16, -8/16, 2/16, -4/16, -7/16, 4/16},
|
||||
{4/16, -8/16, -1/16, 6/16, -7/16, -3/16},
|
||||
{4/16, -8/16, 2/16, 6/16, -7/16, 4/16},
|
||||
-- Box
|
||||
{-5/16, -7/16, -2/16, 5/16, -3/16, 3/16},
|
||||
-- "head"
|
||||
{-4/16, -3/16, -1/16, 4/16, -2/16, 2/16},
|
||||
{-3/16, -2/16, 0, 3/16, -1/16, 1/16},
|
||||
-- "horns"
|
||||
{-4/16, -1/16, 0, -3/16, 0, 1/16},
|
||||
{-3/16, 0, 0, -2/16, 1/16, 1/16},
|
||||
{3/16, -1/16, 0, 4/16, 0, 1/16},
|
||||
{2/16, 0, 0, 3/16, 1/16, 1/16},
|
||||
}
|
||||
},
|
||||
--}}}
|
||||
groups = {choppy=2,oddly_breakable_by_hand=2},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "",
|
||||
|
||||
on_construct = construct_container,
|
||||
after_place_node = place_locked_container,
|
||||
after_dig_node = dig_container,
|
||||
on_rightclick = handle_locked_container,
|
||||
--{{{ Logging
|
||||
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" moves stuff in jewelry box at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" moves stuff to jewelry box at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" takes stuff from jewelry box at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
--}}}
|
||||
})
|
||||
--}}}
|
||||
|
||||
|
@ -336,34 +433,16 @@ minetest.register_node("containers:wood_cabinet", {
|
|||
},
|
||||
paramtype2 = "facedir",
|
||||
groups = {choppy=2,oddly_breakable_by_hand=2},
|
||||
legacy_facedir_simple = true,
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
-- Chest formspec
|
||||
meta:set_string("formspec",
|
||||
"size[8,9]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
[[
|
||||
list[current_name;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)
|
||||
)
|
||||
meta:set_string("infotext", "Cabinet")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", 8*4)
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("main")
|
||||
end,
|
||||
--{{{ Logging
|
||||
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" moves stuff in cabinet at "..minetest.pos_to_string(pos))
|
||||
|
@ -376,58 +455,6 @@ minetest.register_node("containers:wood_cabinet", {
|
|||
minetest.log("action", player:get_player_name()..
|
||||
" takes stuff from cabinet at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
})
|
||||
--}}}
|
||||
|
||||
--{{{ Wooden jewelry box
|
||||
minetest.register_node("containers:wood_jbox", {
|
||||
description = "Wooden jewelry box",
|
||||
tiles = {
|
||||
"default_chest_top.png", "default_chest_top.png",
|
||||
"default_chest_side.png", "default_chest_side.png",
|
||||
"default_chest_side.png", "default_chest_front.png"
|
||||
},
|
||||
paramtype2 = "facedir",
|
||||
groups = {choppy=2,oddly_breakable_by_hand=2},
|
||||
legacy_facedir_simple = true,
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
-- Chest formspec
|
||||
meta:set_string("formspec",
|
||||
"size[8,9]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
[[
|
||||
list[current_name;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)
|
||||
)
|
||||
meta:set_string("infotext", "Jewelry box")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", 8*4)
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("main")
|
||||
end,
|
||||
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" moves stuff in jewelry box at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" moves stuff to jewelry box at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" takes stuff from jewelry box at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
--}}}
|
||||
})
|
||||
--}}}
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 765 B |
Binary file not shown.
After Width: | Height: | Size: 345 B |
Binary file not shown.
After Width: | Height: | Size: 363 B |
Binary file not shown.
After Width: | Height: | Size: 290 B |
Binary file not shown.
After Width: | Height: | Size: 290 B |
Binary file not shown.
After Width: | Height: | Size: 314 B |
Binary file not shown.
Loading…
Reference in New Issue