can't copy vanilla locomotive

Place to get help with not working mods / modding interface.
_Ax_
Burner Inserter
Burner Inserter
Posts: 13
Joined: Tue Jul 23, 2019 1:26 pm
Contact:

can't copy vanilla locomotive

Post by _Ax_ »

Hello, I'm trying to make a little mod and i need to have a copy of the normal locomotive but a little bit more powerful and slower, so I wrote this code:

Code: Select all

--data.lua

--====================================
-- defining shunter loco prototype
local shunterLoco = table.deepcopy(data.raw["locomotive"]["locomotive"]) -- copy the table that defines a loco
shunterLoco.name = "shunter-loco"
shunterLoco.max_speed = 60
shunterLoco.reversing_power_modifier = 1.00

--====================================
-- defining shunter recipe prototype
local shunterLocoRecipe = table.deepcopy(data.raw["recipe"]["locomotive"])
shunterLocoRecipe.name = "shunter-loco-recipe"
shunterLocoRecipe.enabled = true
shunterLocoRecipe.result = shunterLoco.name

--====================================
-- adding those prototypes to the game
data:extend({shunterLoco, shunterLocoRecipe})

Code: Select all

--language.cfg
[item-name]
shunter-loco=Shunter Locomotive

[item-description]
shunter-loco=A locomotive designated to move cars between rail yards.

[entity-name]
shunter-loco=Shunter Locomotive

[entity-description]
shunter-loco=A locomotive designated to move cars between rail yards.
but the thing is that the game keeps crashing on startup with the error

Code: Select all

Item with name 'shunter-loco' does not exist
I don't know what I'm doing wrong, I'm literally copying the vanilla locomotive how can it not exist?
User avatar
Silari
Filter Inserter
Filter Inserter
Posts: 540
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

Re: can't copy vanilla locomotive

Post by Silari »

You haven't defined an item with that name, only an entity and a recipe. They are different things - the entity is the locomotive that's in world, the item is the form that's in your inventory, and the recipe is how you make the item.

You're going to need to copy the item form of the locomotive and change it for your needs, the same as you did for the entity.

At the very least, something like

Code: Select all

local shunterLocoItem = table.deepcopy(data.raw["item-with-entity-data"]["locomotive"])
shunterLocoItem.name = shunterLoco.name
shunterLocoItem.placeresult = shunterLoco.name
and add shunterLocoItem to your data:extend call.

Names might not be correct, working off the top of my head and a quick look at data.raw

Also, I think you need to edit the "minable" property of shunterLoco, as by copying the locomotive it'll be set to return a locomotive instead of your new item when you mine it.
Post Reply

Return to “Modding help”