Imported from trollstream "ContentDB"

master
OldCoder 2022-09-04 22:02:39 -07:00
commit 93123ec55f
4 changed files with 92 additions and 0 deletions

11
LICENSE.txt Normal file
View File

@ -0,0 +1,11 @@
License for Code
----------------
Copyright (C) 2015 cd2
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
http://www.gnu.org/licenses/lgpl-2.1.html

18
README.md Normal file
View File

@ -0,0 +1,18 @@
#public_inventory by cd2
#description
It adds a public inventory.
#license
see LICENSE.txt
#how to install it?
unzip the folder and copy it into the subfolder mods in your minetest folder.
for help see http://wiki.minetest.com/wiki/Installing_Mods
#version
current verion is : 1.1
#bugs
report bugs in the forum

1
description.txt Normal file
View File

@ -0,0 +1 @@
It adds a public inventory.

62
init.lua Normal file
View File

@ -0,0 +1,62 @@
local pi_file = minetest.get_worldpath() .. "/pi"
local pi = minetest.create_detached_inventory("pi", {
on_put = function(inv, listname, index, stack, player)
local list = inv:get_list("main")
if list then
local output = io.open(pi_file, "w")
local str = ""
table.foreach(list,function(index)
str = str..list[index]:to_string()..","
end
)
str = str:sub(1, #str - 1)
output:write(str)
io.close(output)
end
end,
on_take = function(inv, listname, index, stack, player)
local list = inv:get_list("main")
if list then
local output = io.open(pi_file, "w")
local str = ""
table.foreach(list,function(index)
str = str..list[index]:to_string()..","
end
)
str = str:sub(1, #str - 1)
output:write(str)
io.close(output)
end
end,
})
pi:set_size("main", 32)
local function load_pi()
local input = io.open(pi_file, "r")
if input then
local str = input:read()
if str then
for item in str.gmatch(str, '([^,]+)') do
pi:add_item("main", item)
end
end
io.close(input)
end
end
load_pi()
minetest.register_chatcommand("pi", {
params = "",
description = "shows the public inventory",
func = function(name, param)
minetest.show_formspec(name, "public_inventory:pi",
"size[8,9;]"..
"list[detached:pi;main;0,0;8,4;]"..
"list[current_player;main;0,5;8,4;]")
return true, ""
end,
})