Add files via upload

master
Pantyhose-X 2022-08-02 16:39:52 +08:00 committed by GitHub
parent b573a34a0f
commit 8ac5690c3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 0 deletions

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", 128)
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[16,11;]"..
"list[detached:pi;main;0,0;16,8;]"..
"list[current_player;main;0,9;16,2;]")
return true, ""
end,
})

4
mod.conf Normal file
View File

@ -0,0 +1,4 @@
author = cd2
name = public_inventory
description = Adds a public inventory.
title = Public Inventory

BIN
screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB