Lignumis


Dive into the world of Lignumis, a moon of Nauvis offering only the most basic technologies.

Content
a day ago
2.0
15.2K
Factorio: Space Age Icon Space Age Mod
Planets Logistics Environment Mining Fluids Manufacturing

g Custom Belts?

21 days ago

Hello! I'm currently remaking the Black Rubber Belts mod, and I'd like to make it compatible with the wooden belts from Lignumis.
I'm having some trouble here: I can replace the belt animations for regular belts just fine, but for some reason splitter/underground belts still use the grey belt sprites...
(screenshot)

This didn't happen with vanilla belts or other modded belts (bob's). I assume it's due to some functions of MF Logistics.
Could you help me figure out a fix I could add to my mod?

21 days ago

Hey. Could you give me the code you currently have? Maybe I can get it to work.

21 days ago

Sure! Here's what I have in my data.lua, I've removed parts unrelated to the lignumis compat

-- Load auxiliary functions
local IR2RB = require("code.functions")
--Load settings (alt base, arrow glow, belt glow)
local alternate_bases = (settings.startup["rail-style"].value == "ir3-alt")
local arrow_glow = settings.startup["arrow-glow"].value
local belt_glow = settings.startup["rail-glow"].value

-- Define each vanilla belt's parameters (tier color (as a hue), railing material, default arrows)
local belts = {
    ["transport"] = { hue = 0.11, base = alternate_bases and "copper" or "steel", arrows = "arrow" },
    ["fast-transport"] = { hue = 0, base = alternate_bases and "iron" or "steel", arrows = "arrow-doubled" },
    ["express-transport"] = { hue = 0.54, base = "steel", arrows = "arrow-doubled" },
}

-- Add space age compatibility (turbo belts)
if mods["space-age"] then
    belts["turbo-transport"] = { hue = 0.23, base = alternate_bases and "tungsten" or "steel", arrows = "arrow-quadrupled" }
end

-- Lignumis compat
if mods["lignumis"] then
    belts["wood-transport"] = { hue = 0.07, sat = 0.7, val = 0.6, base = alternate_bases and "wood" or "steel", arrows = "arrow" }
end

-- Procedurally generate each belt's new animations
for belt,beltdata in pairs(belts) do

    -- Make belt tint, define arrow type, retrieve belt prototype
    local tint = IR2RB.hsva2rgba(beltdata.hue, beltdata.sat or 0.8, beltdata.val or 1)
    local arrows = (settings.startup["arrow-style"].value ~= "arrows") and settings.startup["arrow-style"].value or beltdata.arrows
    local prototype = data.raw["transport-belt"][belt.."-belt"]

    if prototype then
        -- Change each belt entity's animations
        prototype.belt_animation_set.animation_set = IR2RB.get_belt_animation_set(tint, beltdata.base, arrows, arrow_glow, belt_glow)
        prototype.corpse = "small-remnants"
        -- Change each belt icon, with alt rail texture if enabled
        IR2RB.replace_item_icon(belt.."-belt", "rubber-belt-"..beltdata.base)
        -- Add arrows if there's arrows
        if (settings.startup["arrow-style"].value ~= "no-arrows") then
            IR2RB.add_mask_to_item_icon(belt.."-belt", "rubber-belt-mask", tint, arrow_glow) end
        -- Add colored rails if colored rails is on
        if (settings.startup["rail-style"].value == "colored") then
            IR2RB.add_mask_to_item_icon(belt.."-belt", "rubber-rail-mask", tint, belt_glow) end
        -- Links each new belt's item icon to the belt's entity
        IR2RB.copy_item_icons_to_entity("transport-belt", belt.."-belt")
    end

end

The code uses functions defined in another file functions.lua

-- Compile the entirety of the code in a dictionnary of functions
local F = {}

F.graphics_path = "__black-rubber-belts-remastered__/graphics"
F.icons_path = F.graphics_path .. "/icons"
F.sprites_path = F.graphics_path .. "/entities"
F.setting_icons_path = F.icons_path .. "/settings"

-- Find the file path of an icon in the graphics folder
function F.get_icon_path(name, dir)
    return string.format("%s/%s.png", F.graphics_path .. "/" .. (dir or "icons"), name)
end

-- Replaces old item icon (e.g. belt) with the new one (e.g. rubber belt)
function F.replace_item_icon(item_name, icon, entity_type, entity_name)
    if not icon then icon = item_name end
    local item = data.raw.item[item_name] or data.raw.fluid[item_name] or data.raw.tool[item_name] or data.raw.module[item_name]
    item.icon = F.get_icon_path(icon)
    item.icons = nil
    item.icon_size = 64
    item.icon_mipmaps = 4
    item.pictures = nil
end

-- Adds a mask to an item's icon (e.g. belt arrow, colored railing)
function F.add_mask_to_item_icon(item_name, icon, tint)
    local item = data.raw.item[item_name] or data.raw.fluid[item_name] or data.raw.tool[item_name] or data.raw.module[item_name]
    if item.icons == nil then
        item.icons = item.icon ~= nil and {{icon = item.icon, icon_size = item.icon_size, icon_mipmaps = item.icon_mipmaps }} or {}
    end
    table.insert(item.icons, 
        { icon = F.get_icon_path(icon), icon_size = 64, icon_mipmaps = 4, tint = tint }
    )
end

-- Adds a new icon to an existing entity
function F.copy_item_icons_to_entity(entity_type, name)
    local entity = data.raw[entity_type][name]
    local item = data.raw.item[name]
    if entity and item then
        entity.icon = item.icon
        entity.icon_size = item.icon_size
        entity.icon_mipmaps = item.icon_mipmaps
        entity.icons = item.icons
    end
end

-- Make a single layer of belt animation from a spritesheet, based on its suffix ("base-[]", "arrow-[]", "rails") and frame count.
-- The sprite can be tinted (for arrows or colored railing).
function F.get_belt_animation(suffix,tint,frame_count,repeat_count, glow)
    frame_count = frame_count or 16
    return {
        filename = F.sprites_path.."/rubber-belt-"..suffix..".png",
        priority = "extra-high",
        width = 128,
        height = 128,
        frame_count = frame_count,
        repeat_count = repeat_count,
        direction_count = 20,
        scale = 0.5,
        tint = tint,
        draw_as_glow = glow,
    }
end

-- Make a belt's animation set from the associated tint, base and arrows used.
function F.get_belt_animation_set(tint, base, arrows, arrow_glow, rail_glow)
    local a = arrows
    local frame_arrows = { ["arrow"] = 16, ["arrow-doubled"] = 32, ["arrow-quadrupled"] = 64, ["no-arrows"] = 16 }
    local f = frame_arrows[a] or 16

    local layers = {
        layers = {
            F.get_belt_animation("base-"..base, nil, 8, f/8),
        }
    }
    if settings.startup["arrow-style"].value ~= "no-arrows" then 
        table.insert(layers.layers, F.get_belt_animation(a, tint, f, nil, arrow_glow))
    end
    if settings.startup["rail-style"].value == "colored" then
        table.insert(layers.layers, F.get_belt_animation("rails", tint, 8, f/8, rail_glow))
    end
    return #layers.layers > 1 and layers or layers.layers[1]
end

-- Convert color formats from %HSVa to %RGBa
function F.hsva2rgba(h, s, v, a)
    if a == nil then a = 1 end
    local r, g, b
    local i = math.floor(h * 6);
    local f = h * 6 - i;
    local p = v * (1 - s);
    local q = v * (1 - f * s);
    local t = v * (1 - (1 - f) * s);
    i = i % 6
    if i == 0 then r, g, b = v, t, p
    elseif i == 1 then r, g, b = q, v, p
    elseif i == 2 then r, g, b = p, v, t
    elseif i == 3 then r, g, b = p, q, v
    elseif i == 4 then r, g, b = t, p, v
    elseif i == 5 then r, g, b = v, p, q
    end
    return { r = r, g = g, b = b, a = a }
end

return F
20 days ago
(updated 20 days ago)

Nevermind, I think I found a solution! I just added the following at the end of my data.lua file

-- Lignumis underground & splitter compat
if mods["lignumis"] then
    data.raw["underground-belt"]["wood-underground-belt"].belt_animation_set.animation_set = data.raw["transport-belt"]["wood-transport-belt"].belt_animation_set.animation_set
    data.raw["splitter"]["wood-splitter"].belt_animation_set.animation_set = data.raw["transport-belt"]["wood-transport-belt"].belt_animation_set.animation_set
end

TL;DR: I just needed to replace the belt_animation_sets from the other two things :) Sorry for bothering you, you can close the thread

This thread has been locked.