Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.73 KB | None | 0 0
  1. public class RecipeLoader_AlgaeFarm {
  2.  
  3.     private static final HashMap<Integer, AutoMap<GT_Recipe>> mRecipeCache = new HashMap<Integer, AutoMap<GT_Recipe>>();
  4.     private static final HashMap<Integer, AutoMap<GT_Recipe>> mRecipeCompostCache = new HashMap<Integer, AutoMap<GT_Recipe>>();
  5.  
  6.     public static final void generateRecipes() {
  7.         for (int i=0;i<10;i++) {
  8.             getTieredRecipeFromCache(i, false);
  9.         }
  10.         for (int i=0;i<10;i++) {
  11.             getTieredRecipeFromCache(i, true);
  12.         }
  13.     }  
  14.  
  15.     public static GT_Recipe getTieredRecipeFromCache(int aTier, boolean aCompost) {
  16.         HashMap<Integer, AutoMap<GT_Recipe>> aMap = aCompost ? mRecipeCompostCache : mRecipeCache;
  17.         String aComp = aCompost ? "(Compost)" : "";
  18.  
  19.         AutoMap<GT_Recipe> aTemp = aMap.get(aTier);
  20.         if (aTemp == null || aTemp.isEmpty()) {
  21.             aTemp = new AutoMap<GT_Recipe>();
  22.             aMap.put(aTier, aTemp);
  23.             Logger.INFO("Tier "+aTier+aComp+" had no recipes, initialising new map.");
  24.         }      
  25.         if (aTemp.size() < 500) {
  26.             Logger.INFO("Tier "+aTier+aComp+" has less than 500 recipes, generating "+(500 - aTemp.size())+".");
  27.             for (int i=aTemp.size();i<500;i++) {
  28.                 aTemp.put(generateBaseRecipe(aCompost, aTier));
  29.             }
  30.         }      
  31.         int aIndex = MathUtils.randInt(0, aTemp.isEmpty() ? 1 : aTemp.size());
  32.         Logger.INFO("Using recipe with index of "+aIndex+". "+aComp);
  33.         return aTemp.get(aIndex);
  34.     }
  35.  
  36.     private static GT_Recipe generateBaseRecipe(boolean aUsingCompost, int aTier) {
  37.  
  38.         // Type Safety
  39.         if (aTier < 0) {
  40.             return null;
  41.         }
  42.  
  43.         WeightedCollection<Float> aOutputTimeMulti = new WeightedCollection<Float>();
  44.         for (int i=100;i> 0;i--) {
  45.             float aValue = 0;
  46.             if (i < 10) {
  47.                 aValue = 3f;
  48.             }
  49.             else if (i < 20) {
  50.                 aValue = 2f;
  51.             }
  52.             else {
  53.                 aValue = 1f;               
  54.             }
  55.             aOutputTimeMulti.put(i, aValue);           
  56.         }
  57.  
  58.         final int[] aDurations = new int[] {
  59.                 432000,                
  60.                 378000,            
  61.                 216000,
  62.                 162000,            
  63.                 108000,
  64.                 81000,             
  65.                 54000,
  66.                 40500,             
  67.                 27000,
  68.                 20250,
  69.                 13500,
  70.                 6750,
  71.                 3375,
  72.                 1686,
  73.                 843,
  74.                 421
  75.         };
  76.  
  77.         ItemStack[] aInputs = new ItemStack[] {};  
  78.  
  79.         if (aUsingCompost) {
  80.             // Make it use 4 compost per tier if we have some available
  81.             ItemStack aCompost = ItemUtils.getSimpleStack(AgriculturalChem.mCompost, aTier * 4);
  82.             aInputs = new ItemStack[] {aCompost};
  83.             // Boost Tier by one if using compost so it gets a speed boost
  84.             aTier++;
  85.         }
  86.  
  87.         // We set these elsewhere
  88.         ItemStack[] aOutputs = getOutputsForTier(aTier);
  89.  
  90.         GT_Recipe tRecipe = new Recipe_GT(
  91.                 false,
  92.                 aInputs,
  93.                 aOutputs,
  94.                 (Object) null,
  95.                 new int[] {},
  96.                 new FluidStack[] {GT_Values.NF},
  97.                 new FluidStack[] {GT_Values.NF},
  98.                 (int) (aDurations[aTier] * aOutputTimeMulti.get()), // Time
  99.                 0,
  100.                 0);
  101.        
  102.         tRecipe.mSpecialValue = tRecipe.hashCode();
  103.  
  104.         return tRecipe;
  105.     }
  106.    
  107.     private static ItemStack[] getOutputsForTier(int aTier) {
  108.        
  109.         // Create an Automap to dump contents into
  110.         AutoMap<ItemStack> aOutputMap = new AutoMap<ItemStack>();
  111.        
  112.         // Add loot relevant to tier and also add any from lower tiers.
  113.         if (aTier >= 0) {
  114.             aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mAlgaeBiosmass, MathUtils.randInt(16, 32)));
  115.             aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mAlgaeBiosmass, MathUtils.randInt(32, 64)));          
  116.             if (MathUtils.randInt(0, 10) > 9) {
  117.                 aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, MathUtils.randInt(8, 16)));              
  118.             }
  119.         }
  120.         if (aTier >= 1) {
  121.             aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mAlgaeBiosmass, MathUtils.randInt(16, 32)));
  122.             aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, MathUtils.randInt(16, 32)));         
  123.             if (MathUtils.randInt(0, 10) > 9) {
  124.                 aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, MathUtils.randInt(4, 8)));               
  125.             }
  126.         }
  127.         if (aTier >= 2) {
  128.             aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, MathUtils.randInt(8, 16)));
  129.             aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, MathUtils.randInt(16, 32)));         
  130.             if (MathUtils.randInt(0, 10) > 9) {
  131.                 aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, MathUtils.randInt(4, 8)));               
  132.             }
  133.         }
  134.         if (aTier >= 3) {
  135.             aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, MathUtils.randInt(16, 32)));
  136.             aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mBrownAlgaeBiosmass, MathUtils.randInt(2, 8)));           
  137.             if (MathUtils.randInt(0, 10) > 9) {
  138.                 aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mBrownAlgaeBiosmass, MathUtils.randInt(8, 16)));              
  139.             }
  140.         }
  141.         if (aTier >= 4) {
  142.             aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mBrownAlgaeBiosmass, MathUtils.randInt(16, 32)));
  143.             aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mBrownAlgaeBiosmass, MathUtils.randInt(32, 64)));         
  144.             if (MathUtils.randInt(0, 10) > 9) {
  145.                 aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGoldenBrownAlgaeBiosmass, MathUtils.randInt(4, 8)));             
  146.             }
  147.         }
  148.         if (aTier >= 5) {
  149.             aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mBrownAlgaeBiosmass, MathUtils.randInt(16, 32)));
  150.             aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGoldenBrownAlgaeBiosmass, MathUtils.randInt(16, 32)));           
  151.             if (MathUtils.randInt(0, 10) > 9) {
  152.                 aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mRedAlgaeBiosmass, MathUtils.randInt(1, 2)));             
  153.             }
  154.         }
  155.         // Tier 6 is Highest for outputs
  156.         if (aTier >= 6) {
  157.             aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGoldenBrownAlgaeBiosmass, MathUtils.randInt(16, 32)));
  158.             aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mRedAlgaeBiosmass, MathUtils.randInt(8, 16)));        
  159.             if (MathUtils.randInt(0, 10) > 9) {
  160.                 aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mRedAlgaeBiosmass, MathUtils.randInt(8, 16)));            
  161.             }
  162.         }
  163.        
  164.         // Iterate a special loop at higher tiers to provide more Red/Gold Algae.
  165.         for (int i=0;i<(9-aTier);i++) {
  166.             if (aTier >= (6+i)) {
  167.                 int aMulti = i + 1;
  168.                 aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGoldenBrownAlgaeBiosmass, MathUtils.randInt(4, 8*aMulti)));
  169.                 aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mRedAlgaeBiosmass, MathUtils.randInt(4, 8*aMulti)));          
  170.                 if (MathUtils.randInt(0, 10) > 8) {
  171.                     aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mRedAlgaeBiosmass, MathUtils.randInt(8, 16*aMulti)));             
  172.                 }
  173.             }
  174.         }
  175.        
  176.         // Map the AutoMap contents to an Itemstack Array.
  177.         ItemStack[] aOutputs = new ItemStack[aOutputMap.size()];
  178.         for (int i=0;i<aOutputMap.size();i++) {
  179.             aOutputs[i] = aOutputMap.get(i);
  180.         }  
  181.        
  182.         // Return filled ItemStack Array.
  183.         return aOutputs;
  184.     }
  185.    
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement