Modding Barrel Graphics

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
User avatar
landmine752
Inserter
Inserter
Posts: 26
Joined: Sun Nov 19, 2017 3:35 am
Contact:

Modding Barrel Graphics

Post by landmine752 »

Hey everyone,

I've been trying to change the graphics of a number of the vanilla item icons - including fluids and barrels. Fluids were easy enough, but I'm having a difficult time with switching the graphics for barrels, specifically the recipes.

The barrel icons are working as intended, but the barrels in the barreling recipes are not (the fluid icons in them do update, however). I've checked through the game's files to find a reference to the barreling recipes, or any other barrel graphics, but I've only found the empty-barrel item references plus the barrel code in data-updates.lua

Here's some reference images.
Image

Image


Anyone have ideas on where to find where the barreling recipe icons are loading from?

User avatar
Arch666Angel
Smart Inserter
Smart Inserter
Posts: 1636
Joined: Sun Oct 18, 2015 11:52 am
Contact:

Re: Modding Barrel Graphics

Post by Arch666Angel »

Take a look at base/data-updates.lua barrels are generated there

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Modding Barrel Graphics

Post by darkfrei »

See also Bottled Fluids

Image

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: Modding Barrel Graphics

Post by Deadlock989 »

landmine752 wrote:
Tue Oct 08, 2019 2:33 am
I've checked through the game's files to find a reference to the barreling recipes, or any other barrel graphics, but I've only found the empty-barrel item references plus the barrel code in data-updates.lua

Anyone have ideas on where to find where the barreling recipe icons are loading from?
See the functions generate_fill_barrel_icons and generate_empty_barrel_icons in base/data-updates.lua. If you want/need to override these recipe icons, you have to do it in your own mod's data-updates.lua or later.
Image

User avatar
landmine752
Inserter
Inserter
Posts: 26
Joined: Sun Nov 19, 2017 3:35 am
Contact:

Re: Modding Barrel Graphics

Post by landmine752 »

Deadlock989 wrote:
Tue Oct 08, 2019 9:25 am
landmine752 wrote:
Tue Oct 08, 2019 2:33 am
I've checked through the game's files to find a reference to the barreling recipes, or any other barrel graphics, but I've only found the empty-barrel item references plus the barrel code in data-updates.lua

Anyone have ideas on where to find where the barreling recipe icons are loading from?
See the functions generate_fill_barrel_icons and generate_empty_barrel_icons in base/data-updates.lua. If you want/need to override these recipe icons, you have to do it in your own mod's data-updates.lua or later.
Thanks for the tip. I created a new data-updates.lua for my mod and added in same code (but with references to my mod's graphics) to override the base code. However, it didn't do anything.
Then, I tried renaming all the functions (with the theory that, if I cannot replace functions, I can run new functions to replace existing icons). However, they still don't override the base game's barrel fill/empty icons. I know the functions execute since the game responds to any intentional errors I make (like syntax errors, which my previous method would ignore).

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: Modding Barrel Graphics

Post by Deadlock989 »

landmine752 wrote:
Wed Oct 09, 2019 12:12 am
Thanks for the tip. I created a new data-updates.lua for my mod and added in same code (but with references to my mod's graphics) to override the base code. However, it didn't do anything.
Then, I tried renaming all the functions (with the theory that, if I cannot replace functions, I can run new functions to replace existing icons). However, they still don't override the base game's barrel fill/empty icons. I know the functions execute since the game responds to any intentional errors I make (like syntax errors, which my previous method would ignore).
If you post the code, someone can look at it and maybe diagnose a problem. Otherwise, they would be guessing, and most likely guessing wrong.
Image

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Modding Barrel Graphics

Post by eradicator »

landmine752 wrote:
Wed Oct 09, 2019 12:12 am
I know the functions execute since the game responds to any intentional errors I make (like syntax errors, which my previous method would ignore).
No you don't. Syntax errors do not indicate execution. Use something like this instead.

Code: Select all

error('Stopping here') 
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
landmine752
Inserter
Inserter
Posts: 26
Joined: Sun Nov 19, 2017 3:35 am
Contact:

Re: Modding Barrel Graphics

Post by landmine752 »

Deadlock989 wrote:
Wed Oct 09, 2019 10:43 am
landmine752 wrote:
Wed Oct 09, 2019 12:12 am
Thanks for the tip. I created a new data-updates.lua for my mod and added in same code (but with references to my mod's graphics) to override the base code. However, it didn't do anything.
Then, I tried renaming all the functions (with the theory that, if I cannot replace functions, I can run new functions to replace existing icons). However, they still don't override the base game's barrel fill/empty icons. I know the functions execute since the game responds to any intentional errors I make (like syntax errors, which my previous method would ignore).
If you post the code, someone can look at it and maybe diagnose a problem. Otherwise, they would be guessing, and most likely guessing wrong.
Here's the code, it's basically the data-updates.lua code. I changed all references to base game functions/variables to ensure nothing conflicted with the base game (aside form the actual icons I'm trying to replace), though it probably doesn't matter.

Code: Select all

-- data-updates.lua code for GraphicsMod
-- This auto-generates barrel items and fill/empty recipes for every fluid defined that doesn't have "auto_barrel = false".

-- The technology the barrel unlocks will be added to
local technology_name = "fluid-handling"

-- The base empty barrel item
local empty_newbarrel_name = "empty-barrel"

-- Item icon masks
local newbarrel_side_mask = "__GraphicsMod__/graphics/icons/fluid/barreling/barrel-side-mask.png"
local newbarrel_hoop_top_mask = "__GraphicsMod__/graphics/icons/fluid/barreling/barrel-hoop-top-mask.png"

-- Recipe icon masks
local newbarrel_empty_side_mask = "__GraphicsMod__/graphics/icons/fluid/barreling/barrel-empty-side-mask.png"
local newbarrel_empty_top_mask = "__GraphicsMod__/graphics/icons/fluid/barreling/barrel-empty-top-mask.png"
local newbarrel_fill_side_mask = "__GraphicsMod__/graphics/icons/fluid/barreling/barrel-fill-side-mask.png"
local newbarrel_fill_top_mask = "__GraphicsMod__/graphics/icons/fluid/barreling/barrel-fill-top-mask.png"

-- Alpha used for barrel masks
local side_alpha = 0.75
local top_hoop_alpha = 0.75
-- Fluid required per barrel recipe
local fluid_per_barrel = 50
-- Crafting energy per barrel fill recipe
local energy_per_fill = 0.2
-- Crafting energy per barrel empty recipe
local energy_per_empty = 0.2

local function get_technology(name)
  local technologies = data.raw["technology"]
  if technologies then
    return technologies[name]
  end
  return nil
end

local function get_item(name)
  local items = data.raw["item"]
  if items then
    return items[name]
  end
  return nil
end

local function get_recipes_for_newbarrel(name)
  local recipes = data.raw["recipe"]
  if recipes then
    return recipes["fill-" .. name], recipes["empty-" .. name]
  end
  return nil
end

-- Generates the icons definition for a barrel item with the provided name and fluid definition using the provided empty barrel base icon
local function generate_newbarrel_item_icons(fluid, empty_newbarrel_item)
  local side_tint = util.table.deepcopy(fluid.base_color)
  side_tint.a = side_alpha
  local top_hoop_tint = util.table.deepcopy(fluid.flow_color)
  top_hoop_tint.a = top_hoop_alpha

  return
  {
    {
      icon = empty_newbarrel_item.icon
    },
    {
      icon =  newbarrel_side_mask,
      tint = side_tint
    },
    {
      icon = newbarrel_hoop_top_mask,
      tint = top_hoop_tint
    }
  }
end

-- Generates a barrel item with the provided name and fluid definition using the provided empty barrel stack size
local function create_newbarrel_item(name, fluid, empty_newbarrel_item)
  local result =
  {
    type = "item",
    name = name,
    localised_name = {"item-name.filled-barrel", fluid.localised_name or {"fluid-name." .. fluid.name}},
    icons = generate_newbarrel_item_icons(fluid, empty_newbarrel_item),
    icon_size = 32,
    subgroup = "fill-barrel",
    order = "b[" .. name .. "]",
    stack_size = empty_newbarrel_item.stack_size
  }

  data:extend({result})
  return result
end

local function get_or_create_newbarrel_item(name, fluid, empty_newbarrel_item)
  local existing_item = get_item(name)
  if existing_item then
    return existing_item
  end

  return create_newbarrel_item(name, fluid, empty_newbarrel_item)
end

-- Generates the icons definition for a fill-barrel recipe with the provided barrel name and fluid definition
local function generate_fill_newbarrel_icons(fluid)

  local side_tint = util.table.deepcopy(fluid.base_color)
  side_tint.a = side_alpha
  local top_hoop_tint = util.table.deepcopy(fluid.flow_color)
  top_hoop_tint.a = top_hoop_alpha

  local icons =kk
  {
    {
      icon = "__GraphicsMod__/graphics/icons/fluid/barreling/barrel-fill.png",
      icon_size = 32
    },
    {
      icon = newbarrel_fill_side_mask,
      icon_size = 32,
      tint = side_tint
    },
    {
      icon = newbarrel_fill_top_mask,
      icon_size = 32,
      tint = top_hoop_tint
    }
  }

  if fluid.icon and fluid.icon_size then
    table.insert(icons,
    {
      icon = fluid.icon,
      icon_size = fluid.icon_size,
      scale = 16.0 / fluid.icon_size, -- scale = 0.5 * 32 / icon_size simplified
      shift = {4, -8}
    }
    )
  elseif fluid.icons then
    icons = util.combine_icons(icons, fluid.icons, {scale = 0.5, shift = {4, -8}})
  end

  return icons
end

-- Generates the icons definition for a empty-barrel recipe with the provided barrel name and fluid definition
local function generate_empty_newbarrel_icons(fluid)
  local side_tint = util.table.deepcopy(fluid.base_color)
  side_tint.a = side_alpha
  local top_hoop_tint = util.table.deepcopy(fluid.flow_color)
  top_hoop_tint.a = top_hoop_alpha

  local icons =
  {
    {
      icon = "__GraphicsMod__/graphics/icons/fluid/barreling/barrel-empty.png",
      icon_size = 32
    },
    {
      icon = newbarrel_empty_side_mask,
      icon_size = 32,
      tint = side_tint
    },
    {
      icon = newbarrel_empty_top_mask,
      icon_size = 32,
      tint = top_hoop_tint
    }
  }
  if fluid.icon and fluid.icon_size then
    table.insert(icons,
    {
      icon = fluid.icon,
      icon_size = fluid.icon_size,
      scale = 16.0 / fluid.icon_size,
      shift = {7, 8}
    }
    )
  elseif fluid.icons then
    icons = util.combine_icons(icons, fluid.icons, {scale = 0.5, shift = {7, 8}})
  end

  return icons
end

-- Creates a recipe to fill the provided barrel item with the provided fluid
local function create_fill_newbarrel_recipe(item, fluid)
  local recipe =
  {
    type = "recipe",
    name = "fill-" .. item.name,
    localised_name = {"recipe-name.fill-barrel", fluid.localised_name or {"fluid-name." .. fluid.name}},
    category = "crafting-with-fluid",
    energy_required = energy_per_fill,
    subgroup = "fill-barrel",
    order = "b[fill-" .. item.name .. "]",
    enabled = false,
    icons = generate_fill_newbarrel_icons(fluid),
    icon_size = 32,
    ingredients =
    {
      {type = "fluid", name = fluid.name, amount = fluid_per_barrel, catalyst_amount = fluid_per_barrel},
      {type = "item", name = empty_newbarrel_name, amount = 1, catalyst_amount = 1}
    },
    results=
    {
      {type = "item", name = item.name, amount = 1, catalyst_amount = 1}
    },
    allow_decomposition = false
  }

  data:extend({recipe})
  return recipe
end

-- Creates a recipe to empty the provided full barrel item producing the provided fluid
local function create_empty_newbarrel_recipe(item, fluid)
  local recipe =
  {
    type = "recipe",
    name = "empty-" .. item.name,
    localised_name = {"recipe-name.empty-filled-barrel", fluid.localised_name or {"fluid-name." .. fluid.name}},
    category = "crafting-with-fluid",
    energy_required = energy_per_empty,
    subgroup = "empty-barrel",
    order = "c[empty-" .. item.name .. "]",
    enabled = false,
    icons = generate_empty_newbarrel_icons(fluid),
    icon_size = 32,
    ingredients =
    {
      {type = "item", name = item.name, amount = 1, catalyst_amount = 1}
    },
    results=
    {
      {type = "fluid", name = fluid.name, amount = fluid_per_barrel, catalyst_amount = fluid_per_barrel},
      {type = "item", name = empty_newbarrel_name, amount = 1, catalyst_amount = 1}
    },
    allow_decomposition = false
  }

  data:extend({recipe})
  return recipe
end

local function get_or_create_newbarrel_recipes(item, fluid)
  local fill_recipe, empty_recipe = get_recipes_for_newbarrel(item.name)

  if not fill_recipe then
    fill_recipe = create_fill_newbarrel_recipe(item, fluid)
  end
  if not empty_recipe then
    empty_recipe = create_empty_newbarrel_recipe(item, fluid)
  end

  return fill_recipe, empty_recipe
end

-- Adds the provided barrel recipe and fill/empty recipes to the technology as recipe unlocks if they don't already exist
local function add_newbarrel_to_technology(fill_recipe, empty_recipe, technology)
  local unlock_key = "unlock-recipe"
  local effects = technology.effects

  if not effects then
    technology.effects = {}
    effects = technology.effects
  end

  local add_fill_recipe = true
  local add_empty_recipe = true

  for k,v in pairs(effects) do
    if k == unlock_key then
      local recipe = v.recipe
      if recipe == fill_recipe.name then
        add_fill_recipe = false
      elseif recipe == empty_recipe.name then
        add_empty_recipe = false
      end
    end
  end

  if add_fill_recipe then
    table.insert(effects, {type = unlock_key, recipe = fill_recipe.name})
  end
  if add_empty_recipe then
    table.insert(effects, {type = unlock_key, recipe = empty_recipe.name})
  end
end

local function log_newbarrel_error(string)
  log("Auto barrel generation is disabled: " .. string .. ".")
end

local function can_process_fluids(fluids, technology, empty_newbarrel_item)

  if not fluids then
    log_newbarrel_error("there are no fluids")
    return
  end

  if not technology then
    log_newbarrel_error("the " .. technology_name .. " technology doesn't exist")
    return
  end

  if not empty_newbarrel_item then
    log_newbarrel_error("the " .. empty_newbarrel_name .. " item doesn't exist")
    return
  end

  if not empty_newbarrel_item.icon then
    log_newbarrel_error("the " .. empty_newbarrel_name .. " item singular-icon definition doesn't exist")
    return
  end

  return true
end

local function process_newfluid(fluid, technology, empty_newbarrel_item)

  -- Allow fluids to opt-out
  if fluid.auto_barrel == false then return end

  if not (fluid.icon or fluid.icons) then
    log("Can't make barrel recipe for "..fluid.name..", it doesn't have any icon or icons.")
    return
  end

  local barrel_name = fluid.name .. "-barrel"

  -- check if a barrel already exists for this fluid if not - create one
  local barrel_item = get_or_create_newbarrel_item(barrel_name, fluid, empty_newbarrel_item)

  -- check if the barrel has a recipe if not - create one
  local barrel_fill_recipe, barrel_empty_recipe = get_or_create_newbarrel_recipes(barrel_item, fluid)

  -- check if the barrel recipe exists in the unlock list of the technology if not - add it
  add_newbarrel_to_technology(barrel_fill_recipe, barrel_empty_recipe, technology)

end

local function process_newfluids(fluids, technology, empty_newbarrel_item)

  if not can_process_fluids(fluids, technology, empty_newbarrel_item) then return end

  for name, fluid in pairs(fluids) do
    process_newfluid(fluid, technology, empty_newbarrel_item)
  end

end

process_newfluids(data.raw["fluid"], get_technology(technology_name), get_item(empty_newbarrel_name))
eradicator wrote:
Wed Oct 09, 2019 12:07 pm
landmine752 wrote:
Wed Oct 09, 2019 12:12 am
I know the functions execute since the game responds to any intentional errors I make (like syntax errors, which my previous method would ignore).
No you don't. Syntax errors do not indicate execution. Use something like this instead.

Code: Select all

error('Stopping here') 
I tried adding this code in a number of locations, and unless it was outside any defined function (or it created a syntax error), nothing would happen. So, I guess my code isn't actually running the functions I call. I used the same code I included in this post.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Modding Barrel Graphics

Post by darkfrei »

landmine752 wrote:
Wed Oct 09, 2019 11:06 pm
I tried adding this code in a number of locations, and unless it was outside any defined function (or it created a syntax error), nothing would happen. So, I guess my code isn't actually running the functions I call. I used the same code I included in this post.
Did you try the code from the suggested mod?

User avatar
landmine752
Inserter
Inserter
Posts: 26
Joined: Sun Nov 19, 2017 3:35 am
Contact:

Re: Modding Barrel Graphics

Post by landmine752 »

darkfrei wrote:
Thu Oct 10, 2019 1:06 pm
Did you try the code from the suggested mod?
I've been playing around with it. It will create new items using the new icons perfectly fine, but that's what the mod does. Nothing surprising there.

However, it was helpful in trying to deconstruct how the barrel icons work. In all my attempts, I can successfully create new, almost identical barrels, but still cannot change the graphics of the existing.
Image

As soon as the new item is identical to existing barrels, the new item will not generate and the old barrel will have not changed. The only reason the steam barrel still appears is because it's from the mod's code only - not a default item.
Image

As a test just to see if I could, I tried changing the icons just as you would any other. The results were not successful: when listed in a "prototypes" file with the rest of the icons, the game does not recognize the item and causes an error message. When added to the end of the mod's "data-updates" file, there are no errors but nothing will change.

Code: Select all

data.raw.item["water-barrel"].icon = "__GraphicsMod__/graphics/icons/transport-belt.png"
data.raw.recipe["empty-water-barrel"].icon = "__GraphicsMod__/graphics/icons/transport-belt.png"
I really don't understand what about the barrel code makes it impossible to change the icon graphics.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: Modding Barrel Graphics

Post by Deadlock989 »

landmine752 wrote:
Sat Oct 12, 2019 7:37 pm

Code: Select all

data.raw.item["water-barrel"].icon = "__GraphicsMod__/graphics/icons/transport-belt.png"
data.raw.recipe["empty-water-barrel"].icon = "__GraphicsMod__/graphics/icons/transport-belt.png"
I really don't understand what about the barrel code makes it impossible to change the icon graphics.
The filled barrel items and barrelling recipe icons don't use icon, they use icons. icon is ignored by the game engine if icons is defined.

Code from one of my mod's data-updates.lua:

Code: Select all

for _,fluid in pairs(data.raw.fluid) do
	if data.raw.recipe["empty-"..fluid.name.."-barrel"] then
		data.raw.recipe["empty-"..fluid.name.."-barrel"].icons = {
			{
				icon = get_icon_path("blank",DIR.icon_size),
				icon_size = DIR.icon_size,
			},
			{
				icon = fluid.icon,
				icon_size = fluid.icon_size,
				scale = 0.25 * (64/fluid.icon_size),
				shift = {2,8},
			},
			{
				icon = get_icon_path("barrel-empty",DIR.icon_size),
				icon_size = DIR.icon_size,
			},
			{
				icon = get_icon_path("barrel-empty-mask",DIR.icon_size),
				icon_size = DIR.icon_size,
				tint = fade(fluid.base_color),
			},
		}
		data.raw.recipe["empty-"..fluid.name.."-barrel"].order = fluid.order
		data.raw.recipe["fill-"..fluid.name.."-barrel"].icons = {
			{
				icon = get_icon_path("barrel-fill",DIR.icon_size),
				icon_size = DIR.icon_size,
			},
			{
				icon = get_icon_path("barrel-fill-mask",DIR.icon_size),
				icon_size = DIR.icon_size,
				tint = fade(fluid.base_color),
			},
			{
				icon = fluid.icon,
				icon_size = fluid.icon_size,
				scale = 0.25 * (64/fluid.icon_size),
				shift = {0,-8},
			},
		}
		data.raw.item[fluid.name.."-barrel"].icons = {
			{
				icon = get_icon_path("empty-barrel",DIR.icon_size),
				icon_size = DIR.icon_size,
			},
			{
				icon = get_icon_path("barrel-mask",DIR.icon_size),
				icon_size = DIR.icon_size,
				tint = fade(fluid.base_color),
			},
		}
		data.raw.recipe["fill-"..fluid.name.."-barrel"].order = fluid.order
	end
end
See https://wiki.factorio.com/Types/IconSpecification
Image

User avatar
landmine752
Inserter
Inserter
Posts: 26
Joined: Sun Nov 19, 2017 3:35 am
Contact:

Re: Modding Barrel Graphics

Post by landmine752 »

Deadlock989 wrote:
Sat Oct 12, 2019 7:51 pm
landmine752 wrote:
Sat Oct 12, 2019 7:37 pm

Code: Select all

data.raw.item["water-barrel"].icon = "__GraphicsMod__/graphics/icons/transport-belt.png"
data.raw.recipe["empty-water-barrel"].icon = "__GraphicsMod__/graphics/icons/transport-belt.png"
I really don't understand what about the barrel code makes it impossible to change the icon graphics.
The filled barrel items and barrelling recipe icons don't use icon, they use icons. icon is ignored by the game engine if icons is defined.

Code from one of my mod's data-updates.lua:

Code: Select all

for _,fluid in pairs(data.raw.fluid) do
	if data.raw.recipe["empty-"..fluid.name.."-barrel"] then
		data.raw.recipe["empty-"..fluid.name.."-barrel"].icons = {
			{
				icon = get_icon_path("blank",DIR.icon_size),
				icon_size = DIR.icon_size,
			},
			{
				icon = fluid.icon,
				icon_size = fluid.icon_size,
				scale = 0.25 * (64/fluid.icon_size),
				shift = {2,8},
			},
			{
				icon = get_icon_path("barrel-empty",DIR.icon_size),
				icon_size = DIR.icon_size,
			},
			{
				icon = get_icon_path("barrel-empty-mask",DIR.icon_size),
				icon_size = DIR.icon_size,
				tint = fade(fluid.base_color),
			},
		}
		data.raw.recipe["empty-"..fluid.name.."-barrel"].order = fluid.order
		data.raw.recipe["fill-"..fluid.name.."-barrel"].icons = {
			{
				icon = get_icon_path("barrel-fill",DIR.icon_size),
				icon_size = DIR.icon_size,
			},
			{
				icon = get_icon_path("barrel-fill-mask",DIR.icon_size),
				icon_size = DIR.icon_size,
				tint = fade(fluid.base_color),
			},
			{
				icon = fluid.icon,
				icon_size = fluid.icon_size,
				scale = 0.25 * (64/fluid.icon_size),
				shift = {0,-8},
			},
		}
		data.raw.item[fluid.name.."-barrel"].icons = {
			{
				icon = get_icon_path("empty-barrel",DIR.icon_size),
				icon_size = DIR.icon_size,
			},
			{
				icon = get_icon_path("barrel-mask",DIR.icon_size),
				icon_size = DIR.icon_size,
				tint = fade(fluid.base_color),
			},
		}
		data.raw.recipe["fill-"..fluid.name.."-barrel"].order = fluid.order
	end
end
See https://wiki.factorio.com/Types/IconSpecification
Awesome! I was trying to find a link like that with this sort of information. I've used your code snippet to get started and I'm actually getting somewhere.

Image
Still some extra code to sift through (which is clearly because I just copy and pasted the code snippet), but at least now I know what I'm dealing with. Thanks for the link.

Code thus far:

Code: Select all

local mod_name = "__GraphicsMod__"
local fluid_path = mod_name .. "/graphics/icons/fluid/"
local barreling_path = fluid_path .. "barreling/"
local side_alpha = 0.75
local top_alpha = 0.75

for _,fluid in pairs(data.raw.fluid) do
  
  local side_tint = util.table.deepcopy(fluid.base_color)
  side_tint.a = side_alpha
  local top_hoop_tint = util.table.deepcopy(fluid.flow_color)
  top_hoop_tint.a = top_hoop_alpha
	
	if data.raw.recipe["empty-"..fluid.name.."-barrel"] then
		data.raw.recipe["empty-"..fluid.name.."-barrel"].icons = {
			{
				icon = barreling_path .. "barrel-empty.png",
				icon_size = 32,
			},
			{
				icon = fluid.icon,
				icon_size = fluid.icon_size,
				scale = 0.5,
				shift = {2,8},
			},
			{
				icon = barreling_path .. "barrel-empty-side-mask.png",
				icon_size = 32,
			},
			{
				icon = fluid_path .. fluid.name .. ".png",
				icon_size = 32,
				scale = 0.5,
				tint = top_hoop_tint,
				shift = {7, 8}
			},
		}
		data.raw.recipe["fill-"..fluid.name.."-barrel"].icons = {
			{
				icon = barreling_path .. "barrel-fill.png",
				icon_size = 32,
			},
			{
				icon = barreling_path .. "barrel-fill-side-mask.png",
				icon_size = 32,
				tint = side_tint,
			},
			{
				icon = fluid.icon,
				icon_size = fluid.icon_size,
				scale = 0.5,
				shift = {0,-8},
			},
		}
		data.raw.item[fluid.name.."-barrel"].icons = {
			{
				icon = barreling_path .. "barrel-fill.png",
				icon_size = 32,
			},
			{
				icon = barreling_path .. "barrel-fill-side-mask.png",
				icon_size = 32,
				tint = side_tint,
			},
		}
	end
end

Post Reply

Return to “Modding discussion”