Skip to content

Commit

Permalink
Fixed apply current factory buttons #458
Browse files Browse the repository at this point in the history
Fixed edit recipe ">" and ">>" buttons ignoring factory max ingredient counts #458
  • Loading branch information
KiwiHawk committed Apr 1, 2023
1 parent 169f972 commit 9a8e12c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Date: ???
- Fixed formula parser pattern #450
- Fixed productivity calculation when recipe speed exceeds 1 craft per tick cap #455
- Fixed "convert recipe to block" for "ingredient input" mode #457
- Fixed edit recipe ">" and ">>" buttons ignoring factory max ingredient counts #458
---------------------------------------------------------------------------------------------------
Version: 0.12.15
Date: 2023-03-19
Expand Down
10 changes: 8 additions & 2 deletions data/ModelBuilder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,16 @@ end
function ModelBuilder.setFactoryBlock(block, current_recipe)
if current_recipe ~= nil then
local default_factory_mode = User.getParameter("default_factory_mode")
local categories = EntityPrototype(current_recipe.factory.name):getCraftingCategories()
local factory_prototype = EntityPrototype(current_recipe.factory.name)
local categories = factory_prototype:getCraftingCategories()
local factory_ingredient_count = factory_prototype:getIngredientCount()
for _, recipe in pairs(block.recipes) do
local prototype_recipe = RecipePrototype(recipe)
if (default_factory_mode ~= "category" and categories[prototype_recipe:getCategory()]) or prototype_recipe:getCategory() == RecipePrototype(current_recipe):getCategory() then
local recipe_ingredient_count = prototype_recipe:getIngredientCount()
--- check ingredient limitation
if factory_ingredient_count < recipe_ingredient_count then
-- Skip
elseif (default_factory_mode ~= "category" and categories[prototype_recipe:getCategory()]) or prototype_recipe:getCategory() == RecipePrototype(current_recipe):getCategory() then
Model.setFactory(recipe, current_recipe.factory.name, current_recipe.factory.fuel)
if User.getParameter("default_factory_with_module") == true then
ModelBuilder.setFactoryModulePriority(recipe, current_recipe.factory.module_priority)
Expand Down
2 changes: 1 addition & 1 deletion model/EntityPrototype.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ end
---Return ingredient_count
---@return number
function EntityPrototype:getIngredientCount()
return self.lua_prototype.ingredient_count or 6
return self.lua_prototype.ingredient_count or 255
end

-------------------------------------------------------------------------------
Expand Down
7 changes: 4 additions & 3 deletions model/RecipePrototype.lua
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,11 @@ end
-------------------------------------------------------------------------------
---Return solid ingredient number of Prototype
---@return number
function RecipePrototype:getIngredientCount(factory)
function RecipePrototype:getIngredientCount()
local count = 0
if self.lua_prototype ~= nil and self:getIngredients(factory) ~= nil then
for _,lua_ingredient in pairs(self:getIngredients(factory)) do
local ingredients = self:getIngredients()
if self.lua_prototype ~= nil and ingredients ~= nil then
for _, lua_ingredient in pairs(ingredients) do
if Product(lua_ingredient):getType() == "item" then
count = count + 1
end
Expand Down

0 comments on commit 9a8e12c

Please sign in to comment.