2019-09-05 08:44:32 +02:00
|
|
|
|
|
|
|
--chest code from default(Copyright (C) 2012 celeron55, Perttu Ahola <celeron55@gmail.com>)
|
|
|
|
local chest_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]" ..
|
|
|
|
"listring[current_name;main]" ..
|
|
|
|
"listring[current_player;main]" ..
|
|
|
|
default.get_hotbar_bg(0,4.85)
|
|
|
|
|
|
|
|
-- Helper functions
|
|
|
|
local function drop_chest_stuff()
|
2024-09-26 19:48:32 +02:00
|
|
|
return function(pos, _, oldmetadata)
|
2019-09-05 08:44:32 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:from_table(oldmetadata)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
for i = 1, inv:get_size("main") do
|
|
|
|
local stack = inv:get_stack("main", i)
|
|
|
|
if not stack:is_empty() then
|
|
|
|
local p = {
|
|
|
|
x = pos.x + math.random(0, 5)/5 - 0.5,
|
|
|
|
y = pos.y,
|
|
|
|
z = pos.z + math.random(0, 5)/5 - 0.5}
|
|
|
|
minetest.add_item(p, stack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-06-23 17:04:39 +02:00
|
|
|
local function register_chest(name, custom_def)
|
|
|
|
assert(custom_def.description)
|
|
|
|
assert(custom_def.tiles)
|
|
|
|
|
|
|
|
local def = {
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
legacy_facedir_simple = true,
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = scifi_nodes.node_sound_wood_defaults(),
|
|
|
|
after_dig_node = drop_chest_stuff(),
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", chest_formspec)
|
|
|
|
meta:set_string("infotext", custom_def.description)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size("main", 8 * 4)
|
|
|
|
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 chest 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 chest 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 chest at " .. minetest.pos_to_string(pos))
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
for k, v in pairs(custom_def) do
|
|
|
|
def[k] = v
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node(name, def)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
register_chest("scifi_nodes:crate", {
|
2019-09-05 08:44:32 +02:00
|
|
|
description = "Crate",
|
|
|
|
tiles = {"scifi_nodes_crate.png"},
|
2023-06-23 17:04:39 +02:00
|
|
|
groups = {
|
|
|
|
cracky = 1,
|
|
|
|
oddly_breakable_by_hand = 2,
|
|
|
|
fuel = 8
|
|
|
|
}
|
2019-09-05 08:44:32 +02:00
|
|
|
})
|
|
|
|
|
2023-06-23 17:04:39 +02:00
|
|
|
register_chest("scifi_nodes:box", {
|
2019-09-05 08:44:32 +02:00
|
|
|
description = "Storage box",
|
|
|
|
tiles = {
|
|
|
|
"scifi_nodes_box_top.png",
|
|
|
|
"scifi_nodes_box_top.png",
|
|
|
|
"scifi_nodes_box.png",
|
|
|
|
"scifi_nodes_box.png",
|
|
|
|
"scifi_nodes_box.png",
|
|
|
|
"scifi_nodes_box.png"
|
|
|
|
},
|
2023-06-23 17:04:39 +02:00
|
|
|
groups = {
|
|
|
|
cracky = 1
|
|
|
|
}
|
2019-09-05 08:44:32 +02:00
|
|
|
})
|