2018-08-08 01:06:16 +02:00
|
|
|
--[[
|
|
|
|
|
|
|
|
Tubelib Addons 3
|
|
|
|
================
|
|
|
|
|
2020-11-20 14:45:28 +01:00
|
|
|
Copyright (C) 2017-2020 Joachim Stolberg
|
2018-08-08 01:06:16 +02:00
|
|
|
|
2020-11-20 14:45:28 +01:00
|
|
|
AGPL v3
|
2018-08-08 01:06:16 +02:00
|
|
|
See LICENSE.txt for more information
|
2022-06-09 23:49:50 +02:00
|
|
|
|
2018-08-08 01:06:16 +02:00
|
|
|
chest.lua
|
2022-06-09 23:49:50 +02:00
|
|
|
|
2018-08-08 01:06:16 +02:00
|
|
|
A high performance chest
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
2020-11-03 20:19:38 +01:00
|
|
|
-- Load support for I18n
|
|
|
|
local S = tubelib_addons3.S
|
|
|
|
|
2018-09-15 19:22:10 +02:00
|
|
|
local PlayerActions = {}
|
|
|
|
local InventoryState = {}
|
|
|
|
|
|
|
|
|
|
|
|
local function store_action(pos, player, action, stack)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local name = player and player:get_player_name() or ""
|
|
|
|
local number = meta:get_string("number")
|
|
|
|
local item = stack:get_name().." "..stack:get_count()
|
|
|
|
PlayerActions[number] = {name, action, item}
|
2022-06-09 23:49:50 +02:00
|
|
|
end
|
2018-09-15 19:22:10 +02:00
|
|
|
|
|
|
|
local function send_off_command(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local dest_num = meta:get_string("dest_num")
|
|
|
|
local own_num = meta:get_string("number")
|
|
|
|
local owner = meta:get_string("owner")
|
|
|
|
tubelib.send_message(dest_num, owner, nil, "off", own_num)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function send_command(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local dest_num = meta:get_string("dest_num")
|
|
|
|
if dest_num ~= "" then
|
|
|
|
local own_num = meta:get_string("number")
|
|
|
|
local owner = meta:get_string("owner")
|
|
|
|
tubelib.send_message(dest_num, owner, nil, "on", own_num)
|
|
|
|
minetest.after(1, send_off_command, pos)
|
|
|
|
end
|
|
|
|
end
|
2018-08-08 01:06:16 +02:00
|
|
|
|
|
|
|
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return 0
|
|
|
|
end
|
2018-09-15 19:22:10 +02:00
|
|
|
store_action(pos, player, "put", stack)
|
|
|
|
send_command(pos)
|
2018-08-08 01:06:16 +02:00
|
|
|
return stack:get_count()
|
|
|
|
end
|
|
|
|
|
|
|
|
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return 0
|
|
|
|
end
|
2018-09-15 19:22:10 +02:00
|
|
|
store_action(pos, player, "take", stack)
|
|
|
|
send_command(pos)
|
2018-08-08 01:06:16 +02:00
|
|
|
return stack:get_count()
|
|
|
|
end
|
|
|
|
|
|
|
|
local function formspec()
|
|
|
|
return "size[12,10]"..
|
|
|
|
default.gui_bg..
|
|
|
|
default.gui_bg_img..
|
|
|
|
default.gui_slots..
|
|
|
|
"list[context;main;0,0;12,6;]"..
|
|
|
|
"list[current_player;main;2,6.3;8,4;]"..
|
|
|
|
"listring[context;main]"..
|
|
|
|
"listring[current_player;main]"
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node("tubelib_addons3:chest", {
|
2020-11-03 20:19:38 +01:00
|
|
|
description = S("HighPerf Chest"),
|
2018-08-08 01:06:16 +02:00
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
'tubelib_addons3_chest_bottom.png',
|
|
|
|
'tubelib_addons3_chest_bottom.png',
|
|
|
|
"tubelib_addons3_chest_side.png",
|
|
|
|
"tubelib_addons3_chest_side.png",
|
|
|
|
"tubelib_addons3_chest_side.png",
|
|
|
|
"tubelib_addons3_chest_front.png",
|
|
|
|
},
|
|
|
|
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size('main', 72)
|
|
|
|
end,
|
2022-06-09 23:49:50 +02:00
|
|
|
|
2018-08-08 01:06:16 +02:00
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2018-09-10 22:36:09 +02:00
|
|
|
local number = tubelib.add_node(pos, "tubelib_addons3:chest")
|
|
|
|
meta:set_string("number", number)
|
2018-09-15 19:22:10 +02:00
|
|
|
meta:set_string("owner", placer:get_player_name())
|
2018-08-08 01:06:16 +02:00
|
|
|
meta:set_string("formspec", formspec())
|
2020-11-03 20:19:38 +01:00
|
|
|
meta:set_string("infotext", S("HighPerf Chest").." "..number)
|
2018-08-08 01:06:16 +02:00
|
|
|
end,
|
|
|
|
|
|
|
|
can_dig = function(pos,player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return false
|
|
|
|
end
|
2018-09-15 19:22:10 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2018-08-08 01:06:16 +02:00
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return inv:is_empty("main")
|
|
|
|
end,
|
2022-06-09 23:49:50 +02:00
|
|
|
|
2018-08-08 01:06:16 +02:00
|
|
|
on_dig = function(pos, node, puncher, pointed_thing)
|
|
|
|
minetest.node_dig(pos, node, puncher, pointed_thing)
|
2018-09-10 22:36:09 +02:00
|
|
|
tubelib.remove_node(pos)
|
2018-08-08 01:06:16 +02:00
|
|
|
end,
|
|
|
|
|
|
|
|
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
|
|
|
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
|
|
|
|
|
|
|
paramtype = "light",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {choppy=2, cracky=2, crumbly=2},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2022-06-09 23:49:50 +02:00
|
|
|
on_blast = function() end,
|
2018-08-08 01:06:16 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "tubelib_addons3:chest",
|
|
|
|
recipe = {
|
2018-08-08 11:37:27 +02:00
|
|
|
{"default:tin_ingot", "tubelib_addons1:chest", ""},
|
|
|
|
{"tubelib_addons1:chest", "default:gold_ingot", ""},
|
|
|
|
{"", "", ""},
|
|
|
|
},
|
2018-08-08 01:06:16 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
tubelib.register_node("tubelib_addons3:chest", {}, {
|
2018-08-08 11:37:27 +02:00
|
|
|
on_pull_stack = function(pos, side)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
return tubelib.get_stack(meta, "main")
|
|
|
|
end,
|
2018-08-08 01:06:16 +02:00
|
|
|
on_pull_item = function(pos, side)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2018-08-08 11:37:27 +02:00
|
|
|
return tubelib.get_item(meta, "main")
|
2018-08-08 01:06:16 +02:00
|
|
|
end,
|
|
|
|
on_push_item = function(pos, side, item)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2021-08-01 16:11:12 +02:00
|
|
|
local res = tubelib.put_item(meta, "main", item)
|
|
|
|
if res == false then
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
local leftover = inv:add_item("main", item)
|
|
|
|
item:set_count(leftover:get_count())
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
2018-08-08 01:06:16 +02:00
|
|
|
end,
|
|
|
|
on_unpull_item = function(pos, side, item)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
return tubelib.put_item(meta, "main", item)
|
|
|
|
end,
|
2022-06-09 23:49:50 +02:00
|
|
|
|
2018-08-08 01:06:16 +02:00
|
|
|
on_recv_message = function(pos, topic, payload)
|
2018-09-10 22:36:09 +02:00
|
|
|
if topic == "state" then
|
|
|
|
local meta = minetest.get_meta(pos)
|
2018-09-15 19:22:10 +02:00
|
|
|
return tubelib.get_inv_state(meta, "main")
|
|
|
|
elseif topic == "player_action" then
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local number = meta:get_string("number")
|
|
|
|
return PlayerActions[number]
|
|
|
|
elseif topic == "set_numbers" then
|
|
|
|
if tubelib.check_numbers(payload) then
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("dest_num", payload)
|
|
|
|
local number = meta:get_string("number")
|
2020-11-03 20:19:38 +01:00
|
|
|
meta:set_string("infotext", S("HighPerf Chest").." "..number.." "..S("connected with").." "..payload)
|
2018-09-15 19:22:10 +02:00
|
|
|
return true
|
|
|
|
end
|
2018-09-10 22:36:09 +02:00
|
|
|
else
|
|
|
|
return "unsupported"
|
|
|
|
end
|
2018-08-08 01:06:16 +02:00
|
|
|
end,
|
2022-06-09 23:49:50 +02:00
|
|
|
})
|