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:
parent
fa838f34bc
commit
1591f537c3
22 changed files with 278 additions and 273 deletions
|
@ -1,6 +1,5 @@
|
|||
package com.pahimar.ee3.core.util;
|
||||
|
||||
|
||||
public class EnergyStack {
|
||||
|
||||
public static final String VANILLA_SMELTING_ENERGY_NAME = "vanillaFuelValueUnits";
|
||||
|
@ -27,6 +26,7 @@ public class EnergyStack {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
stringBuilder.append(String.format("%dxenergyStack.%s", stackSize, energyName));
|
||||
|
|
|
@ -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
|
||||
* The first ItemStack being tested for equality
|
||||
* The first ItemStack being tested for equality
|
||||
* @param second
|
||||
* The second ItemStack being tested for equality
|
||||
* @return
|
||||
* true if the two ItemStacks are equivalent, false otherwise
|
||||
* The second ItemStack being tested for equality
|
||||
* @return true if the two ItemStacks are equivalent, false otherwise
|
||||
*/
|
||||
public static boolean compare(ItemStack first, ItemStack second) {
|
||||
|
||||
|
|
|
@ -30,9 +30,11 @@ import cpw.mods.fml.common.registry.GameRegistry;
|
|||
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() {
|
||||
|
||||
|
@ -83,11 +85,9 @@ public class RecipeHelper {
|
|||
* @return List of elements that constitute the input of the given IRecipe.
|
||||
* Could be an ItemStack or an Arraylist
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public static ArrayList<CustomWrappedStack> getRecipeInputs(IRecipe recipe) {
|
||||
|
||||
ArrayList<CustomWrappedStack> recipeInputs = new ArrayList<CustomWrappedStack>();
|
||||
OreStack oreStack = null;
|
||||
|
||||
if (recipe instanceof ShapedRecipes) {
|
||||
|
||||
|
@ -117,20 +117,7 @@ public class RecipeHelper {
|
|||
/*
|
||||
* If the element is a list, then it is an OreStack
|
||||
*/
|
||||
if (shapedOreRecipe.getInput()[i] instanceof ArrayList) {
|
||||
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) {
|
||||
if (shapedOreRecipe.getInput()[i] instanceof ArrayList || shapedOreRecipe.getInput()[i] instanceof ItemStack) {
|
||||
recipeInputs.add(new CustomWrappedStack(shapedOreRecipe.getInput()[i]));
|
||||
}
|
||||
}
|
||||
|
@ -140,17 +127,7 @@ public class RecipeHelper {
|
|||
ShapelessOreRecipe shapelessOreRecipe = (ShapelessOreRecipe) recipe;
|
||||
|
||||
for (Object object : shapelessOreRecipe.getInput()) {
|
||||
if (object instanceof ArrayList) {
|
||||
ArrayList shapelessOreRecipeList = (ArrayList<?>) object;
|
||||
|
||||
if (!shapelessOreRecipeList.isEmpty()) {
|
||||
|
||||
oreStack = new OreStack((ItemStack) shapelessOreRecipeList.get(0));
|
||||
|
||||
recipeInputs.add(new CustomWrappedStack(oreStack));
|
||||
}
|
||||
}
|
||||
else if (object instanceof ItemStack) {
|
||||
if (object instanceof ArrayList || object instanceof ItemStack) {
|
||||
recipeInputs.add(new CustomWrappedStack(object));
|
||||
}
|
||||
}
|
||||
|
@ -185,7 +162,7 @@ public class RecipeHelper {
|
|||
|
||||
if (OreDictionary.getOreID(recipe.getRecipeOutput()) != -1) {
|
||||
// TODO Generalize comparison of OreStacks and OreStacks|ItemStacks
|
||||
if (OreDictionary.getOreID(((OreStack)wrappedStack.getWrappedStack()).oreName) == OreDictionary.getOreID(recipe.getRecipeOutput())) {
|
||||
if (OreDictionary.getOreID(((OreStack) wrappedStack.getWrappedStack()).oreName) == OreDictionary.getOreID(recipe.getRecipeOutput())) {
|
||||
reverseRecipeList.add(recipe);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,6 @@ public class TransmutationHelper {
|
|||
if (currentBlock != null) {
|
||||
meta = currentBlock.damageDropped(meta);
|
||||
|
||||
|
||||
currentBlockStack = new ItemStack(id, 1, meta);
|
||||
|
||||
if (previousBlockStack == null) {
|
||||
|
|
|
@ -12,6 +12,7 @@ import net.minecraft.item.crafting.CraftingManager;
|
|||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.pahimar.ee3.core.util.LogHelper;
|
||||
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.RecipesPotions;
|
||||
import com.pahimar.ee3.item.crafting.RecipesSmelting;
|
||||
import com.pahimar.ee3.item.crafting.RecipesVanilla;
|
||||
|
||||
public class DynEMC {
|
||||
|
||||
|
@ -51,46 +53,38 @@ public class DynEMC {
|
|||
|
||||
RecipeRegistry recipeManager = RecipeRegistry.getInstance();
|
||||
|
||||
Set<CustomWrappedStack> keySet = null;
|
||||
Iterator<CustomWrappedStack> keySetIter = null;
|
||||
CustomWrappedStack key = null;
|
||||
Multimap<CustomWrappedStack, List<CustomWrappedStack>> recipes = HashMultimap.create();
|
||||
Set<CustomWrappedStack> recipeKeySet = null;
|
||||
Iterator<CustomWrappedStack> recipeKeySetIterator = null;
|
||||
CustomWrappedStack recipeOutput = null;
|
||||
|
||||
/* Add Potions */
|
||||
Multimap<CustomWrappedStack, List<CustomWrappedStack>> potionRecipes = RecipesPotions.getPotionRecipes();
|
||||
// Add potion recipes
|
||||
recipes.putAll(RecipesPotions.getPotionRecipes());
|
||||
|
||||
keySet = potionRecipes.keySet();
|
||||
keySetIter = keySet.iterator();
|
||||
key = null;
|
||||
// Add smelting recipes in the vanilla smelting manager
|
||||
recipes.putAll(RecipesSmelting.getSmeltingRecipes());
|
||||
|
||||
while (keySetIter.hasNext()) {
|
||||
key = keySetIter.next();
|
||||
// Add recipes in the vanilla crafting manager
|
||||
recipes.putAll(RecipesVanilla.getVanillaRecipes());
|
||||
|
||||
for (List<CustomWrappedStack> potionInputs : potionRecipes.get(key)) {
|
||||
recipeManager.addRecipe(key, potionInputs);
|
||||
// Add recipes gathered via IMC
|
||||
// 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());
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,6 @@ public class EmcBlackList {
|
|||
this.add(id, OreDictionary.WILDCARD_VALUE);
|
||||
}
|
||||
|
||||
|
||||
public boolean contains(ItemStack itemStack) {
|
||||
|
||||
if (itemStack != null) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.pahimar.ee3.emc;
|
||||
|
||||
|
||||
public class EmcComponent {
|
||||
|
||||
private final EmcType emcType;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.pahimar.ee3.emc;
|
||||
|
||||
|
||||
public enum EmcType {
|
||||
CORPOREAL, KINETIC, TEMPORAL, ESSENTIA, AMORPHOUS, VOID, OMNI;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,8 @@ public class EmcValue {
|
|||
|
||||
public EmcValue() {
|
||||
|
||||
value = 0F;;
|
||||
value = 0F;
|
||||
;
|
||||
recoveryPercentage = 1F;
|
||||
emcComponents = new ArrayList<EmcComponent>();
|
||||
}
|
||||
|
|
|
@ -62,8 +62,9 @@ public class ContainerAludel extends Container {
|
|||
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
|
||||
* player's inventory
|
||||
* If we are shift-clicking an item out of the Aludel's container,
|
||||
* attempt to put it in the first available slot in the player's
|
||||
* inventory
|
||||
*/
|
||||
if (slotIndex < TileAludel.INVENTORY_SIZE) {
|
||||
|
||||
|
@ -74,8 +75,10 @@ public class ContainerAludel extends Container {
|
|||
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 it cannot be merged into the fuel slot, try to put it in the input slot.
|
||||
* If the stack being shift-clicked into the Aludel's container
|
||||
* 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 (!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 it cannot be merged into the dust slot, try to put it in the input slot.
|
||||
* If the stack being shift-clicked into the Aludel's container
|
||||
* 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) {
|
||||
if (!this.mergeItemStack(slotItemStack, TileAludel.DUST_INVENTORY_INDEX, TileAludel.OUTPUT_INVENTORY_INDEX, false)) {
|
||||
|
|
|
@ -62,8 +62,9 @@ public class ContainerCalcinator extends Container {
|
|||
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
|
||||
* player's inventory
|
||||
* If we are shift-clicking an item out of the Aludel's container,
|
||||
* attempt to put it in the first available slot in the player's
|
||||
* inventory
|
||||
*/
|
||||
if (slotIndex < TileCalcinator.INVENTORY_SIZE) {
|
||||
|
||||
|
@ -74,8 +75,10 @@ public class ContainerCalcinator extends Container {
|
|||
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 it cannot be merged into the fuel slot, try to put it in the input slot.
|
||||
* If the stack being shift-clicked into the Aludel's container
|
||||
* 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 (!this.mergeItemStack(slotItemStack, TileCalcinator.FUEL_INVENTORY_INDEX, TileCalcinator.OUTPUT_INVENTORY_INDEX, false)) {
|
||||
|
|
|
@ -51,8 +51,7 @@ public class ContainerGlassBell extends Container {
|
|||
ItemStack itemStack = null;
|
||||
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
||||
|
||||
if (slot != null && slot.getHasStack())
|
||||
{
|
||||
if (slot != null && slot.getHasStack()) {
|
||||
ItemStack slotItemStack = slot.getStack();
|
||||
itemStack = slotItemStack.copy();
|
||||
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
package com.pahimar.ee3.item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.pahimar.ee3.core.util.EnergyStack;
|
||||
import com.pahimar.ee3.core.util.ItemUtil;
|
||||
import com.pahimar.ee3.core.util.OreStack;
|
||||
import com.pahimar.ee3.lib.Reference;
|
||||
|
||||
public class CustomWrappedStack {
|
||||
|
||||
|
@ -37,11 +40,11 @@ public class CustomWrappedStack {
|
|||
* If the ItemStack does not exist in the OreDictionary, wrap it as
|
||||
* an ItemStack
|
||||
*/
|
||||
if (OreDictionary.getOreID(itemStack) == -1) {
|
||||
this.itemStack = itemStack;
|
||||
if (OreDictionary.getOreID(itemStack) == Reference.ORE_DICTIONARY_NOT_FOUND) {
|
||||
this.itemStack = itemStack.copy();
|
||||
oreStack = null;
|
||||
energyStack = null;
|
||||
stackSize = itemStack.stackSize;
|
||||
stackSize = this.itemStack.stackSize;
|
||||
this.itemStack.stackSize = 1;
|
||||
}
|
||||
/*
|
||||
|
@ -67,6 +70,29 @@ public class CustomWrappedStack {
|
|||
stackSize = oreStack.stackSize;
|
||||
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
|
||||
*/
|
||||
|
@ -172,15 +198,7 @@ public class CustomWrappedStack {
|
|||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
if (itemStack != null) {
|
||||
|
||||
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()));
|
||||
|
||||
stringBuilder.append(String.format("%sxitemStack[%s:%s:%s:%s]", this.stackSize, itemStack.itemID, itemStack.getItemDamage(), itemStack.getItemName(), itemStack.getItem().getClass().getCanonicalName()));
|
||||
}
|
||||
else if (oreStack != null) {
|
||||
stringBuilder.append(String.format("%dxoreDictionary.%s", stackSize, oreStack.oreName));
|
||||
|
|
|
@ -157,15 +157,10 @@ public class RecipeRegistry {
|
|||
|
||||
for (CustomWrappedStack key : recipeMap.keySet()) {
|
||||
|
||||
Iterator<List<CustomWrappedStack>> recipeIterator = recipeMap.get(key).iterator();
|
||||
Collection<List<CustomWrappedStack>> recipeMappings = recipeMap.get(key);
|
||||
|
||||
while (recipeIterator.hasNext()) {
|
||||
List<CustomWrappedStack> values = recipeIterator.next();
|
||||
stringBuilder.append(String.format("Recipe Output: %s, Recipe Input: %s", key.toString(), values.toString()));
|
||||
|
||||
if (recipeIterator.hasNext()) {
|
||||
stringBuilder.append("\n");
|
||||
}
|
||||
for (List<CustomWrappedStack> recipeList : recipeMappings) {
|
||||
stringBuilder.append(String.format("Recipe Output: %s, Recipe Input: %s\n", key.toString(), recipeList.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,13 @@ package com.pahimar.ee3.item.crafting;
|
|||
import java.util.ArrayList;
|
||||
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.Multimap;
|
||||
import com.pahimar.ee3.core.util.RecipeHelper;
|
||||
import com.pahimar.ee3.item.CustomWrappedStack;
|
||||
|
||||
public class RecipesVanilla {
|
||||
|
@ -25,9 +30,19 @@ public class RecipesVanilla {
|
|||
private static void init() {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,4 +27,6 @@ public class Reference {
|
|||
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 ORE_DICTIONARY_NOT_FOUND = -1;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue