Custom recipe category is showing in player inventory
-
- Inserter
- Posts: 38
- Joined: Sun Apr 16, 2017 1:54 pm
- Contact:
Custom recipe category is showing in player inventory
I created custom recipe category and then assigned it to my recipes and a custom assembling machine. My custom assembling machine are only showing recipes from this category and normal assembling machine is not showing my recipe category, this it good. But player inventory is showing recipes for my custom recipe category too and I dont want this. Can someone help me?
Sorry for my bad english, english is not my native language.
Sorry for my bad english, english is not my native language.
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: Custom recipe category is showing in player inventory
This is normal. you'll probably notice things like oil processing and stuff made in chemical plants also appears on the crafting menu, even though they specifically need to be made in the oil refinery and chemical plant.
You won't be able to hand craft it, but if you point to it, a tooltip should pop up saying "Made in" and show an image of your new factory's icon.
It's your job to put it in an appropriate section of the player's crafting menu.
You won't be able to hand craft it, but if you point to it, a tooltip should pop up saying "Made in" and show an image of your new factory's icon.
It's your job to put it in an appropriate section of the player's crafting menu.
-
- Inserter
- Posts: 38
- Joined: Sun Apr 16, 2017 1:54 pm
- Contact:
Re: Custom recipe category is showing in player inventory
Oh yes thanks, but for later purposes can I add my own recipe category to player?bobingabout wrote:This is normal. you'll probably notice things like oil processing and stuff made in chemical plants also appears on the crafting menu, even though they specifically need to be made in the oil refinery and chemical plant.
You won't be able to hand craft it, but if you point to it, a tooltip should pop up saying "Made in" and show an image of your new factory's icon.
It's your job to put it in an appropriate section of the player's crafting menu.
Re: Custom recipe category is showing in player inventory
yes you can, that's what most mods doesMineGame159 wrote:Oh yes thanks, but for later purposes can I add my own recipe category to player?bobingabout wrote:This is normal. you'll probably notice things like oil processing and stuff made in chemical plants also appears on the crafting menu, even though they specifically need to be made in the oil refinery and chemical plant.
You won't be able to hand craft it, but if you point to it, a tooltip should pop up saying "Made in" and show an image of your new factory's icon.
It's your job to put it in an appropriate section of the player's crafting menu.
create subgroup (for example "my crafting recipes"), assign it icon, put all your recipes into that subgroup and they will appear in there
i also suggest to assign same subgroup to item protypes (eg. results of your recipes), that way players will have easier way finding your products in logistic signal menu.
IMO having items in same group on craft menu and signal menu is good.
-
- Inserter
- Posts: 38
- Joined: Sun Apr 16, 2017 1:54 pm
- Contact:
Re: Custom recipe category is showing in player inventory
Sorry I meant I have all my items and recipes in subgroup but when it have my own recipe category it cannot be crafted in hand.mexmer wrote:yes you can, that's what most mods doesMineGame159 wrote:Oh yes thanks, but for later purposes can I add my own recipe category to player?bobingabout wrote:This is normal. you'll probably notice things like oil processing and stuff made in chemical plants also appears on the crafting menu, even though they specifically need to be made in the oil refinery and chemical plant.
You won't be able to hand craft it, but if you point to it, a tooltip should pop up saying "Made in" and show an image of your new factory's icon.
It's your job to put it in an appropriate section of the player's crafting menu.
create subgroup (for example "my crafting recipes"), assign it icon, put all your recipes into that subgroup and they will appear in there
i also suggest to assign same subgroup to item protypes (eg. results of your recipes), that way players will have easier way finding your products in logistic signal menu.
IMO having items in same group on craft menu and signal menu is good.
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Custom recipe category is showing in player inventory
table.insert(data.raw.player.player.crafting_categories,'your-crafting-category')MineGame159 wrote: Sorry I meant I have all my items and recipes in subgroup but when it have my own recipe category it cannot be crafted in hand.
-
- Inserter
- Posts: 38
- Joined: Sun Apr 16, 2017 1:54 pm
- Contact:
Re: Custom recipe category is showing in player inventory
Thankseradicator wrote:table.insert(data.raw.player.player.crafting_categories,'your-crafting-category')
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: Custom recipe category is showing in player inventory
although that works, it is incomplete, because it doesn't take into account player entities added by other mods (such as my bobclasses), or the god controller.eradicator wrote:table.insert(data.raw.player.player.crafting_categories,'your-crafting-category')MineGame159 wrote: Sorry I meant I have all my items and recipes in subgroup but when it have my own recipe category it cannot be crafted in hand.
instead, you should iterate through all data.raw.player entities, and add your new category.
a function that does what you need that you can use is quoted below.
Code: Select all
function add_crafting_category_to_entity_type(entity_type, category)
for i, entity in pairs(data.raw[entity_type]) do
if not entity.crafting_categories then
entity.crafting_categories = {category}
else
table.insert(entity.crafting_categories, category)
end
end
end
You will need to call this function on entity types player, and god-controller, as follows:
Code: Select all
add_crafting_category_to_entity_type("player", "your-category")
add_crafting_category_to_entity_type("god-controller", "your-category")
-
- Inserter
- Posts: 38
- Joined: Sun Apr 16, 2017 1:54 pm
- Contact:
Re: Custom recipe category is showing in player inventory
Oh I didn't realize that, thanks for post.bobingabout wrote: although that works, it is incomplete, because it doesn't take into account player entities added by other mods (such as my bobclasses), or the god controller.
instead, you should iterate through all data.raw.player entities, and add your new category.
a function that does what you need that you can use is quoted below.The reason to use a function, is because you'll be doing the same thing twice, for the player, and the god controller, so you could just type everything twice, or re-use the same code by making it a function.Code: Select all
function add_crafting_category_to_entity_type(entity_type, category) for i, entity in pairs(data.raw[entity_type]) do if not entity.crafting_categories then entity.crafting_categories = {category} else table.insert(entity.crafting_categories, category) end end end
You will need to call this function on entity types player, and god-controller, as follows:Code: Select all
add_crafting_category_to_entity_type("player", "your-category") add_crafting_category_to_entity_type("god-controller", "your-category")
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: Custom recipe category is showing in player inventory
oh, yeah, you want to do this in the data-updates phase, because if you do it in data phase, depending on mod loading order, it might be before the other mods add their player entities.
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Custom recipe category is showing in player inventory
I'd be pretty furious if someone added crafting categories to my custom player instances. The whole point i use different player instances is to have control over which player type can craft what. Adding something to all of them completly breaks the concept. That's literally like iterating over data.raw['assembling-machine'] and adding crafting categories to everything just because you're trying to add something to assembling-machine-1/2/3. It is YOUR job as the modder who adds new player classes to make sure that those classes inherit the default player categories if you want that.bobingabout wrote:although that works, it is incomplete, because it doesn't take into account player entities added by other mods (such as my bobclasses), or the god controller.eradicator wrote:table.insert(data.raw.player.player.crafting_categories,'your-crafting-category')MineGame159 wrote: Sorry I meant I have all my items and recipes in subgroup but when it have my own recipe category it cannot be crafted in hand.
instead, you should iterate through all data.raw.player entities, and add your new category.
You're right about the god controller though, so i say:
Code: Select all
for _,tbl in pairs{data.raw.player.player, data.raw['god-controller'].default} do
table.insert(tbl.crafting_categories,'your-crafting-category')
end
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: Custom recipe category is showing in player inventory
Well, it does depend what the player entity is for. Mine are intended to be able to craft everything the normal player can.eradicator wrote:I'd be pretty furious if someone added crafting categories to my custom player instances. The whole point i use different player instances is to have control over which player type can craft what. Adding something to all of them completly breaks the concept. That's literally like iterating over data.raw['assembling-machine'] and adding crafting categories to everything just because you're trying to add something to assembling-machine-1/2/3. It is YOUR job as the modder who adds new player classes to make sure that those classes inherit the default player categories if you want that.bobingabout wrote:although that works, it is incomplete, because it doesn't take into account player entities added by other mods (such as my bobclasses), or the god controller.eradicator wrote:table.insert(data.raw.player.player.crafting_categories,'your-crafting-category')MineGame159 wrote: Sorry I meant I have all my items and recipes in subgroup but when it have my own recipe category it cannot be crafted in hand.
instead, you should iterate through all data.raw.player entities, and add your new category.
You're right about the god controller though, so i say:Which has to be done in data.lua so the change is available to all mods that want to read it in -updates or -final-fixes.Code: Select all
for _,tbl in pairs{data.raw.player.player, data.raw['god-controller'].default} do table.insert(tbl.crafting_categories,'your-crafting-category') end
A safer way to do it (Which is actually what I do in my mod) is to check what crafting categories currently exist on the entity before adding new ones, for example, make sure "crafting" exists on the list.
The problem with doing this is that the function is then pretty involved, and I thought it would be too big of a leap from a one liner adding it to the player.
if you're interested, this is the code in my mod, that will do it all correctly.
Don't just use it directly, at the very least change the function names to not include my bobmods table.
Code: Select all
function bobmods.lib.machine.has_category(machine, category_in)
local hasit = false
if machine and machine.crafting_categories then
for i, category in pairs(machine.crafting_categories) do
if category == category_in then
hasit = true
end
end
end
return hasit
end
function bobmods.lib.machine.add_category(machine, category)
if machine and data.raw["recipe-category"][category] then
if not machine.crafting_categories then
machine.crafting_categories = {category}
elseif not bobmods.lib.machine.has_category(machine, category) then
table.insert(machine.crafting_categories, category)
end
else
if not data.raw["recipe-category"][category] then
log("Crafting category " .. category .. " does not exist.")
end
end
end
function bobmods.lib.machine.if_add_category(machine, category, category_to_add)
if machine and data.raw["recipe-category"][category] and data.raw["recipe-category"][category_to_add] then
if bobmods.lib.machine.has_category(machine, category) then
bobmods.lib.machine.add_category(machine, category_to_add)
end
else
if not data.raw["recipe-category"][category] then
log("Crafting category " .. category .. " does not exist.")
end
if not data.raw["recipe-category"][category_to_add] then
log("Crafting category " .. category_to_add .. " does not exist.")
end
end
end
function bobmods.lib.machine.type_if_add_category(machine_type, category, category_to_add)
if data.raw["recipe-category"][category] and data.raw["recipe-category"][category_to_add] then
for i, machine in pairs(data.raw[machine_type]) do
bobmods.lib.machine.if_add_category(machine, category, category_to_add)
end
else
if not data.raw["recipe-category"][category] then
log("Crafting category " .. category .. " does not exist.")
end
if not data.raw["recipe-category"][category_to_add] then
log("Crafting category " .. category_to_add .. " does not exist.")
end
end
end
...
-- add Assembling Machine catagory.
bobmods.lib.machine.type_if_add_category("assembling-machine", "crafting", "crafting-machine")
-- add new electronics crafting categories
bobmods.lib.machine.type_if_add_category("player", "crafting", "electronics")
if data.raw["god-controller"] then
bobmods.lib.machine.type_if_add_category("god-controller", "crafting", "electronics")
end
bobmods.lib.machine.type_if_add_category("assembling-machine", "crafting", "electronics")
bobmods.lib.machine.type_if_add_category("assembling-machine", "crafting", "electronics-machine")
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Custom recipe category is showing in player inventory
No. The procedure doesn't depend on what you want. Because a mod that adds new categories can not possibly know what you want. On the other side it is trivial for the mod adding new player prototypes to also copy the crafting_categories table from the original player object if that is the desired behavior.bobingabout wrote:Well, it does depend what the player entity is for. Mine are intended to be able to craft everything the normal player can.
Also while i can see where you're coming from with the "add category B only if object also has category A" (much better than the brute force approach) there are still some edge cases where even that would be wrong (admittedly those are probably quite edgy indeed >_>).
Additionally i don't agree with your error handling at all. Technically it's not an error to add a crafting_category to a machine before the crafting_category itself has been defined. The problem with your code is thus that it takes a hard error (=game does not start because engine detects missing crafting_category (if it's actually missing at the end)) into a soft error (=game does start but some bits of code haven't been executed). So a previously immediately obvious error is now hidden in a log entry that doesn't even tell you what prototype caused the error.