Add container groups to support item update

This commit is contained in:
Wuzzy 2024-10-24 22:18:04 +02:00
parent 8a79ca91a8
commit 837b88cf2a
6 changed files with 27 additions and 22 deletions

View File

@ -29,7 +29,7 @@ minetest.register_node(
tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_sides.png",
"default_chest_sides.png", "default_chest_sides.png", "default_chest_front.png"},
paramtype2 = "facedir",
groups = {snappy = 2,choppy = 2,oddly_breakable_by_hand = 2},
groups = {container = 1, snappy = 2,choppy = 2,oddly_breakable_by_hand = 2},
is_ground_content = false,
sounds = rp_sounds.node_sound_wood_defaults(),
on_construct = function(pos)
@ -80,7 +80,7 @@ minetest.register_node(
_tt_help = S("Provides 8 inventory slots"),
tiles = {"default_wood.png", "default_wood.png", "default_bookshelf.png"},
paramtype2 = "facedir",
groups = {snappy = 2,choppy = 3,oddly_breakable_by_hand = 2},
groups = {container = 1, snappy = 2,choppy = 3,oddly_breakable_by_hand = 2},
is_ground_content = false,
sounds = rp_sounds.node_sound_wood_defaults(),
on_construct = function(pos)

View File

@ -13,21 +13,25 @@ end
rp_item_update.update_item = function(itemstack)
local iname = itemstack:get_name()
if updaters[iname] then
minetest.log("error", "Updateing item: "..itemstack:to_string())
itemstack = updaters[iname](iname)
minetest.log("error", "Updated item: "..itemstack:to_string())
itemstack = updaters[iname](itemstack)
return itemstack
else
return nil
end
end
local update_inventory = function(inventory)
for i=1, inventory:get_size("main") do
local item = inventory:get_stack("main", i)
local new_item = rp_item_update.update_item(item)
if new_item then
inventory:set_stack("main", i, new_item)
local update_inventory = function(inventory, lists)
if not lists then
lists = { "main" }
end
for l=1, #lists do
local list = lists[l]
for i=1, inventory:get_size(list) do
local item = inventory:get_stack(list, i)
local new_item = rp_item_update.update_item(item)
if new_item then
inventory:set_stack(list, i, new_item)
end
end
end
end
@ -45,6 +49,7 @@ minetest.register_lbm({
action = function(pos, node)
local meta = minetest.get_meta()
local inv = meta:get_inventory()
update_inventory(inv)
local lists = inv:get_lists()
update_inventory(inv, lists)
end,
})

View File

@ -266,7 +266,7 @@ minetest.register_node("rp_itemshow:frame",{
paramtype2 = "color4dir",
sunlight_propagates = true,
groups = {
choppy = 2, dig_immediate = 2, creative_decoblock = 1, paintable = 1,
container = 1, choppy = 2, dig_immediate = 2, creative_decoblock = 1, paintable = 1,
pathfinder_thin = 1,
-- So that placing a magnocompass on it will point
-- the needle to the correct direction
@ -348,7 +348,7 @@ minetest.register_node("rp_itemshow:showcase", {
tiles = {"rp_itemshow_showcase.png"},
use_texture_alpha = "clip",
paramtype = "light",
groups = { item_showcase = 1, cracky = 3, oddly_breakable_by_hand = 2, uses_canonical_compass = 1, creative_decoblock = 1, furniture = 1, pathfinder_hard = 1 },
groups = { container = 1, item_showcase = 1, cracky = 3, oddly_breakable_by_hand = 2, uses_canonical_compass = 1, creative_decoblock = 1, furniture = 1, pathfinder_hard = 1 },
sounds = rp_sounds.node_sound_glass_defaults(),
is_ground_content = false,

View File

@ -313,7 +313,7 @@ minetest.register_node(
_tt_help = S("Tools can be upgraded with jewels here"),
tiles ={"jewels_bench_top.png", "jewels_bench_bottom.png", "jewels_bench_sides.png"},
paramtype2 = "4dir",
groups = {choppy=2,oddly_breakable_by_hand=2,interactive_node=1,furniture=1,pathfinder_hard=1},
groups = {container=1, choppy=2,oddly_breakable_by_hand=2,interactive_node=1,furniture=1,pathfinder_hard=1},
is_ground_content = false,
sounds = rp_sounds.node_sound_wood_defaults(),

View File

@ -297,7 +297,7 @@ local chest_def = {
},
use_texture_alpha = "blend",
paramtype2 = "4dir",
groups = {choppy = 2, oddly_breakable_by_hand = 2, level = -1, locked = 1, chest = 2, container = 1, paintable = 2, furniture = 1, pathfinder_hard = 1},
groups = {container = 1, choppy = 2, oddly_breakable_by_hand = 2, level = -1, locked = 1, chest = 2, container = 1, paintable = 2, furniture = 1, pathfinder_hard = 1},
is_ground_content = false,
sounds = rp_sounds.node_sound_planks_defaults(),
on_construct = function(pos)

View File

@ -397,7 +397,7 @@ local function set_brush_image(itemstack)
item_meta:set_string("wield_image", "")
item_meta:set_string("inventory_overlay", "")
item_meta:set_string("wield_overlay", "")
return
return itemstack
end
local ratio = color_uses / BRUSH_PAINTS
local rem
@ -415,7 +415,7 @@ local function set_brush_image(itemstack)
rem = 5
end
local color = item_meta:get_int("_palette_index", 0) + 1
local color = item_meta:get_int("_palette_index") + 1
local hexcode = COLOR_HEXCODES[color] or "#FFFFFF"
local mask
@ -430,6 +430,7 @@ local function set_brush_image(itemstack)
item_meta:set_string("wield_image", image)
item_meta:set_string("inventory_overlay", "")
item_meta:set_string("wield_overlay", "")
return itemstack
end
minetest.register_tool("rp_paint:brush", {
@ -471,7 +472,6 @@ minetest.register_tool("rp_paint:brush", {
-- Reduce amount of paint in bucket
change_bucket_level(pos, node, -1)
end
imeta:set_int("palette_index", 0)
imeta:set_int("_palette_index", color)
imeta:set_int("color_uses", BRUSH_PAINTS)
@ -483,7 +483,7 @@ minetest.register_tool("rp_paint:brush", {
end
-- Paint paintable node (brush needs to have paint and node must be paintable)
local color = get_color(imeta)
local color = imeta:get_int("_palette_index")
local color_uses = imeta:get_int("color_uses")
if color_uses <= 0 then
-- Not enough paint on brush: do nothing
@ -527,7 +527,7 @@ minetest.register_tool("rp_paint:brush", {
rem = 5
end
local color = get_color(imeta)
local color = imeta:get_int("_palette_index") + 1
local hexcode = COLOR_HEXCODES[color] or "#FFFFFF"
local mask
@ -866,7 +866,7 @@ rp_item_update.register_item_update("rp_paint:brush", function(itemstack)
item_meta:set_int("palette_index", 0)
item_meta:set_int("_palette_index", pi)
end
set_brush_image(itemstack)
itemstack = set_brush_image(itemstack)
return itemstack
end)