[2.0] Localisation Problems

Place to get help with not working mods / modding interface.
User avatar
BraveCaperCat
Filter Inserter
Filter Inserter
Posts: 331
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

[2.0] Localisation Problems

Post by BraveCaperCat »

Hi! I'm trying to fix my mod called Quality Assurance to work with my new mod. They both use a custom locale to create new furnaces, and Quality Assurance is creating a new furnace based on one of the new furnaces from the other mod. But, that furnace doesn't have a working locale. (the new furnace based on another new furnace)
Here are some images of the new technology, recipe, item and entity for that furnace - and the missing locale which comes with it:
Screenshot 2024-11-02 151410.png
Screenshot 2024-11-02 151410.png (283.05 KiB) Viewed 197 times
Screenshot 2024-11-02 151331.png
Screenshot 2024-11-02 151331.png (112.05 KiB) Viewed 197 times
Screenshot 2024-11-02 151313.png
Screenshot 2024-11-02 151313.png (116.4 KiB) Viewed 197 times
Screenshot 2024-11-02 151250.png
Screenshot 2024-11-02 151250.png (64.27 KiB) Viewed 197 times
Here is the data-stage code and locales for both mods.
QualityAssurance/data-updates.lua:

Code: Select all

local function config(name)
    return settings.startup['qa_' .. name].value
end

local function AddQuality(Machine)
    -- Increase quality for all machines.
    if not config("moduleless-quality") then
        if Machine.module_slots == nil then
            log("Moduleless Quality setting is disabled, and this machine doesn't have module slots. Skipping.")
            return Machine
        else
            if Machine.module_slots == 0 then
                log("Moduleless Quality setting is disabled, and this machine doesn't have module slots. Skipping.")
                return Machine
            end
        end
    end
    if not config("base-quality") then
        log("Base Quality setting is disabled. Skipping.")
        return Machine
    end
    local BaseQuality = false
    while not BaseQuality do
        if Machine.effect_receiver ~= nil then
            if Machine.effect_receiver.base_effect ~= nil then
                if Machine.effect_receiver.base_effect.quality ~= nil then
                    if Machine.effect_receiver.base_effect.quality == 0 then
                        log("Machine does not contain base quality. Adding base quality.")
                        Machine.effect_receiver.base_effect.quality = config("base-quality-value")
                    else
                        log("Machine contains base quality of amount " .. Machine.effect_receiver.base_effect.quality or 0 ..". Skipping.")
                        BaseQuality = true
                    end
                else
                    log("Machine does not contain base quality. Preparing to add base quality.")
                    Machine.effect_receiver.base_effect.quality = 0
                end
            else
                Machine.effect_receiver.base_effect = {}
            end
            if Machine.effect_receiver.uses_beacon_effects ~= true then
                Machine.effect_receiver.uses_beacon_effects = true
            end
            if Machine.effect_receiver.uses_module_effects ~= true then
                Machine.effect_receiver.uses_module_effects = true
            end
            if Machine.effect_receiver.uses_surface_effects ~= true then
                Machine.effect_receiver.uses_surface_effects = true
            end
        else
            Machine.effect_receiver = {}
        end
    end
    return Machine
end

local function EnableQuality(Machine)
    -- Allow Qualities in all Machines.
    local qualityadded = false
    local hasquality = false
    while not hasquality do
        if Machine.allowed_effects ~= nil then
            if type(Machine.allowed_effects) ~= "string" then
                for _, AllowedEffect in pairs(Machine.allowed_effects) do
                    if AllowedEffect == "quality" then
                        hasquality = true
                    end
                end
                if hasquality == false then
                    table.insert(Machine.allowed_effects, "quality")
                    hasquality = true
                end
            else
                Machine.allowed_effects = {Machine.allowed_effects}
            end
        else
            Machine.allowed_effects = {}
        end
    end
    return Machine
end

-- Add all qualities to the selected Technology, and remove technologies with no effect.
local QualityTechnologyName = config("quality-unlock")
log("Adding Qualities to \"".. QualityTechnologyName .."\" Technology.")
local RemovedTechnologies = {}
for i,Technology in pairs(data.raw["technology"]) do
    log("Scanning Technology \"" .. Technology.name .. "\" now.")
    if Technology.name ~= QualityTechnologyName then
        if Technology.effects ~= nil then
            log("Technology has Effects.")
            for j,Effect in pairs(Technology.effects) do
                log("Scanning Modifier of type \"" .. Effect.type .. "\" now.")
                if Effect.type == "unlock-quality" then
                    log("Effect is a match. Moving Quality Unlock to Automation Technology.")
                    table.insert(data.raw["technology"][QualityTechnologyName].effects, Effect)
                    data.raw["technology"][i].effects[j] = nil
                    log("Effect moved.")
                end
            end
            if Technology.effects == {} or Technology.effects == nil then
                log("All effects of Technology \"" .. Technology.name .. "\" have been removed. Removing Technology.")
                RemovedTechnologies[Technology.name] = Technology
                data.raw["technology"][i] = nil
            end
        end
        for _,RemovedTechnology in pairs(RemovedTechnologies) do
            for n,Prerequisite in pairs(Technology.prerequisites) do
                if RemovedTechnology.name == Prerequisite then
                    table.remove(data.raw["technology"][i].prerequisites[n])
                    for _,RemovedTechnologyPrerequisite in pairs(RemovedTechnology.prerequistites) do
                        table.append(Technology.prerequisites, RemovedTechnologyPrerequisite)
                    end
                end
            end
        end
    end
end

-- Perform operations on automated crafting.
local MachineTypes = {"crafting-machine", "furnace", "assembling-machine"}

log("Performing operations on Automated Crafting.")
for _,MachineType in pairs(MachineTypes) do
    if data.raw[MachineType] ~= nil then
        for j,Machine in pairs(data.raw[MachineType]) do
            log("Scanning Machine \"" .. Machine.name .. "\" now.")
            
            Machine = AddQuality(Machine)

            Machine = EnableQuality(Machine)

            data.raw[MachineType][j] = Machine

            -- Create a new version of all machines which have additional module slots.
            if not string.find(Machine.name, "qa_") then
                log("Creating AMS version of \"" .. Machine.name .. "\" now.")
                AMSMachine = table.deepcopy(Machine)
                AMSMachine.name = "qa_" .. AMSMachine.name .. "-ams"
                if Machine.localised_name ~= nil then
                    AMSMachine.localised_name = {"ams.name", {"?", "__ENTITY__" .. Machine.name .. "__", Machine.localised_name, "ams.fallback-name"}}
                    AMSMachine.localised_description = {"ams.description", {"?", "__ENTITY__" .. Machine.name .. "__", Machine.localised_name, "ams.fallback-description"}}
                else
                    AMSMachine.localised_name = {"ams.name", {"?", "__ENTITY__" .. Machine.name .. "__", "ams.fallback-name"}}
                    AMSMachine.localised_description = {"ams.description", {"?", "__ENTITY__" .. Machine.name .. "__", "ams.fallback-description"}}
                end
                log(serpent.block(Machine))
                if AMSMachine.module_slots ~= nil then
                    AMSMachine.module_slots = AMSMachine.module_slots + 2
                else
                    AMSMachine.module_slots = 2
                end
                AMSMachine.crafting_speed = AMSMachine.crafting_speed * 0.8
                AMSMachine["minable"] = AMSMachine["minable"] or {mining_time = 1}
                AMSMachine.minable.results = nil
                AMSMachine.minable.result = AMSMachine.name
                AMSMachine.minable.count = 1

                AMSMachineItem = table.deepcopy(data.raw["item"][Machine.name])
                AMSMachineItem.name = AMSMachine.name
                AMSMachineItem.type = "item"
                if Machine.localised_name ~= nil then
                    AMSMachineItem.localised_name = {"ams.name", {"?", "__ENTITY__" .. Machine.name .. "__", Machine.localised_name, "ams.fallback-name"}}
                    AMSMachineItem.localised_description = {"ams.description", {"?", "__ENTITY__" .. Machine.name .. "__", Machine.localised_name, "ams.fallback-description"}}
                else
                    AMSMachineItem.localised_name = {"ams.name", {"?", "__ENTITY__" .. Machine.name .. "__", "ams.fallback-name"}}
                    AMSMachineItem.localised_description = {"ams.description", {"?", "__ENTITY__" .. Machine.name .. "__", "ams.fallback-description"}}
                end
                log(serpent.block(Machine))
                AMSMachineItem.stack_size = 50
                AMSMachineItem.place_result = AMSMachine.name
                AMSMachine.MachineItem = AMSMachineItem.name

                AMSMachineRecipe = {}
                AMSMachineRecipe.name = AMSMachineItem.name
                AMSMachineRecipe.type = "recipe"
                if Machine.localised_name ~= nil then
                    AMSMachineRecipe.localised_name = {"ams.name", {"?", "__ENTITY__" .. Machine.name .. "__", Machine.localised_name, "ams.fallback-name"}}
                    AMSMachineRecipe.localised_description = {"ams.description", {"?", "__ENTITY__" .. Machine.name .. "__", Machine.localised_name, "ams.fallback-description"}}
                else
                    AMSMachineRecipe.localised_name = {"ams.name", {"?", "__ENTITY__" .. Machine.name .. "__", "ams.fallback-name"}}
                    AMSMachineRecipe.localised_description = {"ams.description", {"?", "__ENTITY__" .. Machine.name .. "__", "ams.fallback-description"}}
                end
                log(serpent.block(Machine))
                if Machine.MachineItem == nil and Machine.minable ~= nil then
                    if Machine.minable.result ~= nil and Machine.minable.result ~= "" then
                        AMSMachineRecipe.ingredients = {{type = "item", name = Machine.minable.result, amount = 1}, {type = "item", name = "steel-plate", amount = 10}, {type = "item", name = "copper-cable", amount = 20}}
                    else
                        AMSMachineRecipe.ingredients = {{type = "item", name = "electronic-circuit", amount = 1}, {type = "item", name = "steel-plate", amount = 10}, {type = "item", name = "copper-cable", amount = 20}}
                    end
                else
                    AMSMachineRecipe.ingredients = {{type = "item", name = Machine.MachineItem, amount = 1}, {type = "item", name = "steel-plate", amount = 10}, {type = "item", name = "copper-cable", amount = 20}}
                end

                if AMSMachineRecipe.ingredients[1]["name"] == nil then
                    AMSMachineRecipe.ingredients[1]["name"] = "electronic-circuit"
                    log("Had to replace ingredient name for \"" .. AMSMachineRecipe.name .. "\"")
                end

                AMSMachineRecipe.results = {{type = "item", name = AMSMachineItem.name, amount = 1}}
                AMSMachineRecipe.enabled = false
                
                AMSMachineTechnology = table.deepcopy(data.raw["technology"]["automation"])
                AMSMachineTechnology.name = AMSMachine.name
                AMSMachineTechnology.prerequisites = {"steel-processing", "electronics"}
                AMSMachineTechnology.research_trigger = {type = "build-entity", entity = {name = Machine.name}}
                AMSMachineTechnology.effects = {{type = "unlock-recipe", recipe = AMSMachineRecipe.name}}
                AMSMachineTechnology.unit = nil
                if Machine.localised_name ~= nil then
                    AMSMachineTechnology.localised_name = {"ams.tech-name", {"?", "__ENTITY__" .. Machine.name .. "__", Machine.localised_name, "ams.fallback-tech-name"}}
                    AMSMachineTechnology.localised_description = {"ams.tech-description", {"?", "__ENTITY__" .. Machine.name .. "__", Machine.localised_name, "ams.fallback-tech-description"}}
                else
                    AMSMachineTechnology.localised_name = {"ams.tech-name", {"?", "__ENTITY__" .. Machine.name .. "__", "ams.fallback-tech-name"}}
                    AMSMachineTechnology.localised_description = {"ams.tech-description", {"?", "__ENTITY__" .. Machine.name .. "__", "ams.fallback-tech-description"}}
                end
                log(serpent.block(Machine))

                log("Made AMS version of \"" .. Machine.name .. "\".")
                log("Machine: \n" .. serpent.block(AMSMachine) .. "\nItem: \n" .. serpent.block(AMSMachineItem) .. "\nRecipe: \n" .. serpent.block(AMSMachineRecipe) .. "\nTechnology: \n" .. serpent.block(AMSMachineTechnology))
                data:extend{AMSMachine, AMSMachineItem, AMSMachineRecipe, AMSMachineTechnology}
            else
                log("Machine \"" .. Machine.name .. "\" is an AMS machine. Skipping the AMS machine making process.")
            end
        end
    end
end

-- Allow Quality Modules in Beacons.
if config("quality-beacons") then
    for _,Beacon in pairs(data.raw["beacon"]) do
        Beacon = EnableQuality(Beacon)
    end
end

-- Improve power of all quality modules.
log("Improving power of all quality modules.")
for _,Module in pairs(data.raw["module"]) do
    log("Scanning module \"" .. Module.name .. "\" now.")
    if Module.effect.quality ~= nil then
        if Module.effect.quality >= 0 then
            log("Module \"" .. Module.name .. "\" contians a Quality increase. Increasing bonus.")
            Module.effect.quality = Module.effect.quality * config("quality-module-multiplier")
            
        end
    end
end
FastFurnaceRecipes/data.lua:

Code: Select all

local function config(name)
    return settings.startup["ffr_" .. name].value
end

local SpeedMultiplier = config("speed-mult")
local BalanceMode = config("balance-mode")

for _,Furnace in pairs(data.raw["furnace"]) do
    if Furnace ~= nil then
        if BalanceMode then
            if not string.find(Furnace.name, "ffr_") then
                local FastFurnaceItem = {}
                if data.raw["item"][Furnace.name] ~= nil then
                    FastFurnaceItem = table.deepcopy(data.raw["item"][Furnace.name])
                else
                    FastFurnaceItem = {}
                    FastFurnaceItem.stack_size = 50
                    FastFurnaceItem.icon = data.raw["item"]["stone-furnace"].icon
                    FastFurnaceItem.type = "item"
                end
                FastFurnaceItem.name = "ffr_fast-" .. Furnace.name
                FastFurnaceItem.place_result = "ffr_fast-" .. Furnace.name
                FastFurnaceItem.localised_name = {"furnace.name", "__ENTITY__" .. Furnace.name .. "__"}
                FastFurnaceItem.localised_description = {"furnace.description", "__ENTITY__" .. Furnace.name .. "__"}
                local FastFurnaceEntity = table.deepcopy(data.raw["furnace"][Furnace.name])
                FastFurnaceEntity.name = "ffr_fast-" .. Furnace.name
                FastFurnaceEntity.minable.result = nil
                if FastFurnaceEntity.minable.mining_time == nil then
                    FastFurnaceEntity.minable.mining_time = 0.2
                end
                FastFurnaceEntity.minable.results = {{type = "item", name = FastFurnaceItem.name, amount = 1}}
                log(serpent.block(FastFurnaceEntity))
                FastFurnaceEntity.max_health = Furnace.max_health * SpeedMultiplier
                FastFurnaceEntity.crafting_speed = Furnace.max_health * SpeedMultiplier
                FastFurnaceEntity.localised_name = {"furnace.name", "__ENTITY__" .. Furnace.name .. "__"}
                FastFurnaceEntity.localised_description = {"furnace.description", "__ENTITY__" .. Furnace.name .. "__"}
                local FastFurnaceRecipe = {}
                FastFurnaceRecipe.enabled = false
                FastFurnaceRecipe.name = "ffr_fast-" .. Furnace.name
                FastFurnaceRecipe.results = {{type = "item", name = FastFurnaceItem.name, amount = 1}}
                FastFurnaceRecipe.localised_name = {"furnace.name", "__ENTITY__" .. Furnace.name .. "__"}
                FastFurnaceRecipe.localised_description = {"furnace.description", "__ENTITY__" .. Furnace.name .. "__"}
                FastFurnaceRecipe.type = "recipe"
                local MakeFurnaceTechAndRecipe = true
                if data.raw["item"][Furnace.name] ~= nil then
                    FastFurnaceRecipe.ingredients = {{type = "item", name = Furnace.name, amount = SpeedMultiplier}}
                else
                    error("Furnace entity \"" .. Furnace.name .. "\" does not have an item of the same name! Recipe for \"" .. FastFurnaceItem.name .. "\" has been removed.")
                    MakeFurnaceTechAndRecipe = false
                end
                if MakeFurnaceTechAndRecipe then
                    local FastFurnaceTech = table.deepcopy(data.raw["technology"]["advanced-material-processing"])
                    FastFurnaceTech.name = "fft_fast-" .. Furnace.name .. "-tech"
                    FastFurnaceTech.prerequisites = {}
                    FastFurnaceTech.effects = {{type = "unlock-recipe", recipe = FastFurnaceRecipe.name}}
                    FastFurnaceTech.research_trigger = {type = "build-entity", entity = Furnace.name}
                    FastFurnaceTech.localised_name = {"furnace.tech-name", "__ENTITY__" .. Furnace.name .. "__"}
                    FastFurnaceTech.localised_description = {"furnace.tech-description", "__ENTITY__" .. Furnace.name .. "__"}
                    data:extend{FastFurnaceTech, FastFurnaceEntity, FastFurnaceItem, FastFurnaceRecipe}
                else
                    data:extend{FastFurnaceEntity, FastFurnaceItem}
                end
            end
        else
            FurnaceCraftingSpeed = data.raw['furnace']['stone-furnace'].crafting_speed
            data.raw["furnace"][Furnace.name] = FurnaceCraftingSpeed * SpeedMultiplier
        end
    end
end
QualityAssurance/locale/en/mod.cfg:

Code: Select all

[ams]
name=__1__ AMS version
description=Similar to __1__, but with additional module slots. Due to this, the speed of __1__ is lowered.
tech-name=__1__ with additional module slots
tech-description=Allows making a version of __1__ with additional module slots. Because of this, the speed of this machine is lowered.
fallback-name=Unnamed Machine AMS version
fallback-description=Similar to Unnamed Machine, but with additional module slots. Due to this, the speed of Unnamed Machine is lowered.
fallback-tech-name=Unnamed Machine with additional module slots
fallback-tech-description=Allows making a version of Unnamed Machine with additional module slots. Because of this, the speed of this machine is lowered.

[mod-setting-name]
qa_base-quality=Add base quality to machines.
qa_quality-unlock=Choose when to unlock quality.
qa_moduleless-quality=Add quality to machines without module sots.
qa_base-quality-value=The percentage of quality to add to machines.
qa_quality-beacons=Allow quality modules in beacons.
qa_quality-module-multiplier=Multiplier for the effect of quality modules.

[mod-setting-description]
qa_base-quality=If this is on, machines will have a base quality factor.
qa_quality-unlock=The technology selected here will unlock every quality.
qa_moduleless-quality=If this is on, the base quality setting will apply to machines with module slots.
qa_base-quality-value=The value of base quality for machines as a precentage. Only applies if base quality is enabled.
qa_quality-beacons=If this is on, you can put quality modules in beacons.
qa_quality-module-multiplier=The multiplier for the effect of quality modules. Only applies to modules which add positive quality.

[string-mod-setting]
qa_quality-unlock-automation=Automation
qa_quality-unlock-automation-2=Automation 2
qa_quality-unlock-quality-module=Quality Module
qa_quality-unlock-rocket-silo=Rocket silo
qa_quality-unlock-quality-module-2=Quality Module 2
qa_quality-unlock-quality-module-3=Quality Module 3

[string-mod-setting-description]
qa_quality-unlock-automation=Unlocks the Assembling Machine.
qa_quality-unlock-automation-2=Unlocks the Assembling Machine 2.
qa_quality-unlock-quality-module=Unlocks the Quality Module.
qa_quality-unlock-rocket-silo=Unlocks the Rocket Silo.
qa_quality-unlock-quality-module-2=Unlocks the Quality Module 2.
qa_quality-unlock-quality-module-3=Unlocks the Quality Module 3.
FastFurnaceRecipes/locale/en/mod.cfg:

Code: Select all

[mod-setting-name]
ffr_speed-mult=Furnace speed multiplier.
ffr_balance-mode=Enables balance mode.

[mod-setting-description]
ffr_speed-mult=Multiplier for the speed of furnaces.
ffr_balance-mode=Balance mode adds multiple new furnaces instead of changing existing ones.

[furnace]
name=Fast __1__
description=A faster version of the standard __1__. Up to 256 times faster than the standard __1__.
tech-name=Compactized __1__
tech-description=The compactization of __1__. It's the same size, shape and color as a regular __1__, but so much faster! How? I have no idea...
Note that the locales for both mods are correct for all other furnaces added by each mod.
Creator of multiple mods, including Quality Assurance - My most popular one. Expect multiple modding-related questions, answers and other posts.
User avatar
BraveCaperCat
Filter Inserter
Filter Inserter
Posts: 331
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: [2.0] Localisation Problems

Post by BraveCaperCat »

I found out how to fix my mod - well, sort of. When I fixed this issue, the fallback locale activated on every base game machine, from Chemical Plants to Assembling Machine 3s to Foundries!
(Insert images here when they're available)
Creator of multiple mods, including Quality Assurance - My most popular one. Expect multiple modding-related questions, answers and other posts.
User avatar
EvilPLa
Burner Inserter
Burner Inserter
Posts: 19
Joined: Sat Nov 14, 2020 7:26 am
Contact:

Re: [2.0] Localisation Problems

Post by EvilPLa »

I don't see the missing name configured in these locale files.

something like this should fix the missing key

[entity-name]
ffr_fast-electric-furnace=I'm a fast Furnace
I havent lost my mind, it's backed up on tape somewhere.
User avatar
BraveCaperCat
Filter Inserter
Filter Inserter
Posts: 331
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: [2.0][Fixed][User Error?][Topic Of Discussion No More] Localisation Problems

Post by BraveCaperCat »

Kt was already fixed by a user called A.Freeman on the modportal.
Creator of multiple mods, including Quality Assurance - My most popular one. Expect multiple modding-related questions, answers and other posts.
Post Reply

Return to “Modding help”