Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 9.38 KB | None | 0 0
  1. package al132.alchemistry.recipes
  2.  
  3. import al132.alchemistry.blocks.ModBlocks
  4. import al132.alchemistry.chemistry.CompoundRegistry
  5. import al132.alchemistry.chemistry.ElementRegistry
  6. import al132.alchemistry.items.ModItems
  7. import al132.alchemistry.utils.extensions.toCompoundStack
  8. import al132.alchemistry.utils.extensions.toDict
  9. import al132.alchemistry.utils.extensions.toElementStack
  10. import al132.alchemistry.utils.extensions.toStack
  11. import net.minecraft.init.Blocks
  12. import net.minecraft.init.Items
  13. import net.minecraft.item.ItemStack
  14. import net.minecraftforge.fluids.FluidRegistry
  15. import net.minecraftforge.fml.common.IFuelHandler
  16. import net.minecraftforge.fml.common.registry.GameRegistry
  17. import net.minecraftforge.oredict.OreDictionary
  18. import java.util.*
  19.  
  20. /**
  21.  * Created by al132 on 1/16/2017.
  22.  */
  23.  
  24. data class DissolverOreData(val prefix: String, val quantity: Int, val strs: List<String>) {
  25.     fun toDictName(index: Int) = prefix + strs[index].first().toUpperCase() + strs[index].substring(1)
  26.     val size = strs.size
  27. }
  28.  
  29. //TODO clean this file up, it's a hot mess
  30. object ModRecipes {
  31.  
  32.     val metals: List<String> = listOf("aluminum",
  33.             "bismuth",
  34.             "cobalt",
  35.             "copper",
  36.             "gold",
  37.             "iridium",
  38.             "iron",
  39.             "lead",
  40.             "magnesium",
  41.             "nickel",
  42.             "platinum",
  43.             "silver",
  44.             "thorium",
  45.             "tin",
  46.             "titanium",
  47.             "tungsten",
  48.             "uranium",
  49.             "zinc")
  50.  
  51.     val metalOreData: List<DissolverOreData> = listOf(
  52.             DissolverOreData("ingot", 16, metals),
  53.             DissolverOreData("ore", 32, metals),
  54.             DissolverOreData("dust", 16, metals),
  55.             DissolverOreData("block", 144, metals),
  56.             DissolverOreData("nugget", 1, metals))
  57.  
  58.     var electrolyzerRecipes = ArrayList<ElectrolyzerRecipe>()
  59.     var dissolverRecipes = ArrayList<DissolverRecipe>()
  60.     var combinerRecipes = ArrayList<CombinerRecipe>()
  61.  
  62.  
  63.     fun init() {
  64.         initBlockRecipes()
  65.         initDissolverRecipes() //before combiner, so combiner can use reversible recipes
  66.         initCombinerRecipes()
  67.         initElectrolyzerRecipes()
  68.         initFuelHandler()
  69.     }
  70.  
  71.  
  72.     fun initBlockRecipes() {
  73.         GameRegistry.addShapedRecipe(ItemStack(ModBlocks.chemical_combiner),
  74.                 "#D#",
  75.                 "#O#",
  76.                 "#P#",
  77.                 '#', Items.IRON_INGOT, 'D', Items.DIAMOND, 'P', Blocks.PISTON, 'O', Blocks.OBSIDIAN)
  78.  
  79.         GameRegistry.addShapedRecipe(ItemStack(ModBlocks.chemical_dissolver),
  80.                 "#B#",
  81.                 "#M#",
  82.                 "#P#",
  83.                 '#', Items.IRON_INGOT, 'B', Items.ENDER_PEARL, 'P', Blocks.PISTON, 'M', Blocks.MAGMA)
  84.  
  85.         GameRegistry.addShapedRecipe(ItemStack(ModBlocks.electrolyzer),
  86.                 "#Q#",
  87.                 "GQG",
  88.                 "#P#",
  89.                 '#', Items.IRON_INGOT, 'G', Items.GOLD_INGOT, 'P', Blocks.PISTON, 'Q', Blocks.QUARTZ_BLOCK)
  90.  
  91.     }
  92.  
  93.  
  94.     fun initDissolverRecipes() {
  95.  
  96.  
  97.         for (compound in CompoundRegistry.compounds) {
  98.             dissolverRecipes.add(DissolverRecipe(stack = compound.toItemStack(1), inputQuantity = 1,
  99.                     _outputs = ProbabilitySetDSL.create {
  100.                         addGroup {
  101.                             for (component in compound.components) {
  102.                                 addItemStack {
  103.                                     component.compound.toItemStack(component.quantity)
  104.                                 }
  105.                             }
  106.                         }
  107.                     }))
  108.         }
  109.  
  110.         if (OreDictionary.doesOreNameExist("itemSilicon")) {
  111.             dissolverRecipes.add(DissolverRecipe(dictName = "itemSilicon", reversible = true,
  112.                     _outputs = ProbabilitySetDSL.create {
  113.                         addStack { ProbabilityStack("silicon".toElementStack(16)) }
  114.                     }))
  115.         }
  116.  
  117.         dissolverRecipes.add(DissolverRecipe(stack = Items.GUNPOWDER.toStack(), reversible = true,
  118.                 _outputs = ProbabilitySetDSL.create {
  119.                     addGroup {
  120.                         addItemStack { "potassium_nitrate".toCompoundStack(2) }
  121.                         addItemStack { "sulfur".toElementStack(8) }
  122.                         addItemStack { "carbon".toElementStack(8) }
  123.                     }
  124.                 }
  125.         ))
  126.  
  127.         //dissolverRecipes = ImmutableList.Builder<DissolverRecipe>()
  128.         dissolverRecipes.add(DissolverRecipe(dictName = "logWood", inputQuantity = 1,
  129.                 _outputs = ProbabilitySetDSL.create {
  130.                     addStack { ProbabilityStack("cellulose", quantity = 1) }
  131.                     /*  testing stuff --
  132.                       addStack { ProbabilityStack("cellulose", 4, 5) }
  133.                       addStack { ProbabilityStack("cellulose", 2, 1) }
  134.                       addGroup {
  135.                           probability = 5
  136.                           addItemStack { CompoundRegistry.get("cellulose")!!.toItemStack(20) }
  137.                           addItemStack { ItemStack(Items.IRON_INGOT) }
  138.                       }*/
  139.                 }))
  140.  
  141.         for (list in metalOreData) {
  142.             for (index in 0 until list.size) {
  143.                 val elementName = list.strs[index]
  144.                 val oreName = list.toDictName(index)
  145.                 if (OreDictionary.doesOreNameExist(oreName)) {
  146.                     dissolverRecipes.add(DissolverRecipe(dictName = oreName, inputQuantity = 1,
  147.                             _outputs = ProbabilitySetDSL.create {
  148.                                 addStack {
  149.                                     ProbabilityStack(item = ModItems.elements,
  150.                                             meta = ElementRegistry.getMeta(elementName),
  151.                                             quantity = list.quantity)
  152.                                 }
  153.                             }))
  154.                 }
  155.             }
  156.         }
  157.  
  158.         dissolverRecipes.add(DissolverRecipe(stack = ItemStack(Blocks.IRON_BARS),
  159.                 _outputs = ProbabilitySetDSL.create {
  160.                     addStack {
  161.                         ProbabilityStack(item = ModItems.elements,
  162.                                 meta = ElementRegistry.getMeta("iron"),
  163.                                 quantity = 6)
  164.                     }
  165.                 }))
  166.     }
  167.  
  168.  
  169.     fun initElectrolyzerRecipes() {
  170.         electrolyzerRecipes.add(ElectrolyzerRecipe(FluidRegistry.WATER, 30,
  171.                 ItemStack(ModItems.elements, 2, ElementRegistry.get("hydrogen")!!.meta),
  172.                 ItemStack(ModItems.elements, 1, ElementRegistry.get("oxygen")!!.meta)))
  173.     }
  174.  
  175.  
  176.     fun initFuelHandler() {
  177.         val fuelHandler = IFuelHandler { fuel ->
  178.             if (fuel.item == ModItems.elements) {
  179.                 when (fuel.itemDamage) {
  180.                     ElementRegistry.get("hydrogen")!!.meta -> return@IFuelHandler 10
  181.                     ElementRegistry.get("carbon")!!.meta -> return@IFuelHandler 200
  182.                 }
  183.             }
  184.             return@IFuelHandler 0
  185.         }
  186.  
  187.         GameRegistry.registerFuelHandler(fuelHandler)
  188.     }
  189.  
  190.  
  191.     fun initCombinerRecipes() {
  192.  
  193.         combinerRecipes.add(CombinerRecipe(Items.COAL.toStack(), listOf("carbon".toElementStack(8))))
  194.         combinerRecipes.add(CombinerRecipe(Items.COAL.toStack(meta = 1), listOf(ItemStack.EMPTY, "carbon".toElementStack(4))))
  195.  
  196.         for (entry in metals) {
  197.             val dustOutput: ItemStack? = OreDictionary.getOres(entry.toDict("dust")).firstOrNull()
  198.             dustOutput?.let {
  199.                 combinerRecipes.add(CombinerRecipe(dustOutput,
  200.                         listOf(entry.toElementStack(4), entry.toElementStack(4), entry.toElementStack(4),
  201.                                 entry.toElementStack(4))))
  202.             }
  203.  
  204.             val ingotOutput: ItemStack? = OreDictionary.getOres(entry.toDict("ingot")).firstOrNull()
  205.             ingotOutput?.let {
  206.                 combinerRecipes.add(CombinerRecipe(ingotOutput,
  207.                         listOf(entry.toElementStack(16))))
  208.             }
  209.  
  210.             val oreOutput: ItemStack? = OreDictionary.getOres(entry.toDict("ore")).firstOrNull()
  211.             oreOutput?.let {
  212.                 combinerRecipes.add(CombinerRecipe(oreOutput,
  213.                         listOf(ItemStack.EMPTY, ItemStack.EMPTY, ItemStack.EMPTY,
  214.                                 ItemStack.EMPTY, entry.toElementStack(8), ItemStack.EMPTY,
  215.                                 entry.toElementStack(8), entry.toElementStack(8), entry.toElementStack(8))))
  216.             }
  217.         }
  218.  
  219.         for (compound in CompoundRegistry.compounds) {
  220.             if (compound.isReversible) {
  221.                 combinerRecipes.add(CombinerRecipe(compound.toItemStack(1),
  222.                         compound.toItemStackList()))
  223.             }
  224.         }
  225.  
  226.         for (recipe in dissolverRecipes) {
  227.             if (recipe.reversible) {
  228.                 combinerRecipes.add(CombinerRecipe(recipe.inputs[0],
  229.                         recipe.outputs.toStackList()
  230.                 ))
  231.             }
  232.         }
  233.  
  234.         var carbon = "carbon".toElementStack(quantity = 64)
  235.         combinerRecipes.add(CombinerRecipe(Items.DIAMOND.toStack(),
  236.                 listOf(carbon, carbon, carbon,
  237.                         carbon, ItemStack.EMPTY, carbon,
  238.                         carbon, carbon, carbon)))
  239.     }
  240. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement