Advertisement
Kryzeth

Fixed Factorio Stdlib Functions

Jul 23rd, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.20 KB | None | 0 0
  1. --Fixing some of the Factorio stdlib functions to work properly with all recipes
  2. function Recipe:clear_ingredients()
  3.     if self:is_valid() then
  4.         if self.normal then
  5.             if self.normal.ingredients then
  6.                 self.normal.ingredients = {}
  7.             end
  8.         end
  9.         if self.expensive then
  10.             if self.expensive.ingredients then
  11.                 self.expensive.ingredients = {}
  12.             end
  13.         end
  14.         if self.ingredients then
  15.             self.ingredients = {}
  16.         end
  17.     end
  18.     return self
  19. end
  20.  
  21. function Recipe:set_enabled(enabled)
  22.     if self:is_valid() then
  23.         if self.normal then
  24.             self.normal.enabled = enabled
  25.         end
  26.         if self.expensive then
  27.             self.expensive.enabled = enabled
  28.         end
  29.         if self.enabled  then
  30.             self.enabled = enabled
  31.         end
  32.     end
  33.     return self
  34. end
  35.  
  36. function Data:copy(new_name, mining_result, opts)
  37.     Is.Assert.String(new_name, 'New name is required')
  38.     if self:is_valid() then
  39.         mining_result = mining_result or new_name
  40.         --local from = self.name
  41.         local copy = table.deep_copy(rawget(self, '_raw'))
  42.         copy.name = new_name
  43.  
  44.         -- For Entities
  45.         -- Need to also check mining_results!!!!!!
  46.         if mining_result then
  47.             if copy.minable and copy.minable.result then
  48.                 copy.minable.result = mining_result
  49.             end
  50.         end
  51.  
  52.         -- For items
  53.         if copy.place_result then
  54.             copy.place_result = new_name
  55.         end
  56.  
  57.         -- For recipes, should also to check results!!
  58.         if copy.type == 'recipe' then
  59.             if copy.normal and copy.normal.result then
  60.                 copy.normal.result = new_name
  61.             end
  62.             if copy.expensive and copy.expensive.result then
  63.                 copy.expensive.result = new_name
  64.             end
  65.             if copy.result then
  66.                 copy.result = new_name
  67.             end
  68.         end
  69.  
  70.         -- rail planners
  71.         if copy.placeable_by and copy.placeable_by.item then
  72.             copy.placeable_by.item = mining_result
  73.         end
  74.  
  75.         return self(copy, nil, opts or self.options)
  76.     else
  77.         error('Cannot Copy, invalid prototype', 4)
  78.     end
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement