mirror of
https://github.com/mt-mods/unifieddyes.git
synced 2024-11-22 23:43:45 +01:00
separate the make-colored-itemstack code into its own function
This commit is contained in:
parent
731c7d133e
commit
a8caed8195
17
init.lua
17
init.lua
@ -154,6 +154,16 @@ end
|
|||||||
function unifieddyes.after_dig_node(foo)
|
function unifieddyes.after_dig_node(foo)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- This helper function mostly by juhdanad, creates a colored itemstack
|
||||||
|
|
||||||
|
function unifieddyes.make_colored_itemstack(itemstack, palette, color)
|
||||||
|
local paletteidx = unifieddyes.getpaletteidx(color, palette)
|
||||||
|
local stack = ItemStack(itemstack)
|
||||||
|
stack:get_meta():set_int("palette_index", paletteidx)
|
||||||
|
stack:get_meta():set_string("dye", color)
|
||||||
|
return stack:to_string()
|
||||||
|
end
|
||||||
|
|
||||||
-- this helper function registers all of the recipes needed to create colored
|
-- this helper function registers all of the recipes needed to create colored
|
||||||
-- blocks with any of the dyes supported by that block's palette.
|
-- blocks with any of the dyes supported by that block's palette.
|
||||||
|
|
||||||
@ -179,7 +189,6 @@ function unifieddyes.register_color_craft(craft)
|
|||||||
for _,val in ipairs(vals_table) do
|
for _,val in ipairs(vals_table) do
|
||||||
|
|
||||||
local color = "dye:"..val..hue[1]..sat
|
local color = "dye:"..val..hue[1]..sat
|
||||||
local paletteidx = unifieddyes.getpaletteidx(color, craft.palette)
|
|
||||||
local newrecipe = table.copy(craft.recipe)
|
local newrecipe = table.copy(craft.recipe)
|
||||||
|
|
||||||
for k, item in ipairs(newrecipe) do
|
for k, item in ipairs(newrecipe) do
|
||||||
@ -187,10 +196,8 @@ function unifieddyes.register_color_craft(craft)
|
|||||||
if item == "NEUTRAL_NODE" then newrecipe[k] = craft.neutral_node end
|
if item == "NEUTRAL_NODE" then newrecipe[k] = craft.neutral_node end
|
||||||
end
|
end
|
||||||
|
|
||||||
local stack = ItemStack(craft.output)
|
local colorized_itemstack =
|
||||||
stack:get_meta():set_int("palette_index", paletteidx)
|
unifieddyes.make_colored_itemstack(craft.output, craft.palette, color)
|
||||||
stack:get_meta():set_string("dye", color)
|
|
||||||
local colorized_itemstack = stack:to_string()
|
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = colorized_itemstack,
|
output = colorized_itemstack,
|
||||||
|
Loading…
Reference in New Issue
Block a user