This commit is contained in:
WayofTime 2014-01-17 14:12:49 -05:00
commit 8601e9faff
498 changed files with 45817 additions and 0 deletions

View file

@ -0,0 +1,73 @@
package thaumcraft.api.crafting;
import java.util.ArrayList;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import thaumcraft.api.ThaumcraftApiHelper;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
public class CrucibleRecipe
{
public ItemStack recipeOutput;
public Object catalyst;
public AspectList aspects;
public String key;
public CrucibleRecipe(String researchKey, ItemStack result, Object cat, AspectList tags)
{
recipeOutput = result;
this.aspects = tags;
this.key = researchKey;
this.catalyst = cat;
if (cat instanceof String)
{
this.catalyst = OreDictionary.getOres((String) cat);
}
}
public boolean matches(AspectList itags, ItemStack cat)
{
if (catalyst instanceof ItemStack &&
!ThaumcraftApiHelper.itemMatches((ItemStack) catalyst, cat, false))
{
return false;
}
else if (catalyst instanceof ArrayList && ((ArrayList<ItemStack>)catalyst).size() > 0)
{
if (!ThaumcraftApiHelper.containsMatch(true, ((ArrayList<ItemStack>)catalyst).toArray(new ItemStack[] {}), cat)) return false;
}
if (itags == null)
{
return false;
}
for (Aspect tag: aspects.getAspects())
{
if (itags.getAmount(tag) < aspects.getAmount(tag))
{
return false;
}
}
return true;
}
public AspectList removeMatching(AspectList itags)
{
AspectList temptags = new AspectList();
temptags.aspects.putAll(itags.aspects);
for (Aspect tag: aspects.getAspects())
{
temptags.remove(tag, aspects.getAmount(tag));
// if (!temptags.remove(tag, aspects.getAmount(tag))) return null;
}
itags = temptags;
return itags;
}
}

View file

@ -0,0 +1,30 @@
package thaumcraft.api.crafting;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import thaumcraft.api.aspects.AspectList;
public interface IArcaneRecipe
{
/**
* Used to check if a recipe matches current crafting inventory
* @param player
*/
boolean matches(IInventory var1, World world, EntityPlayer player);
/**
* Returns an Item that is the result of this recipe
*/
ItemStack getCraftingResult(IInventory var1);
/**
* Returns the size of the recipe area
*/
int getRecipeSize();
ItemStack getRecipeOutput();
AspectList getAspects();
String getResearch();
}

View file

@ -0,0 +1,206 @@
package thaumcraft.api.crafting;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import thaumcraft.api.ThaumcraftApiHelper;
import thaumcraft.api.aspects.AspectList;
public class InfusionEnchantmentRecipe
{
public AspectList aspects;
public String research;
public ItemStack[] components;
public Enchantment enchantment;
public int recipeXP;
public int instability;
public InfusionEnchantmentRecipe(String research, Enchantment input, int inst,
AspectList aspects2, ItemStack[] recipe)
{
this.research = research;
this.enchantment = input;
this.aspects = aspects2;
this.components = recipe;
this.instability = inst;
this.recipeXP = Math.max(1, input.getMinEnchantability(1) / 3);
}
/**
* Used to check if a recipe matches current crafting inventory
* @param player
*/
public boolean matches(ArrayList<ItemStack> input, ItemStack central, World world, EntityPlayer player)
{
if (research.length() > 0 && !ThaumcraftApiHelper.isResearchComplete(player.username, research))
{
return false;
}
if (!enchantment.canApply(central))
{
return false;
}
Map map1 = EnchantmentHelper.getEnchantments(central);
Iterator iterator = map1.keySet().iterator();
while (iterator.hasNext())
{
int j1 = ((Integer)iterator.next()).intValue();
Enchantment ench = Enchantment.enchantmentsList[j1];
if (j1 == enchantment.effectId &&
EnchantmentHelper.getEnchantmentLevel(j1, central) >= ench.getMaxLevel())
{
return false;
}
if (enchantment.effectId != ench.effectId &&
(!enchantment.canApplyTogether(ench) ||
!ench.canApplyTogether(enchantment)))
{
return false;
}
}
ItemStack i2 = null;
ArrayList<ItemStack> ii = new ArrayList<ItemStack>();
for (ItemStack is: input)
{
ii.add(is.copy());
}
for (ItemStack comp: components)
{
boolean b = false;
for (int a = 0; a < ii.size(); a++)
{
i2 = ii.get(a).copy();
if (comp.getItemDamage() == OreDictionary.WILDCARD_VALUE)
{
i2.setItemDamage(OreDictionary.WILDCARD_VALUE);
}
if (areItemStacksEqual(i2, comp, true))
{
ii.remove(a);
b = true;
break;
}
}
if (!b)
{
return false;
}
}
// System.out.println(ii.size());
return ii.size() == 0 ? true : false;
}
private boolean areItemStacksEqual(ItemStack stack0, ItemStack stack1, boolean fuzzy)
{
if (stack0 == null && stack1 != null)
{
return false;
}
if (stack0 != null && stack1 == null)
{
return false;
}
if (stack0 == null && stack1 == null)
{
return true;
}
boolean t1 = false;
if (fuzzy)
{
t1 = true;
int od = OreDictionary.getOreID(stack0);
if (od != -1)
{
ItemStack[] ores = OreDictionary.getOres(od).toArray(new ItemStack[] {});
if (ThaumcraftApiHelper.containsMatch(false, new ItemStack[] {stack1}, ores))
return true;
}
}
else
{
t1 = ItemStack.areItemStackTagsEqual(stack0, stack1);
}
return stack0.itemID != stack1.itemID ? false : (stack0.getItemDamage() != stack1.getItemDamage() ? false : (stack0.stackSize > stack0.getMaxStackSize() ? false : t1));
}
public Enchantment getEnchantment()
{
return enchantment;
}
public AspectList getAspects()
{
return aspects;
}
public String getResearch()
{
return research;
}
public int calcInstability(ItemStack recipeInput)
{
int i = 0;
Map map1 = EnchantmentHelper.getEnchantments(recipeInput);
Iterator iterator = map1.keySet().iterator();
while (iterator.hasNext())
{
int j1 = ((Integer)iterator.next()).intValue();
i += EnchantmentHelper.getEnchantmentLevel(j1, recipeInput);
}
return (i / 2) + instability;
}
public int calcXP(ItemStack recipeInput)
{
return recipeXP * (1 + EnchantmentHelper.getEnchantmentLevel(enchantment.effectId, recipeInput));
}
public float getEssentiaMod(ItemStack recipeInput)
{
float mod = EnchantmentHelper.getEnchantmentLevel(enchantment.effectId, recipeInput);
Map map1 = EnchantmentHelper.getEnchantments(recipeInput);
Iterator iterator = map1.keySet().iterator();
while (iterator.hasNext())
{
int j1 = ((Integer)iterator.next()).intValue();
if (j1 != enchantment.effectId)
{
mod += EnchantmentHelper.getEnchantmentLevel(j1, recipeInput) * .1f;
}
}
return mod;
}
}

View file

@ -0,0 +1,147 @@
package thaumcraft.api.crafting;
import java.util.ArrayList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import thaumcraft.api.ThaumcraftApiHelper;
import thaumcraft.api.aspects.AspectList;
public class InfusionRecipe
{
public AspectList aspects;
public String research;
public ItemStack[] components;
public ItemStack recipeInput;
public Object recipeOutput;
public int instability;
public InfusionRecipe(String research, Object output, int inst,
AspectList aspects2, ItemStack input, ItemStack[] recipe)
{
this.research = research;
this.recipeOutput = output;
this.recipeInput = input;
this.aspects = aspects2;
this.components = recipe;
this.instability = inst;
}
/**
* Used to check if a recipe matches current crafting inventory
* @param player
*/
public boolean matches(ArrayList<ItemStack> input, ItemStack central, World world, EntityPlayer player)
{
if (research.length() > 0 && !ThaumcraftApiHelper.isResearchComplete(player.username, research))
{
return false;
}
ItemStack i2 = central.copy();
if (recipeInput.getItemDamage() == OreDictionary.WILDCARD_VALUE)
{
i2.setItemDamage(OreDictionary.WILDCARD_VALUE);
}
if (!areItemStacksEqual(i2, recipeInput, true))
{
return false;
}
ArrayList<ItemStack> ii = new ArrayList<ItemStack>();
for (ItemStack is: input)
{
ii.add(is.copy());
}
for (ItemStack comp: components)
{
boolean b = false;
for (int a = 0; a < ii.size(); a++)
{
i2 = ii.get(a).copy();
if (comp.getItemDamage() == OreDictionary.WILDCARD_VALUE)
{
i2.setItemDamage(OreDictionary.WILDCARD_VALUE);
}
if (areItemStacksEqual(i2, comp, true))
{
ii.remove(a);
b = true;
break;
}
}
if (!b)
{
return false;
}
}
// System.out.println(ii.size());
return ii.size() == 0 ? true : false;
}
private boolean areItemStacksEqual(ItemStack stack0, ItemStack stack1, boolean fuzzy)
{
if (stack0 == null && stack1 != null)
{
return false;
}
if (stack0 != null && stack1 == null)
{
return false;
}
if (stack0 == null && stack1 == null)
{
return true;
}
boolean t1 = false;
if (fuzzy)
{
t1 = true;
int od = OreDictionary.getOreID(stack0);
if (od != -1)
{
ItemStack[] ores = OreDictionary.getOres(od).toArray(new ItemStack[] {});
if (ThaumcraftApiHelper.containsMatch(false, new ItemStack[] {stack1}, ores))
return true;
}
}
else
{
t1 = ItemStack.areItemStackTagsEqual(stack0, stack1);
}
return stack0.itemID != stack1.itemID ? false : (stack0.getItemDamage() != stack1.getItemDamage() ? false : (stack0.stackSize > stack0.getMaxStackSize() ? false : t1));
}
public Object getRecipeOutput()
{
return recipeOutput;
}
public AspectList getAspects()
{
return aspects;
}
public String getResearch()
{
return research;
}
}

View file

@ -0,0 +1,282 @@
package thaumcraft.api.crafting;
import java.util.ArrayList;
import java.util.HashMap;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import thaumcraft.api.ThaumcraftApiHelper;
import thaumcraft.api.aspects.AspectList;
public class ShapedArcaneRecipe implements IArcaneRecipe
{
//Added in for future ease of change, but hard coded for now.
private static final int MAX_CRAFT_GRID_WIDTH = 3;
private static final int MAX_CRAFT_GRID_HEIGHT = 3;
public ItemStack output = null;
public Object[] input = null;
public AspectList aspects = null;
public String research;
public int width = 0;
public int height = 0;
private boolean mirrored = true;
public ShapedArcaneRecipe(String research, Block result, AspectList aspects, Object... recipe)
{
this(research, new ItemStack(result), aspects, recipe);
}
public ShapedArcaneRecipe(String research, Item result, AspectList aspects, Object... recipe)
{
this(research, new ItemStack(result), aspects, recipe);
}
public ShapedArcaneRecipe(String research, ItemStack result, AspectList aspects, Object... recipe)
{
output = result.copy();
this.research = research;
this.aspects = aspects;
String shape = "";
int idx = 0;
if (recipe[idx] instanceof Boolean)
{
mirrored = (Boolean)recipe[idx];
if (recipe[idx + 1] instanceof Object[])
{
recipe = (Object[])recipe[idx + 1];
}
else
{
idx = 1;
}
}
if (recipe[idx] instanceof String[])
{
String[] parts = ((String[])recipe[idx++]);
for (String s : parts)
{
width = s.length();
shape += s;
}
height = parts.length;
}
else
{
while (recipe[idx] instanceof String)
{
String s = (String)recipe[idx++];
shape += s;
width = s.length();
height++;
}
}
if (width * height != shape.length())
{
String ret = "Invalid shaped ore recipe: ";
for (Object tmp : recipe)
{
ret += tmp + ", ";
}
ret += output;
throw new RuntimeException(ret);
}
HashMap<Character, Object> itemMap = new HashMap<Character, Object>();
for (; idx < recipe.length; idx += 2)
{
Character chr = (Character)recipe[idx];
Object in = recipe[idx + 1];
if (in instanceof ItemStack)
{
itemMap.put(chr, ((ItemStack)in).copy());
}
else if (in instanceof Item)
{
itemMap.put(chr, new ItemStack((Item)in));
}
else if (in instanceof Block)
{
itemMap.put(chr, new ItemStack((Block)in, 1, OreDictionary.WILDCARD_VALUE));
}
else if (in instanceof String)
{
itemMap.put(chr, OreDictionary.getOres((String)in));
}
else
{
String ret = "Invalid shaped ore recipe: ";
for (Object tmp : recipe)
{
ret += tmp + ", ";
}
ret += output;
throw new RuntimeException(ret);
}
}
input = new Object[width * height];
int x = 0;
for (char chr : shape.toCharArray())
{
input[x++] = itemMap.get(chr);
}
}
@Override
public ItemStack getCraftingResult(IInventory var1)
{
return output.copy();
}
@Override
public int getRecipeSize()
{
return input.length;
}
@Override
public ItemStack getRecipeOutput()
{
return output;
}
@Override
public boolean matches(IInventory inv, World world, EntityPlayer player)
{
if (research.length() > 0 && !ThaumcraftApiHelper.isResearchComplete(player.username, research))
{
return false;
}
for (int x = 0; x <= MAX_CRAFT_GRID_WIDTH - width; x++)
{
for (int y = 0; y <= MAX_CRAFT_GRID_HEIGHT - height; ++y)
{
if (checkMatch(inv, x, y, false))
{
return true;
}
if (mirrored && checkMatch(inv, x, y, true))
{
return true;
}
}
}
return false;
}
private boolean checkMatch(IInventory inv, int startX, int startY, boolean mirror)
{
for (int x = 0; x < MAX_CRAFT_GRID_WIDTH; x++)
{
for (int y = 0; y < MAX_CRAFT_GRID_HEIGHT; y++)
{
int subX = x - startX;
int subY = y - startY;
Object target = null;
if (subX >= 0 && subY >= 0 && subX < width && subY < height)
{
if (mirror)
{
target = input[width - subX - 1 + subY * width];
}
else
{
target = input[subX + subY * width];
}
}
ItemStack slot = ThaumcraftApiHelper.getStackInRowAndColumn(inv, x, y);
if (target instanceof ItemStack)
{
if (!checkItemEquals((ItemStack)target, slot))
{
return false;
}
}
else if (target instanceof ArrayList)
{
boolean matched = false;
for (ItemStack item : (ArrayList<ItemStack>)target)
{
matched = matched || checkItemEquals(item, slot);
}
if (!matched)
{
return false;
}
}
else if (target == null && slot != null)
{
return false;
}
}
}
return true;
}
private boolean checkItemEquals(ItemStack target, ItemStack input)
{
if (input == null && target != null || input != null && target == null)
{
return false;
}
return (target.itemID == input.itemID &&
(!target.hasTagCompound() || ItemStack.areItemStackTagsEqual(target, input)) &&
(target.getItemDamage() == OreDictionary.WILDCARD_VALUE || target.getItemDamage() == input.getItemDamage()));
}
public ShapedArcaneRecipe setMirrored(boolean mirror)
{
mirrored = mirror;
return this;
}
/**
* Returns the input for this recipe, any mod accessing this value should never
* manipulate the values in this array as it will effect the recipe itself.
* @return The recipes input vales.
*/
public Object[] getInput()
{
return this.input;
}
@Override
public AspectList getAspects()
{
return aspects;
}
@Override
public String getResearch()
{
return research;
}
}

View file

@ -0,0 +1,172 @@
package thaumcraft.api.crafting;
import java.util.ArrayList;
import java.util.Iterator;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import thaumcraft.api.ThaumcraftApiHelper;
import thaumcraft.api.aspects.AspectList;
public class ShapelessArcaneRecipe implements IArcaneRecipe
{
private ItemStack output = null;
private ArrayList input = new ArrayList();
public AspectList aspects = null;
public String research;
public ShapelessArcaneRecipe(String research, Block result, AspectList aspects, Object... recipe)
{
this(research, new ItemStack(result), aspects, recipe);
}
public ShapelessArcaneRecipe(String research, Item result, AspectList aspects, Object... recipe)
{
this(research, new ItemStack(result), aspects, recipe);
}
public ShapelessArcaneRecipe(String research, ItemStack result, AspectList aspects, Object... recipe)
{
output = result.copy();
this.research = research;
this.aspects = aspects;
for (Object in : recipe)
{
if (in instanceof ItemStack)
{
input.add(((ItemStack)in).copy());
}
else if (in instanceof Item)
{
input.add(new ItemStack((Item)in));
}
else if (in instanceof Block)
{
input.add(new ItemStack((Block)in));
}
else if (in instanceof String)
{
input.add(OreDictionary.getOres((String)in));
}
else
{
String ret = "Invalid shapeless ore recipe: ";
for (Object tmp : recipe)
{
ret += tmp + ", ";
}
ret += output;
throw new RuntimeException(ret);
}
}
}
@Override
public int getRecipeSize()
{
return input.size();
}
@Override
public ItemStack getRecipeOutput()
{
return output;
}
@Override
public ItemStack getCraftingResult(IInventory var1)
{
return output.copy();
}
@Override
public boolean matches(IInventory var1, World world, EntityPlayer player)
{
if (research.length() > 0 && !ThaumcraftApiHelper.isResearchComplete(player.username, research))
{
return false;
}
ArrayList required = new ArrayList(input);
for (int x = 0; x < 9; x++)
{
ItemStack slot = var1.getStackInSlot(x);
if (slot != null)
{
boolean inRecipe = false;
Iterator req = required.iterator();
while (req.hasNext())
{
boolean match = false;
Object next = req.next();
if (next instanceof ItemStack)
{
match = checkItemEquals((ItemStack)next, slot);
}
else if (next instanceof ArrayList)
{
for (ItemStack item : (ArrayList<ItemStack>)next)
{
match = match || checkItemEquals(item, slot);
}
}
if (match)
{
inRecipe = true;
required.remove(next);
break;
}
}
if (!inRecipe)
{
return false;
}
}
}
return required.isEmpty();
}
private boolean checkItemEquals(ItemStack target, ItemStack input)
{
return (target.itemID == input.itemID &&
(!target.hasTagCompound() || ItemStack.areItemStackTagsEqual(target, input)) &&
(target.getItemDamage() == OreDictionary.WILDCARD_VALUE || target.getItemDamage() == input.getItemDamage()));
}
/**
* Returns the input for this recipe, any mod accessing this value should never
* manipulate the values in this array as it will effect the recipe itself.
* @return The recipes input vales.
*/
public ArrayList getInput()
{
return this.input;
}
@Override
public AspectList getAspects()
{
return aspects;
}
@Override
public String getResearch()
{
return research;
}
}