From b63f0291056b868d4c46c48b25e46328ad7cf154 Mon Sep 17 00:00:00 2001 From: Boblet Date: Wed, 21 Feb 2024 09:52:42 +0100 Subject: [PATCH] assembler config now uses the new system --- changelog | 4 + .../gui/GUIScreenTemplateFolder.java | 48 +- .../inventory/recipes/AssemblerRecipes.java | 578 +++++------------- .../inventory/recipes/anvil/AnvilRecipes.java | 7 +- .../recipes/loader/SerializableRecipe.java | 1 + .../items/machine/ItemAssemblyTemplate.java | 30 +- src/main/java/com/hbm/main/MainRegistry.java | 6 +- 7 files changed, 222 insertions(+), 452 deletions(-) diff --git a/changelog b/changelog index be8d936a0..fa755b7ee 100644 --- a/changelog +++ b/changelog @@ -3,6 +3,10 @@ * Tweaked super shotgun animations, added config for changing the animation style * The benelli now has reloading animations and the drum mag as advertised * Tom will now explode close to bedrock even when not hitting a block +* The assembler recipe config now uses the same system as all other recipe configs, the file has moved into the `hbmRecipes` folder + * Old files are still compatible if moved to the new folder, since the base structure of the recipe file is the same + * Recipes should work as expected with the `/ntmreload` command + * Recipes now have an optional list for specifying which template folder they are made in ## Fixed * Fixed the structure toggle on the world creation screen not working correctly on most world types diff --git a/src/main/java/com/hbm/inventory/gui/GUIScreenTemplateFolder.java b/src/main/java/com/hbm/inventory/gui/GUIScreenTemplateFolder.java index aae2a8a45..f58519d0a 100644 --- a/src/main/java/com/hbm/inventory/gui/GUIScreenTemplateFolder.java +++ b/src/main/java/com/hbm/inventory/gui/GUIScreenTemplateFolder.java @@ -13,6 +13,7 @@ import com.hbm.inventory.RecipesCommon.ComparableStack; import com.hbm.inventory.fluid.FluidType; import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.recipes.AssemblerRecipes; +import com.hbm.inventory.recipes.AssemblerRecipes.AssemblerRecipe; import com.hbm.inventory.recipes.ChemplantRecipes; import com.hbm.inventory.recipes.ChemplantRecipes.ChemRecipe; import com.hbm.inventory.recipes.CrucibleRecipes; @@ -34,6 +35,7 @@ import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; @@ -56,21 +58,22 @@ public class GUIScreenTemplateFolder extends GuiScreen { if(player.getHeldItem() == null) return; + + Item item = player.getHeldItem().getItem(); - if(player.getHeldItem().getItem() == ModItems.template_folder) { + this.isJournal = item != ModItems.template_folder; + if(!this.isJournal) { // Stamps - for(ItemStack i : ItemStamp.stamps.get(StampType.PLATE)) - allStacks.add(i.copy()); - for(ItemStack i : ItemStamp.stamps.get(StampType.WIRE)) - allStacks.add(i.copy()); - for(ItemStack i : ItemStamp.stamps.get(StampType.CIRCUIT)) - allStacks.add(i.copy()); + for(ItemStack i : ItemStamp.stamps.get(StampType.PLATE)) allStacks.add(i.copy()); + for(ItemStack i : ItemStamp.stamps.get(StampType.WIRE)) allStacks.add(i.copy()); + for(ItemStack i : ItemStamp.stamps.get(StampType.CIRCUIT)) allStacks.add(i.copy()); // Tracks for(int i = 1; i < ItemCassette.TrackType.values().length; i++) { allStacks.add(new ItemStack(ModItems.siren_track, 1, i)); } + // Fluid IDs FluidType[] fluids = Fluids.getInNiceOrder(); for(int i = 1; i < fluids.length; i++) { @@ -78,14 +81,18 @@ public class GUIScreenTemplateFolder extends GuiScreen { allStacks.add(new ItemStack(ModItems.fluid_identifier, 1, fluids[i].getID())); } } - // Assembly Templates - for(int i = 0; i < AssemblerRecipes.recipeList.size(); i++) { - - ComparableStack comp = AssemblerRecipes.recipeList.get(i); - if(AssemblerRecipes.hidden.get(comp) == null) { - allStacks.add(ItemAssemblyTemplate.writeType(new ItemStack(ModItems.assembly_template, 1, i), comp)); - } + } + + // Assembly Templates + for(int i = 0; i < AssemblerRecipes.recipeList.size(); i++) { + ComparableStack comp = AssemblerRecipes.recipeList.get(i); + AssemblerRecipe recipe = AssemblerRecipes.recipes.get(comp); + if(recipe != null && recipe.folders.contains(item)) { + allStacks.add(ItemAssemblyTemplate.writeType(new ItemStack(ModItems.assembly_template, 1, i), comp)); } + } + + if(!this.isJournal) { // Chemistry Templates for(int i = 0; i < ChemplantRecipes.recipes.size(); i++) { ChemRecipe chem = ChemplantRecipes.recipes.get(i); @@ -96,19 +103,6 @@ public class GUIScreenTemplateFolder extends GuiScreen { for(int i = 0; i < CrucibleRecipes.recipes.size(); i++) { allStacks.add(new ItemStack(ModItems.crucible_template, 1, CrucibleRecipes.recipes.get(i).getId())); } - } else { - - for(int i = 0; i < AssemblerRecipes.recipeList.size(); i++) { - - if(AssemblerRecipes.hidden.get(AssemblerRecipes.recipeList.get(i)) != null && - AssemblerRecipes.hidden.get(AssemblerRecipes.recipeList.get(i)).contains(player.getHeldItem().getItem())) { - - ComparableStack comp = AssemblerRecipes.recipeList.get(i); - allStacks.add(ItemAssemblyTemplate.writeType(new ItemStack(ModItems.assembly_template, 1, i), comp)); - } - } - - isJournal = true; } search(null); diff --git a/src/main/java/com/hbm/inventory/recipes/AssemblerRecipes.java b/src/main/java/com/hbm/inventory/recipes/AssemblerRecipes.java index 068b8db5b..42c3792ad 100644 --- a/src/main/java/com/hbm/inventory/recipes/AssemblerRecipes.java +++ b/src/main/java/com/hbm/inventory/recipes/AssemblerRecipes.java @@ -1,6 +1,16 @@ package com.hbm.inventory.recipes; -import com.google.gson.Gson; +import static com.hbm.inventory.OreDictManager.*; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -8,142 +18,35 @@ import com.google.gson.stream.JsonWriter; import com.hbm.blocks.ModBlocks; import com.hbm.config.GeneralConfig; import com.hbm.inventory.OreDictManager; -import com.hbm.inventory.RecipesCommon.AStack; -import com.hbm.inventory.RecipesCommon.ComparableStack; -import com.hbm.inventory.RecipesCommon.OreDictStack; +import com.hbm.inventory.RecipesCommon.*; import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.material.MaterialShapes; import com.hbm.inventory.material.Mats; import com.hbm.inventory.material.NTMMaterial; +import com.hbm.inventory.recipes.loader.SerializableRecipe; import com.hbm.items.ItemAmmoEnums; -import com.hbm.items.ItemGenericPart.EnumPartType; import com.hbm.items.ModItems; +import com.hbm.items.ItemGenericPart.EnumPartType; import com.hbm.items.machine.ItemAssemblyTemplate; import com.hbm.items.machine.ItemDrillbit.EnumDrillType; import com.hbm.items.machine.ItemPistons.EnumPistonType; import com.hbm.items.weapon.ItemAmmoHIMARS; import com.hbm.main.MainRegistry; + import cpw.mods.fml.common.Loader; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraftforge.oredict.OreDictionary; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.util.*; -import java.util.Map.Entry; - -import static com.hbm.inventory.OreDictManager.*; - -public class AssemblerRecipes { - - public static File config; - public static File template; - private static final Gson gson = new Gson(); - public static HashMap recipes = new HashMap(); - public static HashMap time = new HashMap(); +public class AssemblerRecipes extends SerializableRecipe { + + public static HashMap recipes = new HashMap(); public static List recipeList = new ArrayList(); - public static HashMap> hidden = new HashMap(); - - /** - * Pre-Init phase: Finds the recipe config (if exists) and checks if a template is present, if not it generates one. - * @param dir The suggested config folder - */ - public static void preInit(File dir) { - - if(dir == null || !dir.isDirectory()) - return; - - template = dir; - - List files = Arrays.asList(dir.listFiles()); - - for(File file : files) { - if(file.getName().equals("hbmAssembler.json")) { - config = file; - } - } - } - - public static void loadRecipes() { - - if(config == null) { - registerDefaults(); - } else { - loadJSONRecipes(); - } - - generateList(); - saveTemplateJSON(template); - } - - /** - * Generates an ordered list of outputs, used by the template item to generate subitems - */ - private static void generateList() { - - List list = new ArrayList(recipes.keySet()); - Collections.sort(list); - recipeList = list; - } - - public static ItemStack getOutputFromTempate(ItemStack stack) { - - if(stack != null && stack.getItem() instanceof ItemAssemblyTemplate) { - - ComparableStack comp = ItemAssemblyTemplate.readType(stack); - - //NEW - if(comp != null) { - return comp.toStack(); - } - - //LEGACY - int i = stack.getItemDamage(); - if(i >= 0 && i < recipeList.size()) { - return recipeList.get(i).toStack(); - } - } - - return null; - } - - public static List getRecipeFromTempate(ItemStack stack) { - - if(stack != null && stack.getItem() instanceof ItemAssemblyTemplate) { - - //NEW - ComparableStack compStack = ItemAssemblyTemplate.readType(stack); - if(compStack != null) { - AStack[] ret = recipes.get(compStack); - return ret == null ? null : Arrays.asList(ret); - } - - //LEGACY - int i = stack.getItemDamage(); - if(i >= 0 && i < recipeList.size()) { - ItemStack out = recipeList.get(i).toStack(); - - if(out != null) { - ComparableStack comp = new ComparableStack(out); - AStack[] ret = recipes.get(comp); - return ret == null ? null : Arrays.asList(ret); - } - } - } - - return null; - } - - /** - * Registers regular recipes if there's no custom configuration - */ - private static void registerDefaults() { + + @Override + public void registerDefaults() { boolean exp = GeneralConfig.enableExpensiveMode; @@ -308,7 +211,7 @@ public class AssemblerRecipes { makeRecipe(new ComparableStack(ModBlocks.nuke_fleija, 1), new AStack[] {new ComparableStack(ModItems.hull_small_aluminium, 1), new ComparableStack(ModItems.fins_quad_titanium, 1), new ComparableStack(ModItems.circuit_targeting_tier4, 2), new ComparableStack(ModItems.wire_gold, 8), new OreDictStack("dyeWhite", 4), },400); makeRecipe(new ComparableStack(ModBlocks.nuke_solinium, 1), new AStack[] {new ComparableStack(ModItems.hull_small_steel, 2), new ComparableStack(ModItems.fins_quad_titanium, 1), new ComparableStack(ModItems.circuit_targeting_tier4, 3), new ComparableStack(ModItems.wire_gold, 10), new ComparableStack(ModItems.pipes_steel, 4), new OreDictStack("dyeGray", 4), },400); makeRecipe(new ComparableStack(ModBlocks.nuke_n2, 1), new AStack[] {new ComparableStack(ModItems.hull_big_steel, 3), new ComparableStack(ModItems.hull_small_steel, 2), new ComparableStack(ModItems.wire_magnetized_tungsten, 12), new ComparableStack(ModItems.pipes_steel, 6), new ComparableStack(ModItems.circuit_targeting_tier4, 3), new OreDictStack("dyeBlack", 12), },300); - makeRecipe(new ComparableStack(ModBlocks.nuke_fstbmb, 1), new AStack[] {new ComparableStack(ModItems.sphere_steel, 1), new ComparableStack(ModItems.hull_big_titanium, 6), new ComparableStack(ModItems.fins_big_steel, 1), new ComparableStack(ModItems.powder_magic, 8), new ComparableStack(ModItems.wire_gold, 12), new ComparableStack(ModItems.circuit_targeting_tier4, 4), new OreDictStack("dyeGray", 6), },600); + makeRecipe(new ComparableStack(ModBlocks.nuke_fstbmb, 1), new AStack[] {new ComparableStack(ModItems.sphere_steel, 1), new ComparableStack(ModItems.hull_big_titanium, 6), new ComparableStack(ModItems.fins_big_steel, 1), new ComparableStack(ModItems.powder_magic, 8), new ComparableStack(ModItems.wire_gold, 12), new ComparableStack(ModItems.circuit_targeting_tier4, 4), new OreDictStack("dyeGray", 6), },600, ModItems.journal_pip, ModItems.journal_bj); makeRecipe(new ComparableStack(ModBlocks.nuke_custom, 1), new AStack[] {new ComparableStack(ModItems.hull_small_steel, 2), new ComparableStack(ModItems.fins_small_steel, 1), new ComparableStack(ModItems.circuit_gold, 1), new ComparableStack(ModItems.wire_gold, 12), new OreDictStack("dyeGray", 4), },300); makeRecipe(new ComparableStack(ModBlocks.float_bomb, 1), new AStack[] {new OreDictStack(TI.plate(), 12), new ComparableStack(ModItems.levitation_unit, 1), new ComparableStack(ModItems.circuit_gold, 4), new ComparableStack(ModItems.wire_gold, 6), },250); makeRecipe(new ComparableStack(ModBlocks.therm_endo, 1), new AStack[] {new OreDictStack(TI.plate(), 12), new ComparableStack(ModItems.powder_ice, 32), new ComparableStack(ModItems.circuit_gold, 1), new ComparableStack(ModItems.coil_gold, 4), },250); @@ -397,15 +300,15 @@ public class AssemblerRecipes { makeRecipe(new ComparableStack(ModItems.mp_warhead_10_buster, 1), new AStack[] {new ComparableStack(ModItems.seg_10, 1), new OreDictStack(TI.plate(), 4), new ComparableStack(ModBlocks.det_charge, 1), new ComparableStack(ModBlocks.det_cord, 4), new ComparableStack(ModItems.board_copper, 4), new ComparableStack(ModItems.circuit_targeting_tier3, 1), },100); makeRecipe(new ComparableStack(ModItems.mp_warhead_10_nuclear, 1), new AStack[] {new ComparableStack(ModItems.seg_10, 1), new OreDictStack(STEEL.plate(), 6), new OreDictStack(PU239.ingot(), 1), new OreDictStack(OreDictManager.getReflector(), 2), new OreDictStack(ANY_HIGHEXPLOSIVE.ingot(), 4), new ComparableStack(ModItems.circuit_targeting_tier3, 1), },200); makeRecipe(new ComparableStack(ModItems.mp_warhead_10_nuclear_large, 1), new AStack[] {new ComparableStack(ModItems.seg_10, 1), new OreDictStack(STEEL.plate(), 8), new OreDictStack(AL.plate(), 4), new OreDictStack(PU239.ingot(), 2), new ComparableStack(ModBlocks.det_charge, 4), new ComparableStack(ModItems.circuit_targeting_tier4, 1), },300); - makeRecipe(new ComparableStack(ModItems.mp_warhead_10_taint, 1), new AStack[] {new ComparableStack(ModItems.seg_10, 1), new OreDictStack(STEEL.plate(), 12), new ComparableStack(ModBlocks.det_cord, 2), new ComparableStack(ModItems.powder_magic, 12), new ComparableStack(ModItems.bucket_mud, 1), },100); - makeRecipe(new ComparableStack(ModItems.mp_warhead_10_cloud, 1), new AStack[] {new ComparableStack(ModItems.seg_10, 1), new OreDictStack(STEEL.plate(), 12), new ComparableStack(ModBlocks.det_cord, 2), new ComparableStack(ModItems.grenade_pink_cloud, 2), },100); + makeRecipe(new ComparableStack(ModItems.mp_warhead_10_taint, 1), new AStack[] {new ComparableStack(ModItems.seg_10, 1), new OreDictStack(STEEL.plate(), 12), new ComparableStack(ModBlocks.det_cord, 2), new ComparableStack(ModItems.powder_magic, 12), new ComparableStack(ModItems.bucket_mud, 1), },100, ModItems.journal_pip); + makeRecipe(new ComparableStack(ModItems.mp_warhead_10_cloud, 1), new AStack[] {new ComparableStack(ModItems.seg_10, 1), new OreDictStack(STEEL.plate(), 12), new ComparableStack(ModBlocks.det_cord, 2), new ComparableStack(ModItems.grenade_pink_cloud, 2), },100, ModItems.journal_pip); makeRecipe(new ComparableStack(ModItems.mp_warhead_15_he, 1), new AStack[] {new ComparableStack(ModItems.seg_15, 1), new OreDictStack(STEEL.plate(), 16), new ComparableStack(ModBlocks.det_charge, 4), new ComparableStack(ModItems.circuit_targeting_tier3, 1), },200); makeRecipe(new ComparableStack(ModItems.mp_warhead_15_incendiary, 1), new AStack[] {new ComparableStack(ModItems.seg_15, 1), new OreDictStack(STEEL.plate(), 16), new ComparableStack(ModBlocks.det_charge, 2), new OreDictStack(P_RED.dust(), 8), new ComparableStack(ModItems.circuit_targeting_tier3, 1), },200); makeRecipe(new ComparableStack(ModItems.mp_warhead_15_nuclear, 1), new AStack[] {new ComparableStack(ModItems.seg_15, 1), new OreDictStack(STEEL.plate(), 24), new OreDictStack(TI.plate(), 12), new OreDictStack(PU239.ingot(), 3), new ComparableStack(ModBlocks.det_charge, 6), new ComparableStack(ModItems.circuit_targeting_tier4, 1), },500); makeRecipe(new ComparableStack(ModItems.mp_warhead_15_n2, 1), new AStack[] {new ComparableStack(ModItems.seg_15, 1), new OreDictStack(STEEL.plate(), 8), new OreDictStack(TI.plate(), 20), new ComparableStack(ModBlocks.det_charge, 24), new ComparableStack(Blocks.redstone_block, 12), new OreDictStack(MAGTUNG.dust(), 6), new ComparableStack(ModItems.circuit_targeting_tier4, 1), },400); - makeRecipe(new ComparableStack(ModItems.mp_warhead_15_balefire, 1), new AStack[] {new ComparableStack(ModItems.seg_15, 1), new OreDictStack(OreDictManager.getReflector(), 16), new ComparableStack(ModItems.powder_magic, 6), new ComparableStack(ModItems.egg_balefire_shard, 4), new OreDictStack(ANY_HIGHEXPLOSIVE.ingot(), 8), new ComparableStack(ModItems.circuit_targeting_tier4, 1), }, 60); - makeRecipe(new ComparableStack(ModItems.missile_soyuz, 1), new AStack[] {new ComparableStack(ModItems.rocket_fuel, 40), new ComparableStack(ModBlocks.det_cord, 20), new ComparableStack(ModItems.thruster_medium, 12), new ComparableStack(ModItems.thruster_small, 12), new ComparableStack(ModItems.tank_steel, 10), new ComparableStack(ModItems.circuit_targeting_tier4, 2), new ComparableStack(ModItems.circuit_targeting_tier3, 8), new OreDictStack(RUBBER.ingot(), 64), new ComparableStack(ModItems.fins_small_steel, 4), new ComparableStack(ModItems.hull_big_titanium, 32), new ComparableStack(ModItems.hull_big_steel, 18), new OreDictStack(FIBER.ingot(), 64), },600); - makeRecipe(new ComparableStack(ModItems.missile_soyuz_lander, 1), new AStack[] {new ComparableStack(ModItems.rocket_fuel, 10), new ComparableStack(ModItems.thruster_small, 3), new ComparableStack(ModItems.tank_steel, 2), new ComparableStack(ModItems.circuit_targeting_tier3, 4), new OreDictStack(ANY_RUBBER.ingot(), 32), new ComparableStack(ModItems.hull_big_aluminium, 2), new ComparableStack(ModItems.sphere_steel, 1), new OreDictStack(FIBER.ingot(), 12), },600); + makeRecipe(new ComparableStack(ModItems.mp_warhead_15_balefire, 1), new AStack[] {new ComparableStack(ModItems.seg_15, 1), new OreDictStack(OreDictManager.getReflector(), 16), new ComparableStack(ModItems.powder_magic, 6), new ComparableStack(ModItems.egg_balefire_shard, 4), new OreDictStack(ANY_HIGHEXPLOSIVE.ingot(), 8), new ComparableStack(ModItems.circuit_targeting_tier4, 1), }, 60, ModItems.journal_bj); + makeRecipe(new ComparableStack(ModItems.missile_soyuz, 1), new AStack[] {new ComparableStack(ModItems.rocket_fuel, 40), new ComparableStack(ModBlocks.det_cord, 20), new ComparableStack(ModItems.thruster_medium, 12), new ComparableStack(ModItems.thruster_small, 12), new ComparableStack(ModItems.tank_steel, 10), new ComparableStack(ModItems.circuit_targeting_tier4, 2), new ComparableStack(ModItems.circuit_targeting_tier3, 8), new OreDictStack(RUBBER.ingot(), 64), new ComparableStack(ModItems.fins_small_steel, 4), new ComparableStack(ModItems.hull_big_titanium, 32), new ComparableStack(ModItems.hull_big_steel, 18), new OreDictStack(FIBER.ingot(), 64), },600, ModItems.journal_bj); + makeRecipe(new ComparableStack(ModItems.missile_soyuz_lander, 1), new AStack[] {new ComparableStack(ModItems.rocket_fuel, 10), new ComparableStack(ModItems.thruster_small, 3), new ComparableStack(ModItems.tank_steel, 2), new ComparableStack(ModItems.circuit_targeting_tier3, 4), new OreDictStack(ANY_RUBBER.ingot(), 32), new ComparableStack(ModItems.hull_big_aluminium, 2), new ComparableStack(ModItems.sphere_steel, 1), new OreDictStack(FIBER.ingot(), 12), },600, ModItems.journal_bj); makeRecipe(new ComparableStack(ModItems.fusion_shield_tungsten, 1), new AStack[] {new OreDictStack(W.block(), 32), new OreDictStack(OreDictManager.getReflector(), 96)}, 600); makeRecipe(new ComparableStack(ModItems.fusion_shield_desh, 1), new AStack[] {new OreDictStack(DESH.block(), 16), new OreDictStack(CO.block(), 16), new OreDictStack(BIGMT.plate(), 96)}, 600); makeRecipe(new ComparableStack(ModItems.fusion_shield_chlorophyte, 1), new AStack[] {new OreDictStack(W.block(), 16), new OreDictStack(DURA.block(), 16), new OreDictStack(OreDictManager.getReflector(), 48), new ComparableStack(ModItems.powder_chlorophyte, 48)}, 600); @@ -669,7 +572,7 @@ public class AssemblerRecipes { new ComparableStack(ModItems.coin_radiation, 1), new ComparableStack(ModItems.coin_maskman, 1), new ComparableStack(ModItems.coin_worm, 1), - }, 1200); + }, 1200, ModItems.journal_bj); makeRecipe(new ComparableStack(ModBlocks.vault_door, 1), new AStack[] { new OreDictStack(STEEL.ingot(), 32), @@ -1060,7 +963,7 @@ public class AssemblerRecipes { if(!GeneralConfig.enable528) { makeRecipe(new ComparableStack(ModBlocks.machine_hephaestus, 1), new AStack[] { new ComparableStack(ModItems.pipes_steel, 1), !exp ? new OreDictStack(STEEL.ingot(), 24) : new OreDictStack(STEEL.heavyComp(), 2), !exp ? new OreDictStack(CU.plate(), 24) : new OreDictStack(CU.heavyComp(), 2), new OreDictStack(NB.ingot(), 4), new OreDictStack(RUBBER.ingot(), 12), new ComparableStack(ModBlocks.glass_quartz, 16) }, 150); - makeRecipe(new ComparableStack(ModBlocks.machine_radgen, 1), new AStack[] {new OreDictStack(STEEL.ingot(), 8), new OreDictStack(STEEL.plate(), 32), new ComparableStack(ModItems.coil_magnetized_tungsten, 6), new ComparableStack(ModItems.wire_magnetized_tungsten, 24), new ComparableStack(ModItems.circuit_gold, 4), new ComparableStack(ModItems.reactor_core, 3), new OreDictStack(STAR.ingot(), 1), new OreDictStack("dyeRed", 1), },400); + makeRecipe(new ComparableStack(ModBlocks.machine_radgen, 1), new AStack[] {new OreDictStack(STEEL.ingot(), 8), new OreDictStack(STEEL.plate(), 32), new ComparableStack(ModItems.coil_magnetized_tungsten, 6), new ComparableStack(ModItems.wire_magnetized_tungsten, 24), new ComparableStack(ModItems.circuit_gold, 4), new ComparableStack(ModItems.reactor_core, 3), new OreDictStack(STAR.ingot(), 1), new OreDictStack("dyeRed", 1), }, 400, ModItems.journal_pip); makeRecipe(new ComparableStack(ModBlocks.machine_reactor_breeding, 1), new AStack[] {new ComparableStack(ModItems.reactor_core, 1), new OreDictStack(STEEL.ingot(), 12), new OreDictStack(PB.plate(), 16), new ComparableStack(ModBlocks.reinforced_glass, 4), new OreDictStack(ASBESTOS.ingot(), 4), new OreDictStack(ANY_RESISTANTALLOY.ingot(), 4), new ComparableStack(ModItems.crt_display, 1)},150); makeRecipe(new ComparableStack(ModBlocks.reactor_research, 1), new AStack[] {new OreDictStack(STEEL.ingot(), 8), new OreDictStack(ANY_RESISTANTALLOY.ingot(), 4), new ComparableStack(ModItems.motor_desh, 2), new OreDictStack(B.ingot(), 5), new OreDictStack(PB.plate(), 8), new ComparableStack(ModItems.crt_display, 3), new ComparableStack(ModItems.circuit_copper, 2), },300); @@ -1269,298 +1172,142 @@ public class AssemblerRecipes { makeRecipe(new ComparableStack(ModItems.heavy_component, 1, mat.id), new AStack[] { new OreDictStack(MaterialShapes.CASTPLATE.name() + mat.names[0], 256) }, 12_000); } } - - /// HIDDEN /// - hidden.put(new ComparableStack(ModBlocks.machine_radgen, 1), new HashSet() {{ add(ModItems.journal_pip); }}); - hidden.put(new ComparableStack(ModBlocks.nuke_fstbmb, 1), new HashSet() {{ add(ModItems.journal_pip); add(ModItems.journal_bj); }}); - hidden.put(new ComparableStack(ModItems.mp_warhead_10_cloud, 1), new HashSet() {{ add(ModItems.journal_pip); }}); - hidden.put(new ComparableStack(ModItems.mp_warhead_10_taint, 1), new HashSet() {{ add(ModItems.journal_pip); }}); - hidden.put(new ComparableStack(ModItems.mp_warhead_15_balefire, 1), new HashSet() {{ add(ModItems.journal_bj); }}); - hidden.put(new ComparableStack(ModItems.sat_gerald, 1), new HashSet() {{ add(ModItems.journal_bj); }}); - hidden.put(new ComparableStack(ModItems.missile_soyuz, 1), new HashSet() {{ add(ModItems.journal_bj); }}); - hidden.put(new ComparableStack(ModItems.missile_soyuz_lander, 1), new HashSet() {{ add(ModItems.journal_bj); }}); } public static void makeRecipe(ComparableStack out, AStack[] in, int duration) { + makeRecipe(out, in, duration, ModItems.template_folder); + } + + public static void makeRecipe(ComparableStack out, AStack[] in, int duration, Item... folder) { if(out == null || Item.itemRegistry.getNameForObject(out.item) == null) { MainRegistry.logger.error("Canceling assembler registration, item was null!"); return; } - recipes.put(out, in); - time.put(out, duration); + AssemblerRecipe recipe = new AssemblerRecipe(in, duration, folder); + recipes.put(out, recipe); + recipeList.add(out); + } + + @Override + public String getFileName() { + return "hbmAssembler.json"; + } + + @Override + public Object getRecipeObject() { + return this.recipes; + } + + @Override + public void deleteRecipes() { + recipes.clear(); + recipeList.clear(); + } + + @Override + public void readRecipe(JsonElement recipe) { + JsonObject obj = recipe.getAsJsonObject(); + + ItemStack output = this.readItemStack(obj.get("output").getAsJsonArray()); + AStack[] input = this.readAStackArray(obj.get("input").getAsJsonArray()); + int duration = obj.get("duration").getAsInt(); + + if(obj.has("folders")) { + JsonArray array = obj.get("folders").getAsJsonArray(); + List items = new ArrayList(); + for(JsonElement element : array) { + Item item = (Item) Item.itemRegistry.getObject(element.getAsString()); + if(item != null) items.add(item); + } + this.makeRecipe(new ComparableStack(output), input, duration, items.toArray(new Item[0])); + } else { + this.makeRecipe(new ComparableStack(output), input, duration); + } + } + + @Override + public void writeRecipe(Object recipe, JsonWriter writer) throws IOException { + Entry entry = (Entry) recipe; + + writer.name("output"); + this.writeItemStack(entry.getKey().toStack(), writer); + writer.name("input").beginArray(); + for(AStack stack : entry.getValue().ingredients) this.writeAStack(stack, writer); + writer.endArray(); + writer.name("duration").value(entry.getValue().time); + + if(entry.getValue().folders.size() != 1 || !entry.getValue().folders.contains(ModItems.template_folder)) { + writer.name("folders").beginArray(); + for(Item folder : entry.getValue().folders) writer.value(Item.itemRegistry.getNameForObject(folder)); + writer.endArray(); + } + } + + public static ItemStack getOutputFromTempate(ItemStack stack) { + + if(stack != null && stack.getItem() instanceof ItemAssemblyTemplate) { + + ComparableStack comp = ItemAssemblyTemplate.readType(stack); + + //NEW + if(comp != null) { + return comp.toStack(); + } + + //LEGACY + int i = stack.getItemDamage(); + if(i >= 0 && i < recipeList.size()) { + return recipeList.get(i).toStack(); + } + } + + return null; + } + + public static List getRecipeFromTempate(ItemStack stack) { + + if(stack != null && stack.getItem() instanceof ItemAssemblyTemplate) { + + //NEW + ComparableStack compStack = ItemAssemblyTemplate.readType(stack); + if(compStack != null) { + AssemblerRecipe recipe = recipes.get(compStack); + AStack[] ret = recipe.ingredients; + return ret == null ? null : Arrays.asList(ret); + } + + //LEGACY + int i = stack.getItemDamage(); + if(i >= 0 && i < recipeList.size()) { + ItemStack out = recipeList.get(i).toStack(); + + if(out != null) { + ComparableStack comp = new ComparableStack(out); + AssemblerRecipe recipe = recipes.get(comp); + AStack[] ret = recipe.ingredients; + return ret == null ? null : Arrays.asList(ret); + } + } + } + + return null; } public static void addTantalium(ComparableStack out, int amount) { - AStack[] ins = recipes.get(out); + AssemblerRecipe recipe = recipes.get(out); - if(ins != null) { + if(recipe != null) { - AStack[] news = new AStack[ins.length + 1]; + AStack[] news = new AStack[recipe.ingredients.length + 1]; - for(int i = 0; i < ins.length; i++) - news[i] = ins[i]; + for(int i = 0; i < recipe.ingredients.length; i++) + news[i] = recipe.ingredients[i]; news[news.length - 1] = new ComparableStack(ModItems.circuit_tantalium, amount); - - recipes.put(out, news); - } - } - - /* - * { - * recipes : [ - * { - * output : [ "item", "hbm:item.tank_steel", 1, 0 ], - * duration : 100, - * input : [ - * [ "dict", "blockSteel", 6 ], - * [ "dict", "plateTitanium", 2 ], - * [ "dict", "dyeGray", 1 ], - * ] - * }, - * { - * output : [ "item", "hbm:plate_gold", 2, 0 ], - * duration : 20, - * input : [ - * [ "dict", "ingotGold", 3 ], - * [ "item", "hbm:item.wire_gold", 5 ] - * ] - * } - * ] - * } - */ - private static void loadJSONRecipes() { - - try { - JsonObject json = gson.fromJson(new FileReader(config), JsonObject.class); - - JsonElement recipes = json.get("recipes"); - - if(recipes instanceof JsonArray) { - - JsonArray recArray = recipes.getAsJsonArray(); - - //go through the recipes array - for(JsonElement recipe : recArray) { - - if(recipe.isJsonObject()) { - - JsonObject recObj = recipe.getAsJsonObject(); - - JsonElement input = recObj.get("input"); - JsonElement output = recObj.get("output"); - JsonElement duration = recObj.get("duration"); - - int time = 100; - - if(duration.isJsonPrimitive()) { - if(duration.getAsJsonPrimitive().isNumber()) { - time = Math.max(1, duration.getAsJsonPrimitive().getAsInt()); - } - } - - if(!(input instanceof JsonArray)) { - MainRegistry.logger.error("Error reading recipe, no input found!"); - continue; - } - - if(!(output instanceof JsonArray)) { - MainRegistry.logger.error("Error reading recipe, no output found!"); - continue; - } - - Object outp = parseJsonArray(output.getAsJsonArray()); - List inp = new ArrayList(); - - for(JsonElement in : input.getAsJsonArray()) { - - if(in.isJsonArray()) { - Object i = parseJsonArray(in.getAsJsonArray()); - - if(i instanceof ComparableStack || i instanceof OreDictStack) - inp.add(i); - } - } - - if(outp instanceof ComparableStack) { - AssemblerRecipes.recipes.put((ComparableStack) outp, Arrays.copyOf(inp.toArray(), inp.size(), AStack[].class)); - AssemblerRecipes.time.put((ComparableStack) outp, time); - } - } - } - } - - } catch (Exception e) { - //shush - } - } - - private static Object parseJsonArray(JsonArray array) { - - boolean dict = false; - String item = ""; - int stacksize = 1; - int meta = 0; - - if(array.size() < 2) - return null; - - //is index 0 "item" or "dict"? - if(array.get(0).isJsonPrimitive()) { - - if(array.get(0).getAsString().equals("item")) { - dict = false; - } else if(array.get(0).getAsString().equals("dict")) { - dict = true; - } else { - - MainRegistry.logger.error("Error reading recipe, stack array does not have 'item' or 'dict' label!"); - return null; - } - - } else { - - MainRegistry.logger.error("Error reading recipe, label is not a valid data type!"); - return null; - } - - //is index 1 a string - if(array.get(1).isJsonPrimitive()) { - - item = array.get(1).getAsString(); - - } else { - MainRegistry.logger.error("Error reading recipe, item string is not a valid data type!"); - return null; - } - - //if index 2 exists, eval it as a stacksize - if(array.size() > 2 && array.get(2).isJsonPrimitive()) { - - if(array.get(2).getAsJsonPrimitive().isNumber()) { - - stacksize = Math.max(1, array.get(2).getAsJsonPrimitive().getAsNumber().intValue()); - - } else { - - MainRegistry.logger.error("Error reading recipe, stack size is not a valid data type!"); - return null; - } - } - - //ore dict implementation - if(dict) { - - if(OreDictionary.doesOreNameExist(item)) { - return new OreDictStack(item, stacksize); - } else { - - MainRegistry.logger.error("Error reading recipe, ore dict name does not exist!"); - return null; - } - - //comparable stack - } else { - - //if index 4 exists, eval it as a meta - if(array.size() > 3 && array.get(3).isJsonPrimitive()) { - - if(array.get(3).getAsJsonPrimitive().isNumber()) { - - meta = Math.max(0, array.get(3).getAsJsonPrimitive().getAsNumber().intValue()); - - } else { - - MainRegistry.logger.error("Error reading recipe, metadata is not a valid data type!"); - return null; - } - } - - Item it = (Item)Item.itemRegistry.getObject(item); - - if(it == null) { - - MainRegistry.logger.error("Item could not be found!"); - return null; - } - - return new ComparableStack(it, stacksize, meta); - } - } - - public static void saveTemplateJSON(File dir) { - - template = new File(dir.getAbsolutePath() + File.separatorChar + "_hbmAssembler.json"); - - try { - - JsonWriter writer = new JsonWriter(new FileWriter(template)); - writer.setIndent(" "); - - writer.beginObject(); - - writer.name("recipes").beginArray(); - - for(ComparableStack output : recipeList) { - - writer.beginObject(); - writer.name("output").beginArray(); - writer.setIndent(""); - writer.value("item"); - writer.value(Item.itemRegistry.getNameForObject(output.toStack().getItem())); - writer.value(output.stacksize); - if(output.meta > 0) - writer.value(output.meta); - writer.endArray(); - writer.setIndent(" "); - - - writer.name("input").beginArray(); - - AStack[] inputs = recipes.get(output); - for(AStack astack : inputs) { - - writer.beginArray(); - writer.setIndent(""); - - if(astack instanceof ComparableStack) { - ComparableStack comp = (ComparableStack) astack; - - writer.value("item"); - writer.value(Item.itemRegistry.getNameForObject(comp.toStack().getItem())); - writer.value(comp.stacksize); - if(comp.meta > 0) - writer.value(comp.meta); - } - - if(astack instanceof OreDictStack) { - OreDictStack ore = (OreDictStack) astack; - - writer.value("dict"); - writer.value(ore.name); - writer.value(ore.stacksize); - } - - writer.endArray(); - writer.setIndent(" "); - } - - writer.endArray(); - - writer.name("duration").value(time.get(output)); - - writer.endObject(); - } - - writer.endArray(); - writer.endObject(); - writer.close(); - - } catch(IOException e) { - //shush + recipe.ingredients = news; } } @@ -1568,18 +1315,13 @@ public class AssemblerRecipes { Map> recipes = new HashMap(); - for(Entry entry : AssemblerRecipes.recipes.entrySet()) { + for(Entry entry : AssemblerRecipes.recipes.entrySet()) { List value = new ArrayList(); + AssemblerRecipe recipe = entry.getValue(); - for(AStack o : entry.getValue()) { - - if(o instanceof ComparableStack) { - value.add(((ComparableStack)o).toStack()); - - } else if(o instanceof OreDictStack) { - value.add(((OreDictStack)o).extractForNEI()); - } + for(AStack o : recipe.ingredients) { + value.add(o.extractForNEI()); } recipes.put(entry.getKey().toStack(), value); @@ -1587,4 +1329,22 @@ public class AssemblerRecipes { return recipes; } + + public static class AssemblerRecipe { + + public AStack[] ingredients; + public int time; + public HashSet folders; + + public AssemblerRecipe(AStack[] ingredients, int time) { + this(ingredients, time, ModItems.template_folder); + } + + public AssemblerRecipe(AStack[] ingredients, int time, Item... folder) { + this.ingredients = ingredients; + this.time = time; + this.folders = new HashSet(); + for(Item item : folder) this.folders.add(item); + } + } } diff --git a/src/main/java/com/hbm/inventory/recipes/anvil/AnvilRecipes.java b/src/main/java/com/hbm/inventory/recipes/anvil/AnvilRecipes.java index 794daf237..e510ee224 100644 --- a/src/main/java/com/hbm/inventory/recipes/anvil/AnvilRecipes.java +++ b/src/main/java/com/hbm/inventory/recipes/anvil/AnvilRecipes.java @@ -12,6 +12,7 @@ import com.hbm.inventory.RecipesCommon.ComparableStack; import com.hbm.inventory.RecipesCommon.OreDictStack; import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.recipes.AssemblerRecipes; +import com.hbm.inventory.recipes.AssemblerRecipes.AssemblerRecipe; import com.hbm.items.ItemAmmoEnums.*; import com.hbm.items.ItemEnums.EnumChunkType; import com.hbm.items.ModItems; @@ -1058,10 +1059,10 @@ public class AnvilRecipes { public static void pullFromAssembler(ComparableStack result, int tier) { - AStack[] ingredients = AssemblerRecipes.recipes.get(result); + AssemblerRecipe recipe = AssemblerRecipes.recipes.get(result); - if(ingredients != null) { - constructionRecipes.add(new AnvilConstructionRecipe(ingredients, new AnvilOutput(result.toStack())).setTier(tier)); + if(recipe != null) { + constructionRecipes.add(new AnvilConstructionRecipe(recipe.ingredients, new AnvilOutput(result.toStack())).setTier(tier)); } } diff --git a/src/main/java/com/hbm/inventory/recipes/loader/SerializableRecipe.java b/src/main/java/com/hbm/inventory/recipes/loader/SerializableRecipe.java index ac32b1332..c187fd17a 100644 --- a/src/main/java/com/hbm/inventory/recipes/loader/SerializableRecipe.java +++ b/src/main/java/com/hbm/inventory/recipes/loader/SerializableRecipe.java @@ -67,6 +67,7 @@ public abstract class SerializableRecipe { recipeHandlers.add(new ElectrolyserMetalRecipes()); recipeHandlers.add(new ArcWelderRecipes()); recipeHandlers.add(new ExposureChamberRecipes()); + recipeHandlers.add(new AssemblerRecipes()); recipeHandlers.add(new MatDistribution()); recipeHandlers.add(new CustomMachineRecipes()); diff --git a/src/main/java/com/hbm/items/machine/ItemAssemblyTemplate.java b/src/main/java/com/hbm/items/machine/ItemAssemblyTemplate.java index a25a54983..d3e58e448 100644 --- a/src/main/java/com/hbm/items/machine/ItemAssemblyTemplate.java +++ b/src/main/java/com/hbm/items/machine/ItemAssemblyTemplate.java @@ -7,6 +7,7 @@ import java.util.List; import com.hbm.inventory.RecipesCommon.ComparableStack; import com.hbm.inventory.RecipesCommon.OreDictStack; import com.hbm.inventory.recipes.AssemblerRecipes; +import com.hbm.inventory.recipes.AssemblerRecipes.AssemblerRecipe; import com.hbm.items.ModItems; import com.hbm.util.I18nUtil; @@ -37,8 +38,9 @@ public class ItemAssemblyTemplate extends Item { public IIcon getIconFromDamage(int meta) { ComparableStack stack = AssemblerRecipes.recipeList.get(meta); + AssemblerRecipe recipe = AssemblerRecipes.recipes.get(stack); - if(AssemblerRecipes.hidden.get(stack) != null) + if(recipe != null && !recipe.folders.contains(ModItems.template_folder)) return this.hiddenIcon; return this.itemIcon; @@ -52,7 +54,9 @@ public class ItemAssemblyTemplate extends Item { //LEGACY if(out == null) out = AssemblerRecipes.recipeList.get(stack.getItemDamage()); - if(AssemblerRecipes.hidden.get(out) != null) + AssemblerRecipe recipe = AssemblerRecipes.recipes.get(stack); + + if(recipe != null && !recipe.folders.contains(ModItems.template_folder)) return this.hiddenIcon; return this.itemIcon; @@ -144,12 +148,11 @@ public class ItemAssemblyTemplate extends Item { ComparableStack out = readType(stack); //LEGACY if(out == null) out = AssemblerRecipes.recipeList.get(i); - Integer time = AssemblerRecipes.time.get(out); - - if(time != null) - return time; - else - return 100; + AssemblerRecipe recipe = AssemblerRecipes.recipes.get(out); + + if(recipe != null) return recipe.time; + + return 100; } @Override @@ -174,7 +177,14 @@ public class ItemAssemblyTemplate extends Item { out = AssemblerRecipes.recipeList.get(i); nbtType = false; } - HashSet folders = AssemblerRecipes.hidden.get(out); + + AssemblerRecipe recipe = AssemblerRecipes.recipes.get(out); + if(recipe == null) { + list.add("I AM ERROR"); + return; + } + + HashSet folders = recipe.folders; if(folders == null) folders = new HashSet() { @@ -206,7 +216,7 @@ public class ItemAssemblyTemplate extends Item { return; } - Object[] in = AssemblerRecipes.recipes.get(out); + Object[] in = recipe.ingredients; if(in == null) { list.add("I AM ERROR"); diff --git a/src/main/java/com/hbm/main/MainRegistry.java b/src/main/java/com/hbm/main/MainRegistry.java index 3928f0aa8..890c996c6 100644 --- a/src/main/java/com/hbm/main/MainRegistry.java +++ b/src/main/java/com/hbm/main/MainRegistry.java @@ -285,7 +285,6 @@ public class MainRegistry { Satellite.register(); HTTPHandler.loadStats(); CraftingManager.mainRegistry(); - AssemblerRecipes.preInit(PreEvent.getModConfigurationDirectory()); SiegeTier.registerTiers(); HazardRegistry.registerItems(); HazardRegistry.registerTrafos(); @@ -843,11 +842,9 @@ public class MainRegistry { @EventHandler public static void PostLoad(FMLPostInitializationEvent PostEvent) { TileEntityNukeFurnace.registerFuels(); - AssemblerRecipes.loadRecipes(); MagicRecipes.register(); LemegetonRecipes.register(); SILEXRecipes.register(); - AnvilRecipes.register(); RefineryRecipes.registerRefinery(); GasCentrifugeRecipes.register(); @@ -856,6 +853,9 @@ public class MainRegistry { //the good stuff SerializableRecipe.registerAllHandlers(); SerializableRecipe.initialize(); + + //Anvil has to come after serializables (i.e. anvil) + AnvilRecipes.register(); //has to register after cracking, and therefore after all serializable recipes RadiolysisRecipes.registerRadiolysis();