Fix some bugs in rp_paint

This commit is contained in:
Wuzzy 2024-10-24 22:37:27 +02:00
parent 837b88cf2a
commit c574d033d8
2 changed files with 24 additions and 50 deletions

View File

@ -13,8 +13,8 @@ end
rp_item_update.update_item = function(itemstack)
local iname = itemstack:get_name()
if updaters[iname] then
itemstack = updaters[iname](itemstack)
return itemstack
local new_itemstack = updaters[iname](itemstack)
return new_itemstack
else
return nil
end
@ -22,17 +22,21 @@ end
local update_inventory = function(inventory, lists)
if not lists then
lists = { "main" }
lists = { main = inventory:get_list("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)
for listname, list in pairs(lists) do
local changed = false
for i=1, #list do
local item = list[i]
local new_item = rp_item_update.update_item(item)
if new_item then
inventory:set_stack(list, i, new_item)
list[i] = new_item
changed = true
end
end
if changed then
inventory:set_list(listname, list)
end
end
end
@ -44,10 +48,10 @@ end)
minetest.register_lbm({
label = "Update items in containers",
name = "rp_item_update:update_containers",
nodename = { "group:container" },
nodenames = { "group:container" },
run_at_every_load = true,
action = function(pos, node)
local meta = minetest.get_meta()
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local lists = inv:get_lists()
update_inventory(inv, lists)

View File

@ -399,6 +399,7 @@ local function set_brush_image(itemstack)
item_meta:set_string("wield_overlay", "")
return itemstack
end
-- Brush with paint; show the amount of paint left
local ratio = color_uses / BRUSH_PAINTS
local rem
if ratio > 0.83333 then
@ -456,7 +457,7 @@ minetest.register_tool("rp_paint:brush", {
-- Dip brush in water bucket to remove paint
if minetest.get_item_group(node.name, "bucket_water") == 1 then
imeta:set_int("color_uses", 0)
set_item_image(imeta, "")
itemstack = set_brush_image(itemstack)
minetest.sound_play({name="rp_paint_brush_dip", gain=0.3, pitch=1.5}, {pos=pos, max_hear_distance = 8}, true)
return itemstack
end
@ -475,19 +476,18 @@ minetest.register_tool("rp_paint:brush", {
imeta:set_int("_palette_index", color)
imeta:set_int("color_uses", BRUSH_PAINTS)
local hexcode = COLOR_HEXCODES[color+1] or "#FFFFFF"
set_item_image(imeta, "rp_paint_brush_overlay.png^(rp_paint_brush.png^[multiply:"..hexcode..")")
itemstack = set_brush_image(itemstack)
minetest.sound_play({name="rp_paint_brush_dip", gain=0.3}, {pos=pos, max_hear_distance = 8}, true)
return itemstack
end
-- Paint paintable node (brush needs to have paint and node must be paintable)
local color = imeta:get_int("_palette_index")
local color = imeta:get_int("_palette_index") + 1
local color_uses = imeta:get_int("color_uses")
if color_uses <= 0 then
-- Not enough paint on brush: do nothing
set_item_image(imeta, "")
itemstack = set_brush_image(itemstack)
minetest.sound_play({name="rp_paint_brush_fail", gain=0.5}, {pos=pos, max_hear_distance=8}, true)
return itemstack
end
@ -507,38 +507,8 @@ minetest.register_tool("rp_paint:brush", {
color_uses = math.max(0, math.min(BRUSH_PAINTS, color_uses))
-- Update paint brush image to show the amount of paint left
if color_uses <= 0 then
set_item_image(imeta, "")
else
local ratio = color_uses / BRUSH_PAINTS
local rem
if ratio > 0.83333 then
rem = 0
elseif ratio > 0.66667 then
rem = 1
elseif ratio > 0.50000 then
rem = 2
elseif ratio > 0.33333 then
rem = 3
elseif ratio > 0.16667 then
rem = 4
else
rem = 5
end
local color = imeta:get_int("_palette_index") + 1
local hexcode = COLOR_HEXCODES[color] or "#FFFFFF"
local mask
if rem > 0 then
mask = "^[mask:rp_paint_brush_overlay_mask_"..rem..".png"
else
mask = ""
end
local istr = "rp_paint_brush_overlay.png^(rp_paint_brush.png"..mask.."^[multiply:"..hexcode..")"
set_item_image(imeta, istr)
end
-- Update paint brush image
itemstack = set_brush_image(itemstack)
else
minetest.sound_play({name="rp_paint_brush_fail", gain=0.5}, {pos=pos, max_hear_distance=8}, true)
end
@ -862,11 +832,11 @@ rp_item_update.register_item_update("rp_paint:brush", function(itemstack)
local item_meta = itemstack:get_meta()
local pi = item_meta:get_int("palette_index")
local color
if pi > 0 then
if pi ~= 0 then
item_meta:set_int("palette_index", 0)
item_meta:set_int("_palette_index", pi)
itemstack = set_brush_image(itemstack)
return itemstack
end
itemstack = set_brush_image(itemstack)
return itemstack
end)