Skip to content

Commit

Permalink
Revert "workaround for engine bug in crafting, placing, digging items…
Browse files Browse the repository at this point in the history
… with a palette index of 0"

This reverts commit eb5610f.
  • Loading branch information
OgelGames committed May 7, 2022
1 parent c079888 commit 2af4f1f
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions api.lua
Expand Up @@ -21,11 +21,14 @@ minetest.register_on_placenode(
return false
end

local param2
if not string.find(itemstack:to_string(), "palette_index") then
local param2
local color = 0

if def.palette == "unifieddyes_palette_extended.png"
and def.paramtype2 == "color" then
param2 = 240
color = 240
elseif def.palette == "unifieddyes_palette_colorwallmounted.png"
and def.paramtype2 == "colorwallmounted" then
param2 = newnode.param2 % 8
Expand All @@ -36,21 +39,17 @@ minetest.register_on_placenode(

if param2 then
minetest.swap_node(pos, {name = newnode.name, param2 = param2})
minetest.get_meta(pos):set_int("palette_index", color)
end
end

if def.palette ~= "" then
minetest.get_meta(pos):set_int("palette_index", param2 or 240)
end
end
)

-- The complementary function: strip-off the color if the node being dug is still white/neutral

local function move_item(item, pos, inv, digger, fix_color)
if not (digger and digger:is_player()) then return end
local function move_item(item, pos, inv, digger)
if not (digger and digger:is_player()) then return end
local creative = minetest.is_creative_enabled(digger:get_player_name())
item = unifieddyes.fix_bad_color_info(item, fix_color)
if inv:room_for_item("main", item)
and (not creative or not inv:contains_item("main", item, true)) then
inv:add_item("main", item)
Expand All @@ -70,23 +69,22 @@ function unifieddyes.on_dig(pos, node, digger)

local oldparam2 = minetest.get_node(pos).param2
local def = minetest.registered_items[node.name]
local fix_color
local del_color

if def.paramtype2 == "color" and oldparam2 == 240 and def.palette == "unifieddyes_palette_extended.png" then
fix_color = 240
elseif def.paramtype2 == "color" and oldparam2 == 0 and def.palette == "unifieddyes_palette_extended.png" then
fix_color = 0
del_color = true
elseif def.paramtype2 == "colorwallmounted" and math.floor(oldparam2 / 8) == 0
and def.palette == "unifieddyes_palette_colorwallmounted.png" then
fix_color = 0
and def.palette == "unifieddyes_palette_colorwallmounted.png" then
del_color = true
elseif def.paramtype2 == "colorfacedir" and math.floor(oldparam2 / 32) == 0
and string.find(def.palette, "unifieddyes_palette_") then
fix_color = 0
and string.find(def.palette, "unifieddyes_palette_") then
del_color = true
end

local inv = digger:get_inventory()
if fix_color then
move_item(node.name, pos, inv, digger, fix_color)

if del_color then
move_item(node.name, pos, inv, digger)
else
return minetest.node_dig(pos, node, digger)
end
Expand Down Expand Up @@ -132,14 +130,11 @@ end

-- This helper function creates a colored itemstack

function unifieddyes.fix_bad_color_info(item, paletteidx)
local stack=minetest.itemstring_with_color(item, paletteidx)
return string.gsub(stack, "u0001color", "u0001palette_index")
end

function unifieddyes.make_colored_itemstack(item, palette, color)
local paletteidx = unifieddyes.getpaletteidx(color, palette)
return unifieddyes.fix_bad_color_info(item, paletteidx), paletteidx
local stack = ItemStack(item)
stack:get_meta():set_int("palette_index", paletteidx)
return stack:to_string(),paletteidx
end

-- these helper functions register all of the recipes needed to create colored
Expand Down

0 comments on commit 2af4f1f

Please sign in to comment.