Organizing imports, cleaning up formatting, and lots of work on recipe registry in prep for building the new DynEMC graph structure

This commit is contained in:
pahimar 2013-07-03 14:36:35 -04:00
parent fa838f34bc
commit 1591f537c3
22 changed files with 278 additions and 273 deletions

View file

@ -1,6 +1,5 @@
package com.pahimar.ee3.core.util; package com.pahimar.ee3.core.util;
public class EnergyStack { public class EnergyStack {
public static final String VANILLA_SMELTING_ENERGY_NAME = "vanillaFuelValueUnits"; public static final String VANILLA_SMELTING_ENERGY_NAME = "vanillaFuelValueUnits";
@ -27,6 +26,7 @@ public class EnergyStack {
@Override @Override
public String toString() { public String toString() {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(String.format("%dxenergyStack.%s", stackSize, energyName)); stringBuilder.append(String.format("%dxenergyStack.%s", stackSize, energyName));

View file

@ -43,14 +43,14 @@ public class ItemUtil {
} }
/** /**
* Compares two ItemStacks for equality, testing itemID, metaData, stackSize, and their NBTTagCompounds (if they are present) * Compares two ItemStacks for equality, testing itemID, metaData,
* stackSize, and their NBTTagCompounds (if they are present)
* *
* @param first * @param first
* The first ItemStack being tested for equality * The first ItemStack being tested for equality
* @param second * @param second
* The second ItemStack being tested for equality * The second ItemStack being tested for equality
* @return * @return true if the two ItemStacks are equivalent, false otherwise
* true if the two ItemStacks are equivalent, false otherwise
*/ */
public static boolean compare(ItemStack first, ItemStack second) { public static boolean compare(ItemStack first, ItemStack second) {

View file

@ -30,9 +30,11 @@ import cpw.mods.fml.common.registry.GameRegistry;
public class RecipeHelper { public class RecipeHelper {
/** /**
* Discovers all instances of ItemStacks with wild card meta values in the vanilla Crafting Manager * Discovers all instances of ItemStacks with wild card meta values in the
* vanilla Crafting Manager
* *
* @return A list of CustomWrappedStacks that contains all wild card meta ItemStacks in the vanilla Crafting Manager * @return A list of CustomWrappedStacks that contains all wild card meta
* ItemStacks in the vanilla Crafting Manager
*/ */
public static ArrayList<CustomWrappedStack> populateWildCards() { public static ArrayList<CustomWrappedStack> populateWildCards() {
@ -83,11 +85,9 @@ public class RecipeHelper {
* @return List of elements that constitute the input of the given IRecipe. * @return List of elements that constitute the input of the given IRecipe.
* Could be an ItemStack or an Arraylist * Could be an ItemStack or an Arraylist
*/ */
@SuppressWarnings({ "rawtypes" })
public static ArrayList<CustomWrappedStack> getRecipeInputs(IRecipe recipe) { public static ArrayList<CustomWrappedStack> getRecipeInputs(IRecipe recipe) {
ArrayList<CustomWrappedStack> recipeInputs = new ArrayList<CustomWrappedStack>(); ArrayList<CustomWrappedStack> recipeInputs = new ArrayList<CustomWrappedStack>();
OreStack oreStack = null;
if (recipe instanceof ShapedRecipes) { if (recipe instanceof ShapedRecipes) {
@ -117,20 +117,7 @@ public class RecipeHelper {
/* /*
* If the element is a list, then it is an OreStack * If the element is a list, then it is an OreStack
*/ */
if (shapedOreRecipe.getInput()[i] instanceof ArrayList) { if (shapedOreRecipe.getInput()[i] instanceof ArrayList || shapedOreRecipe.getInput()[i] instanceof ItemStack) {
ArrayList shapedOreRecipeList = (ArrayList<?>) shapedOreRecipe.getInput()[i];
if (!shapedOreRecipeList.isEmpty()) {
oreStack = new OreStack((ItemStack) shapedOreRecipeList.get(0));
recipeInputs.add(new CustomWrappedStack(oreStack));
}
}
/*
* Else it is possibly an ItemStack
*/
else if (shapedOreRecipe.getInput()[i] instanceof ItemStack) {
recipeInputs.add(new CustomWrappedStack(shapedOreRecipe.getInput()[i])); recipeInputs.add(new CustomWrappedStack(shapedOreRecipe.getInput()[i]));
} }
} }
@ -140,17 +127,7 @@ public class RecipeHelper {
ShapelessOreRecipe shapelessOreRecipe = (ShapelessOreRecipe) recipe; ShapelessOreRecipe shapelessOreRecipe = (ShapelessOreRecipe) recipe;
for (Object object : shapelessOreRecipe.getInput()) { for (Object object : shapelessOreRecipe.getInput()) {
if (object instanceof ArrayList) { if (object instanceof ArrayList || object instanceof ItemStack) {
ArrayList shapelessOreRecipeList = (ArrayList<?>) object;
if (!shapelessOreRecipeList.isEmpty()) {
oreStack = new OreStack((ItemStack) shapelessOreRecipeList.get(0));
recipeInputs.add(new CustomWrappedStack(oreStack));
}
}
else if (object instanceof ItemStack) {
recipeInputs.add(new CustomWrappedStack(object)); recipeInputs.add(new CustomWrappedStack(object));
} }
} }

View file

@ -53,7 +53,6 @@ public class TransmutationHelper {
if (currentBlock != null) { if (currentBlock != null) {
meta = currentBlock.damageDropped(meta); meta = currentBlock.damageDropped(meta);
currentBlockStack = new ItemStack(id, 1, meta); currentBlockStack = new ItemStack(id, 1, meta);
if (previousBlockStack == null) { if (previousBlockStack == null) {

View file

@ -12,6 +12,7 @@ import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipe;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.pahimar.ee3.core.util.LogHelper; import com.pahimar.ee3.core.util.LogHelper;
import com.pahimar.ee3.core.util.OreStack; import com.pahimar.ee3.core.util.OreStack;
@ -22,6 +23,7 @@ import com.pahimar.ee3.item.CustomWrappedStack;
import com.pahimar.ee3.item.crafting.RecipeRegistry; import com.pahimar.ee3.item.crafting.RecipeRegistry;
import com.pahimar.ee3.item.crafting.RecipesPotions; import com.pahimar.ee3.item.crafting.RecipesPotions;
import com.pahimar.ee3.item.crafting.RecipesSmelting; import com.pahimar.ee3.item.crafting.RecipesSmelting;
import com.pahimar.ee3.item.crafting.RecipesVanilla;
public class DynEMC { public class DynEMC {
@ -51,46 +53,38 @@ public class DynEMC {
RecipeRegistry recipeManager = RecipeRegistry.getInstance(); RecipeRegistry recipeManager = RecipeRegistry.getInstance();
Set<CustomWrappedStack> keySet = null; Multimap<CustomWrappedStack, List<CustomWrappedStack>> recipes = HashMultimap.create();
Iterator<CustomWrappedStack> keySetIter = null; Set<CustomWrappedStack> recipeKeySet = null;
CustomWrappedStack key = null; Iterator<CustomWrappedStack> recipeKeySetIterator = null;
CustomWrappedStack recipeOutput = null;
/* Add Potions */ // Add potion recipes
Multimap<CustomWrappedStack, List<CustomWrappedStack>> potionRecipes = RecipesPotions.getPotionRecipes(); recipes.putAll(RecipesPotions.getPotionRecipes());
keySet = potionRecipes.keySet(); // Add smelting recipes in the vanilla smelting manager
keySetIter = keySet.iterator(); recipes.putAll(RecipesSmelting.getSmeltingRecipes());
key = null;
while (keySetIter.hasNext()) { // Add recipes in the vanilla crafting manager
key = keySetIter.next(); recipes.putAll(RecipesVanilla.getVanillaRecipes());
for (List<CustomWrappedStack> potionInputs : potionRecipes.get(key)) { // Add recipes gathered via IMC
recipeManager.addRecipe(key, potionInputs); // TODO Gather IMC recipes
// Add items that have no recipe
// Iterate through every recipe in the map, and add them to the registry
recipeKeySet = recipes.keySet();
recipeKeySetIterator = recipeKeySet.iterator();
recipeOutput = null;
while (recipeKeySetIterator.hasNext()) {
recipeOutput = recipeKeySetIterator.next();
for (List<CustomWrappedStack> recipeInputs : recipes.get(recipeOutput)) {
recipeManager.addRecipe(recipeOutput, recipeInputs);
} }
} }
/* Add Smelting */
Multimap<CustomWrappedStack, List<CustomWrappedStack>> smeltingRecipes = RecipesSmelting.getSmeltingRecipes();
keySet = smeltingRecipes.keySet();
keySetIter = keySet.iterator();
key = null;
while (keySetIter.hasNext()) {
key = keySetIter.next();
for (List<CustomWrappedStack> smeltingInputs : smeltingRecipes.get(key)) {
recipeManager.addRecipe(key, smeltingInputs);
}
}
/* Add vanilla crafting */
/* Add recipes sent via IMC */
/* Add all other items that don't have some method of crafting */
LogHelper.debug(recipeManager.toString()); LogHelper.debug(recipeManager.toString());
} }

View file

@ -65,7 +65,6 @@ public class EmcBlackList {
this.add(id, OreDictionary.WILDCARD_VALUE); this.add(id, OreDictionary.WILDCARD_VALUE);
} }
public boolean contains(ItemStack itemStack) { public boolean contains(ItemStack itemStack) {
if (itemStack != null) { if (itemStack != null) {

View file

@ -1,6 +1,5 @@
package com.pahimar.ee3.emc; package com.pahimar.ee3.emc;
public class EmcComponent { public class EmcComponent {
private final EmcType emcType; private final EmcType emcType;

View file

@ -1,6 +1,5 @@
package com.pahimar.ee3.emc; package com.pahimar.ee3.emc;
public enum EmcType { public enum EmcType {
CORPOREAL, KINETIC, TEMPORAL, ESSENTIA, AMORPHOUS, VOID, OMNI; CORPOREAL, KINETIC, TEMPORAL, ESSENTIA, AMORPHOUS, VOID, OMNI;
} }

View file

@ -19,7 +19,8 @@ public class EmcValue {
public EmcValue() { public EmcValue() {
value = 0F;; value = 0F;
;
recoveryPercentage = 1F; recoveryPercentage = 1F;
emcComponents = new ArrayList<EmcComponent>(); emcComponents = new ArrayList<EmcComponent>();
} }

View file

@ -62,8 +62,9 @@ public class ContainerAludel extends Container {
itemStack = slotItemStack.copy(); itemStack = slotItemStack.copy();
/** /**
* If we are shift-clicking an item out of the Aludel's container, attempt to put it in the first available slot in the * If we are shift-clicking an item out of the Aludel's container,
* player's inventory * attempt to put it in the first available slot in the player's
* inventory
*/ */
if (slotIndex < TileAludel.INVENTORY_SIZE) { if (slotIndex < TileAludel.INVENTORY_SIZE) {
@ -74,8 +75,10 @@ public class ContainerAludel extends Container {
else { else {
/** /**
* If the stack being shift-clicked into the Aludel's container is a fuel, first try to put it in the fuel slot. * If the stack being shift-clicked into the Aludel's container
* If it cannot be merged into the fuel slot, try to put it in the input slot. * is a fuel, first try to put it in the fuel slot. If it cannot
* be merged into the fuel slot, try to put it in the input
* slot.
*/ */
if (TileEntityFurnace.isItemFuel(slotItemStack)) { if (TileEntityFurnace.isItemFuel(slotItemStack)) {
if (!this.mergeItemStack(slotItemStack, TileAludel.FUEL_INVENTORY_INDEX, TileAludel.INPUT_INVENTORY_INDEX, false)) { if (!this.mergeItemStack(slotItemStack, TileAludel.FUEL_INVENTORY_INDEX, TileAludel.INPUT_INVENTORY_INDEX, false)) {
@ -84,8 +87,10 @@ public class ContainerAludel extends Container {
} }
/** /**
* If the stack being shift-clicked into the Aludel's container is a dust, first try to put it in the dust slot. * If the stack being shift-clicked into the Aludel's container
* If it cannot be merged into the dust slot, try to put it in the input slot. * is a dust, first try to put it in the dust slot. If it cannot
* be merged into the dust slot, try to put it in the input
* slot.
*/ */
else if (slotItemStack.getItem() instanceof ItemAlchemicalDust) { else if (slotItemStack.getItem() instanceof ItemAlchemicalDust) {
if (!this.mergeItemStack(slotItemStack, TileAludel.DUST_INVENTORY_INDEX, TileAludel.OUTPUT_INVENTORY_INDEX, false)) { if (!this.mergeItemStack(slotItemStack, TileAludel.DUST_INVENTORY_INDEX, TileAludel.OUTPUT_INVENTORY_INDEX, false)) {

View file

@ -62,8 +62,9 @@ public class ContainerCalcinator extends Container {
itemStack = slotItemStack.copy(); itemStack = slotItemStack.copy();
/** /**
* If we are shift-clicking an item out of the Aludel's container, attempt to put it in the first available slot in the * If we are shift-clicking an item out of the Aludel's container,
* player's inventory * attempt to put it in the first available slot in the player's
* inventory
*/ */
if (slotIndex < TileCalcinator.INVENTORY_SIZE) { if (slotIndex < TileCalcinator.INVENTORY_SIZE) {
@ -74,8 +75,10 @@ public class ContainerCalcinator extends Container {
else { else {
/** /**
* If the stack being shift-clicked into the Aludel's container is a fuel, first try to put it in the fuel slot. * If the stack being shift-clicked into the Aludel's container
* If it cannot be merged into the fuel slot, try to put it in the input slot. * is a fuel, first try to put it in the fuel slot. If it cannot
* be merged into the fuel slot, try to put it in the input
* slot.
*/ */
if (TileEntityFurnace.isItemFuel(slotItemStack)) { if (TileEntityFurnace.isItemFuel(slotItemStack)) {
if (!this.mergeItemStack(slotItemStack, TileCalcinator.FUEL_INVENTORY_INDEX, TileCalcinator.OUTPUT_INVENTORY_INDEX, false)) { if (!this.mergeItemStack(slotItemStack, TileCalcinator.FUEL_INVENTORY_INDEX, TileCalcinator.OUTPUT_INVENTORY_INDEX, false)) {

View file

@ -51,8 +51,7 @@ public class ContainerGlassBell extends Container {
ItemStack itemStack = null; ItemStack itemStack = null;
Slot slot = (Slot) inventorySlots.get(slotIndex); Slot slot = (Slot) inventorySlots.get(slotIndex);
if (slot != null && slot.getHasStack()) if (slot != null && slot.getHasStack()) {
{
ItemStack slotItemStack = slot.getStack(); ItemStack slotItemStack = slot.getStack();
itemStack = slotItemStack.copy(); itemStack = slotItemStack.copy();

View file

@ -1,11 +1,14 @@
package com.pahimar.ee3.item; package com.pahimar.ee3.item;
import java.util.ArrayList;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import com.pahimar.ee3.core.util.EnergyStack; import com.pahimar.ee3.core.util.EnergyStack;
import com.pahimar.ee3.core.util.ItemUtil; import com.pahimar.ee3.core.util.ItemUtil;
import com.pahimar.ee3.core.util.OreStack; import com.pahimar.ee3.core.util.OreStack;
import com.pahimar.ee3.lib.Reference;
public class CustomWrappedStack { public class CustomWrappedStack {
@ -37,11 +40,11 @@ public class CustomWrappedStack {
* If the ItemStack does not exist in the OreDictionary, wrap it as * If the ItemStack does not exist in the OreDictionary, wrap it as
* an ItemStack * an ItemStack
*/ */
if (OreDictionary.getOreID(itemStack) == -1) { if (OreDictionary.getOreID(itemStack) == Reference.ORE_DICTIONARY_NOT_FOUND) {
this.itemStack = itemStack; this.itemStack = itemStack.copy();
oreStack = null; oreStack = null;
energyStack = null; energyStack = null;
stackSize = itemStack.stackSize; stackSize = this.itemStack.stackSize;
this.itemStack.stackSize = 1; this.itemStack.stackSize = 1;
} }
/* /*
@ -67,6 +70,29 @@ public class CustomWrappedStack {
stackSize = oreStack.stackSize; stackSize = oreStack.stackSize;
oreStack.stackSize = 1; oreStack.stackSize = 1;
} }
else if (object instanceof ArrayList) {
itemStack = null;
ArrayList<?> objectList = (ArrayList<?>) object;
if (!objectList.isEmpty()) {
for (Object listElement : objectList) {
if (listElement instanceof ItemStack) {
ItemStack stack = (ItemStack) listElement;
if (OreDictionary.getOreID(stack) != Reference.ORE_DICTIONARY_NOT_FOUND) {
oreStack = new OreStack(stack);
stackSize = oreStack.stackSize;
oreStack.stackSize = 1;
break;
}
}
}
}
energyStack = null;
}
/* /*
* Or we are given an EnergyStack to wrap * Or we are given an EnergyStack to wrap
*/ */
@ -172,15 +198,7 @@ public class CustomWrappedStack {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
if (itemStack != null) { if (itemStack != null) {
stringBuilder.append(String.format("%sxitemStack[%s:%s:%s:%s]", this.stackSize, itemStack.itemID, itemStack.getItemDamage(), itemStack.getItemName(), itemStack.getItem().getClass().getCanonicalName()));
stringBuilder.append(String.format("itemID: %d, metaData: %d, stackSize: %d, ", itemStack.itemID, itemStack.getItemDamage(), stackSize));
if (itemStack.hasTagCompound()) {
stringBuilder.append(String.format("nbtTagCompound: %s, ", itemStack.getTagCompound().toString()));
}
stringBuilder.append(String.format("itemName: %s, className: %s ", itemStack.getItemName(), itemStack.getItem().getClass().toString()));
} }
else if (oreStack != null) { else if (oreStack != null) {
stringBuilder.append(String.format("%dxoreDictionary.%s", stackSize, oreStack.oreName)); stringBuilder.append(String.format("%dxoreDictionary.%s", stackSize, oreStack.oreName));

View file

@ -157,15 +157,10 @@ public class RecipeRegistry {
for (CustomWrappedStack key : recipeMap.keySet()) { for (CustomWrappedStack key : recipeMap.keySet()) {
Iterator<List<CustomWrappedStack>> recipeIterator = recipeMap.get(key).iterator(); Collection<List<CustomWrappedStack>> recipeMappings = recipeMap.get(key);
while (recipeIterator.hasNext()) { for (List<CustomWrappedStack> recipeList : recipeMappings) {
List<CustomWrappedStack> values = recipeIterator.next(); stringBuilder.append(String.format("Recipe Output: %s, Recipe Input: %s\n", key.toString(), recipeList.toString()));
stringBuilder.append(String.format("Recipe Output: %s, Recipe Input: %s", key.toString(), values.toString()));
if (recipeIterator.hasNext()) {
stringBuilder.append("\n");
}
} }
} }

View file

@ -3,8 +3,13 @@ package com.pahimar.ee3.item.crafting;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.pahimar.ee3.core.util.RecipeHelper;
import com.pahimar.ee3.item.CustomWrappedStack; import com.pahimar.ee3.item.CustomWrappedStack;
public class RecipesVanilla { public class RecipesVanilla {
@ -25,9 +30,19 @@ public class RecipesVanilla {
private static void init() { private static void init() {
vanillaRecipes = HashMultimap.create(); vanillaRecipes = HashMultimap.create();
}
private static void discoverItems() { for (Object recipeObject : CraftingManager.getInstance().getRecipeList()) {
if (recipeObject instanceof IRecipe) {
IRecipe recipe = (IRecipe) recipeObject;
ItemStack recipeOutput = recipe.getRecipeOutput();
if (recipeOutput != null) {
ArrayList<CustomWrappedStack> recipeInputs = RecipeHelper.getRecipeInputs(recipe);
vanillaRecipes.put(new CustomWrappedStack(recipeOutput), recipeInputs);
}
}
}
} }
} }

View file

@ -27,4 +27,6 @@ public class Reference {
public static final String CLIENT_PROXY_CLASS = "com.pahimar.ee3.core.proxy.ClientProxy"; public static final String CLIENT_PROXY_CLASS = "com.pahimar.ee3.core.proxy.ClientProxy";
public static final int VERSION_CHECK_ATTEMPTS = 3; public static final int VERSION_CHECK_ATTEMPTS = 3;
public static final int ORE_DICTIONARY_NOT_FOUND = -1;
} }