add more inventory structure, add chest, add "drop contents" function in utils

master
Sumyjkl 2022-08-31 21:57:06 +10:00
parent 5cfdf6879b
commit 79775edddb
14 changed files with 172 additions and 14 deletions

View File

@ -0,0 +1,24 @@
Media contained within is under CC-BY-4.0. https://creativecommons.org/licenses/by/4.0/
MIT License
Copyright (c) 2022 Sumi, SumianVoice <info[at]sumianvoice.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,10 @@
local mod_name = minetest.get_current_modname()
local mod_path = minetest.get_modpath(mod_name)
local S = minetest.get_translator(mod_name)
pmb_inventory = {}
dofile(mod_path .. DIR_DELIM .. "scripts" .. DIR_DELIM .. "drop_contents.lua")
dofile(mod_path .. DIR_DELIM .. "scripts" .. DIR_DELIM .. "player.lua")

View File

@ -0,0 +1,2 @@
name = pmb_inventory
author = Sumi

View File

@ -0,0 +1,17 @@
function pmb_inventory.drop_contents(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local inv_lists = inv:get_lists()
local items = {}
for list_name, list in pairs(inv_lists) do
if not inv:is_empty(list_name) then
for i=0, inv:get_size(list_name) do
local stack = inv:get_stack(list_name, i)
minetest.add_item(pos, stack)
inv:remove_item(list_name, stack)
end
end
end
end

View File

@ -0,0 +1,37 @@
local mod_name = minetest.get_current_modname()
local mod_path = minetest.get_modpath(mod_name)
local S = minetest.get_translator(mod_name)
pmb_inventory.player = {}
local inv = pmb_inventory.player
inv.width = 10
inv.height = 4
function pmb_inventory.player.set_size(width, height)
inv.width = width
inv.height = height
end
function pmb_inventory.player.get_formspec(offset, size)
if offset==nil then offset = {x=0,y=0} end
if size==nil then size = {x=10,y=4} end
return (
"list[current_player;main;"..tostring(offset.x)..","..tostring(offset.y).. ";"..(inv.width)..","..(inv.height-1)..";10]"..
"list[current_player;main;"..tostring(offset.x)..","..tostring(0.3+offset.y+inv.height-1)..";"..(inv.width)..","..(1)..";]"..
"listcolors[#66504f88;#f7e7da99]"..
"background[0,0;10,8;pmb_inv_bg.png;true]"
)
end
function pmb_inventory.player.get_craft_menu()
return [[
size[10,8]
image[6,1;2,1;pmb_inv_arrow.png]
list[current_player;craft;3,0;3,3;]
list[current_player;craftpreview;7,1;1,1;]
]] ..
pmb_inventory.player.get_formspec({x=0,y=3.5})
end

View File

@ -0,0 +1,24 @@
Media contained within is under CC-BY-4.0. https://creativecommons.org/licenses/by/4.0/
MIT License
Copyright (c) 2022 Sumi, SumianVoice <info[at]sumianvoice.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,6 @@
local mod_name = minetest.get_current_modname()
local mod_path = minetest.get_modpath(mod_name)
pmb_storage = {}
dofile(mod_path .. DIR_DELIM .. "nodes" .. DIR_DELIM .. "chest.lua")

View File

@ -0,0 +1,3 @@
name = pmb_storage
author = Sumi
optional_depends = pmb_sounds, pmb_inventory

View File

@ -0,0 +1,33 @@
local formspec = [[
size[10,4]
list[context;main;0,0;10,3;]
list[current_player;main;0,5;8,4;]
]]
minetest.register_node('pmb_storage:chest', {
description = "Storage chest",
groups = { oddly_breakable_by_hand = 2, choppy = 1, solid = 1, suffocates = 0, wood = 1, item_wooden_chest = 1, },
tiles = {"pmb_storage_chest.png"},
mesh = "pmb_storage_chest.b3d",
drawtype = "mesh",
sounds = pmb_sounds.default_wood(),
paramtype2 = "facedir",
after_place_node = function(pos, placer, itemstack, pointed_thing)
pmb_util.rotate_and_place_from(pos, placer, itemstack, pointed_thing)
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",
"size[10,8]"..
"list[context;main;0,0;10,3;]"..
pmb_inventory.player.get_formspec({x=0,y=3.5}))
meta:set_string("infotext", "Chest");
local inv = meta:get_inventory()
inv:set_size("main", 10*3)
end,
on_destruct = function(pos)
pmb_inventory.drop_contents(pos)
end
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -1,4 +1,6 @@
local mod_name = minetest.get_current_modname()
local mod_path = minetest.get_modpath(mod_name)
player_init = {}
dofile(mod_path .. DIR_DELIM .. "inventory.lua")

View File

@ -1,20 +1,19 @@
local formspec =(
"size[10,8]"..
"image[6,1;2,1;pmb_inv_arrow.png]"..
"list[current_player;main;0,3.5;10,3;10]".. -- main inv
"list[current_player;main;0,7.25;10,1;]".. -- hotbar
"list[current_player;craft;3,0;3,3;]"..
"list[current_player;craftpreview;7,1;1,1;]"..
"background[0,0;10,8;pmb_inv_bg.png;true]"..
"listcolors[#66504f88;#f7e7da99]"
)
player_init.inventory = {
width = 10,
height = 4,
}
player_init.inventory.size = player_init.inventory.width * player_init.inventory.height
-- set the formspec size
pmb_inventory.player.set_size(player_init.inventory.width, player_init.inventory.height)
local formspec = pmb_inventory.player.get_craft_menu()
minetest.register_on_joinplayer(function(player)
player:hud_set_hotbar_itemcount(10)
player:set_inventory_formspec(formspec)
local inv = player:get_inventory()
inv:set_width("main", 10)
inv:set_size("main", 10*4)
inv:set_size("main", player_init.inventory.size)
end)

View File

@ -1,3 +1,4 @@
name = player_init
author = PMB team
description =
description =
depends = pmb_inventory