allow bags via item groups
This commit is contained in:
parent
815651a32f
commit
ffa50bc3a7
50
init.lua
50
init.lua
|
@ -83,9 +83,9 @@ local HUD_TIMER_MAX = 1.5
|
||||||
local MIN_FORMSPEC_VERSION = 4
|
local MIN_FORMSPEC_VERSION = 4
|
||||||
|
|
||||||
local BAG_SIZES = {
|
local BAG_SIZES = {
|
||||||
small = INV_SIZE + 3,
|
[1] = INV_SIZE + 3,
|
||||||
medium = INV_SIZE + 6,
|
[2] = INV_SIZE + 6,
|
||||||
large = INV_SIZE + 9,
|
[3] = INV_SIZE + 9,
|
||||||
}
|
}
|
||||||
|
|
||||||
local SUBCAT = {
|
local SUBCAT = {
|
||||||
|
@ -2452,11 +2452,11 @@ local function get_inv_slots(data, fs)
|
||||||
fmt("list[current_player;main;%f,%f;%u,1;]", inv_x, inv_y, HOTBAR_COUNT))
|
fmt("list[current_player;main;%f,%f;%u,1;]", inv_x, inv_y, HOTBAR_COUNT))
|
||||||
|
|
||||||
if bag then
|
if bag then
|
||||||
if bag == "small" then
|
if bag == 1 then
|
||||||
width, size = 10, 0.892
|
width, size = 10, 0.892
|
||||||
elseif bag == "medium" then
|
elseif bag == 2 then
|
||||||
width, size = 11, 0.8
|
width, size = 11, 0.8
|
||||||
elseif bag == "large" then
|
elseif bag == 3 then
|
||||||
width, size = 12, 0.726
|
width, size = 12, 0.726
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2947,13 +2947,25 @@ local function init_backpack(player)
|
||||||
local data = pdata[name]
|
local data = pdata[name]
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
|
|
||||||
|
--legacy compat
|
||||||
|
if data.bag_size and type(data.bag_size) == "string" then
|
||||||
|
local convert = {
|
||||||
|
small = 1,
|
||||||
|
medium = 2,
|
||||||
|
large = 3,
|
||||||
|
}
|
||||||
|
data.bag_item = fmt("i3:bag_%s", data.bag_size)
|
||||||
|
data.bag_size = convert[data.bag_size]
|
||||||
|
end
|
||||||
|
|
||||||
inv:set_size("main", data.bag_size and BAG_SIZES[data.bag_size] or INV_SIZE)
|
inv:set_size("main", data.bag_size and BAG_SIZES[data.bag_size] or INV_SIZE)
|
||||||
|
|
||||||
data.bag = create_inventory(fmt("%s_backpack", name), {
|
data.bag = create_inventory(fmt("%s_backpack", name), {
|
||||||
allow_put = function(_inv, listname, _, stack)
|
allow_put = function(_inv, listname, _, stack)
|
||||||
local empty = _inv:get_stack(listname, 1):is_empty()
|
local empty = _inv:get_stack(listname, 1):is_empty()
|
||||||
|
local item_group = minetest.get_item_group(stack:get_name(), "i3_bag")
|
||||||
|
|
||||||
if empty and sub(stack:get_name(), 1, 7) == "i3:bag_" then
|
if empty and item_group > 0 and item_group < 4 then
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2963,7 +2975,8 @@ local function init_backpack(player)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_put = function(_, _, _, stack)
|
on_put = function(_, _, _, stack)
|
||||||
data.bag_size = match(stack:get_name(), "_(%w+)$")
|
data.bag_size = minetest.get_item_group(stack:get_name(), "i3_bag")
|
||||||
|
data.bag_item = stack:get_name()
|
||||||
inv:set_size("main", BAG_SIZES[data.bag_size])
|
inv:set_size("main", BAG_SIZES[data.bag_size])
|
||||||
set_fs(player)
|
set_fs(player)
|
||||||
end,
|
end,
|
||||||
|
@ -2978,6 +2991,7 @@ local function init_backpack(player)
|
||||||
end
|
end
|
||||||
|
|
||||||
data.bag_size = nil
|
data.bag_size = nil
|
||||||
|
data.bag_item = nil
|
||||||
inv:set_size("main", INV_SIZE)
|
inv:set_size("main", INV_SIZE)
|
||||||
|
|
||||||
set_fs(player)
|
set_fs(player)
|
||||||
|
@ -2986,8 +3000,8 @@ local function init_backpack(player)
|
||||||
|
|
||||||
data.bag:set_size("main", 1)
|
data.bag:set_size("main", 1)
|
||||||
|
|
||||||
if data.bag_size then
|
if data.bag_item then
|
||||||
data.bag:set_stack("main", 1, fmt("i3:bag_%s", data.bag_size))
|
data.bag:set_stack("main", 1, data.bag_item)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3038,6 +3052,7 @@ core.register_on_dieplayer(function(player)
|
||||||
|
|
||||||
if data.bag_size then
|
if data.bag_size then
|
||||||
data.bag_size = nil
|
data.bag_size = nil
|
||||||
|
data.bag_item = nil
|
||||||
data.bag:set_list("main", {})
|
data.bag:set_list("main", {})
|
||||||
|
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
|
@ -3049,6 +3064,7 @@ end)
|
||||||
|
|
||||||
local META_SAVES = {
|
local META_SAVES = {
|
||||||
bag_size = true,
|
bag_size = true,
|
||||||
|
bag_item = true,
|
||||||
waypoints = true,
|
waypoints = true,
|
||||||
inv_items = true,
|
inv_items = true,
|
||||||
known_recipes = true,
|
known_recipes = true,
|
||||||
|
@ -3373,30 +3389,40 @@ end
|
||||||
|
|
||||||
local bag_recipes = {
|
local bag_recipes = {
|
||||||
small = {
|
small = {
|
||||||
|
rcp = {
|
||||||
{"", "farming:string", ""},
|
{"", "farming:string", ""},
|
||||||
{"group:wool", "group:wool", "group:wool"},
|
{"group:wool", "group:wool", "group:wool"},
|
||||||
{"group:wool", "group:wool", "group:wool"},
|
{"group:wool", "group:wool", "group:wool"},
|
||||||
},
|
},
|
||||||
|
group = 1,
|
||||||
|
},
|
||||||
medium = {
|
medium = {
|
||||||
|
rcp = {
|
||||||
{"farming:string", "i3:bag_small", "farming:string"},
|
{"farming:string", "i3:bag_small", "farming:string"},
|
||||||
{"farming:string", "i3:bag_small", "farming:string"},
|
{"farming:string", "i3:bag_small", "farming:string"},
|
||||||
},
|
},
|
||||||
|
group = 2,
|
||||||
|
},
|
||||||
large = {
|
large = {
|
||||||
|
rcp = {
|
||||||
{"farming:string", "i3:bag_medium", "farming:string"},
|
{"farming:string", "i3:bag_medium", "farming:string"},
|
||||||
{"farming:string", "i3:bag_medium", "farming:string"},
|
{"farming:string", "i3:bag_medium", "farming:string"},
|
||||||
},
|
},
|
||||||
|
group = 3,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for size, rcp in pairs(bag_recipes) do
|
for size, item in pairs(bag_recipes) do
|
||||||
local bagname = fmt("i3:bag_%s", size)
|
local bagname = fmt("i3:bag_%s", size)
|
||||||
|
|
||||||
core.register_craftitem(bagname, {
|
core.register_craftitem(bagname, {
|
||||||
description = fmt("%s Backpack", size:gsub("^%l", upper)),
|
description = fmt("%s Backpack", size:gsub("^%l", upper)),
|
||||||
inventory_image = fmt("i3_bag_%s.png", size),
|
inventory_image = fmt("i3_bag_%s.png", size),
|
||||||
stack_max = 1,
|
stack_max = 1,
|
||||||
|
groups = {i3_bag = item.group}
|
||||||
})
|
})
|
||||||
|
|
||||||
core.register_craft {output = bagname, recipe = rcp}
|
core.register_craft {output = bagname, recipe = item.rcp}
|
||||||
core.register_craft {type = "fuel", recipe = bagname, burntime = 3}
|
core.register_craft {type = "fuel", recipe = bagname, burntime = 3}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Ŝarĝante…
Reference in New Issue