Skip to content

Commit

Permalink
Error with Nullius Rocket Recipes #468
Browse files Browse the repository at this point in the history
  • Loading branch information
KiwiHawk committed Jul 16, 2023
1 parent 1e2d69f commit 203e8e0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Version: 0.12.19
Date: ???
Bugfixes:
- Fixed blocks not linking correctly when in ingredient input mode #467
- Fixed error with Nullius rocket recipes #468
---------------------------------------------------------------------------------------------------
Version: 0.12.18
Date: 2023-07-09
Expand Down
43 changes: 37 additions & 6 deletions model/Player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -422,17 +422,20 @@ function Player.checkFactoryLimitationModule(module, lua_recipe)
local check_not_bypass = true
local prototype = RecipePrototype(lua_recipe)
local category = prototype:getCategory()
if category == "rocket-building" and lua_recipe.name ~= "rocket-part" then
local rocket_recipe = RecipePrototype("rocket-part")
local rocket_part_recipe = Player.getRocketPartRecipe(lua_recipe.factory)
if category == rocket_part_recipe.category and lua_recipe.name ~= rocket_part_recipe.name then
local rocket_recipe = RecipePrototype(rocket_part_recipe.name)
if rocket_recipe.lua_prototype ~= nil then
rocket_recipe.name = "rocket-part"
rocket_recipe.name = rocket_part_recipe.name
rocket_recipe.factory = lua_recipe.factory
allowed = Player.checkFactoryLimitationModule(module, rocket_recipe)
return allowed
end
return true
end
if rules_excluded[category] == nil then category = "standard" end
if rules_excluded[category] == nil then
category = "standard"
end
check_not_bypass = Player.checkRules(check_not_bypass, rules_excluded, category, EntityPrototype(factory.name):native(), false)
if table.size(module.limitations) > 0 and check_not_bypass and model_filter_factory_module == true then
allowed = false
Expand Down Expand Up @@ -1026,6 +1029,34 @@ function Player.buildFluidRecipe(fluid, ingredients, temperature)
return recipe
end

function Player.getRocketPartRecipe(factory)
-- Get rocket silos
local silos = {}
if factory and factory.name then
silos = {game.entity_prototypes[factory.name]}
else
local entity_filters = {
{filter = "type", invert = false, mode = "and", type = "rocket-silo"},
{filter = "hidden", invert = true, mode = "and"},
}
silos = game.get_filtered_entity_prototypes(entity_filters)
end

-- Get rocket silo fixed recipes
local rocket_part_recipes = {}
for _, silo_prototype in pairs(silos) do
if silo_prototype.fixed_recipe then
table.insert(rocket_part_recipes, game.recipe_prototypes[silo_prototype.fixed_recipe])
end
end

if #rocket_part_recipes == 0 then
return nil
else
return rocket_part_recipes[1]
end
end

function Player.buildRocketRecipe(prototype)
if prototype == nil then return nil end
local products = prototype.rocket_launch_products
Expand All @@ -1034,7 +1065,7 @@ function Player.buildRocketRecipe(prototype)
local stack_size = item_prototype:stackSize()
table.insert(ingredients, {name=prototype.name, type="item", amount=1, constant=true})
local recipe = {}
recipe.category = "rocket-building"
recipe.category = Player.getRocketPartRecipe().category
recipe.enabled = true
recipe.energy = 1
recipe.force = {}
Expand Down Expand Up @@ -1062,7 +1093,7 @@ end
function Player.getRocketRecipes()
local recipes = {}

if Player.getRecipe("rocket-part") ~= nil and Player.getRecipe("rocket-silo") ~= nil then
if Player.getRocketPartRecipe() ~= nil then
for key, item_prototype in pairs(Player.getItemPrototypes()) do
if item_prototype.rocket_launch_products ~= nil and table.size(item_prototype.rocket_launch_products) > 0 then
local recipe = Player.buildRocketRecipe(item_prototype)
Expand Down

0 comments on commit 203e8e0

Please sign in to comment.