Removed use of MappableStackWrapper and used for-loop checking instead.

This commit is contained in:
Vasco Lavos committed 2014-02-15 00:14:18 +00:00
1 parent 6200b2efec
commit 95ed8be22d
6 files changed
+34 -78

No files matched your search

@@ -1,44 +0,0 @@
/**
* This class was created by <cpw>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [? (GMT)]
*/
package vazkii.botania.api.internal;
import net.minecraft.item.ItemStack;
public class MappableStackWrapper {
private ItemStack wrap;
public MappableStackWrapper(ItemStack toWrap) {
wrap = toWrap;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof MappableStackWrapper))
return false;
MappableStackWrapper isw = (MappableStackWrapper) obj;
if (wrap.getHasSubtypes())
return isw.wrap.isItemEqual(wrap);
else return isw.wrap == wrap;
}
public ItemStack getStack() {
return wrap;
}
@Override
public int hashCode() {
return System.identityHashCode(wrap);
}
}
@@ -17,7 +17,6 @@ import java.util.List;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import vazkii.botania.api.internal.MappableStackWrapper;
public class RecipePetals {
@@ -29,12 +28,8 @@ public class RecipePetals {
List<Object> inputsToSet = new ArrayList();
for(Object obj : inputs) {
if(obj instanceof String)
if(obj instanceof String || obj instanceof ItemStack)
inputsToSet.add(obj);
else if(obj instanceof MappableStackWrapper)
inputsToSet.add(obj);
else if(obj instanceof ItemStack)
inputsToSet.add(new MappableStackWrapper((ItemStack) obj));
else throw new IllegalArgumentException("Invalid input");
}
@@ -48,19 +43,35 @@ public class RecipePetals {
ItemStack stack = inv.getStackInSlot(i);
if(stack == null)
break;
String oredict = OreDictionary.getOreName(OreDictionary.getOreID(stack));
if(!inputsMissing.contains(stack) && !inputsMissing.contains(oredict))
return false;
if(inputsMissing.contains(stack))
inputsMissing.remove(stack);
else inputsMissing.remove(oredict);
int stackIndex = -1, oredictIndex = -1;
for(int j = 0; j < inputsMissing.size(); j++) {
Object input = inputsMissing.get(j);
if(input instanceof String && input.equals(oredict)) {
oredictIndex = j;
break;
} else if(input instanceof ItemStack && simpleAreStacksEqual((ItemStack) input, stack)) {
stackIndex = j;
break;
}
}
if(stackIndex != -1)
inputsMissing.remove(stackIndex);
else if(oredictIndex != -1)
inputsMissing.remove(oredictIndex);
else return false;
}
return inputsMissing.isEmpty();
}
boolean simpleAreStacksEqual(ItemStack stack, ItemStack stack2) {
return stack.itemID == stack2.itemID && stack.getItemDamage() == stack2.getItemDamage();
}
public List<Object> getInputs() {
return new ArrayList(inputs);
@@ -128,16 +128,17 @@ public class TileRuneAltar extends TileSimpleInventory implements ISidedInventor
public void onWanded(EntityPlayer player, ItemStack wand) {
updateRecipe();
RecipeRuneAltar recipe = null;
for(RecipeRuneAltar recipe_ : BotaniaAPI.runeAltarRecipes) {
if(recipe_.matches(this)) {
recipe = recipe_;
break;
}
}
if(manaToGet > 0 && mana >= manaToGet) {
RecipeRuneAltar recipe = null;
for(RecipeRuneAltar recipe_ : BotaniaAPI.runeAltarRecipes)
if(recipe_.matches(this)) {
recipe = recipe_;
break;
}
List<EntityItem> items = worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1));
EntityItem livingrock = null;
for(EntityItem item : items)
@@ -25,7 +25,6 @@ public class BiomeDecorationHandler {
public void onWorldDecoration(DecorateBiomeEvent.Decorate event) {
if((event.getResult() == Result.ALLOW || event.getResult() == Result.DEFAULT) && event.type == EventType.FLOWERS)
for(int i = 0; i < 3; i++) {
int x = event.chunkX + event.world.rand.nextInt(16) + 8;
int y = event.world.rand.nextInt(128);
int z = event.chunkZ + event.world.rand.nextInt(16) + 8;
@@ -52,14 +52,6 @@ public class ItemTwigWand extends Item16Colors {
return false;
}
@Override
public boolean shouldPassSneakingClickToBlock(World par2World, int par4, int par5, int par6) {
int id = par2World.getBlockId(par4, par5, par6);
if(Block.blocksList[id] instanceof IWandable)
return false;
return true;
}
@Override
public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) {
if(par3Entity instanceof EntityPlayer && ((EntityPlayer) par3Entity).getCurrentEquippedItem() == par1ItemStack)
@@ -24,7 +24,6 @@ import net.minecraftforge.oredict.OreDictionary;
import org.lwjgl.opengl.GL11;
import vazkii.botania.api.internal.IGuiLexiconEntry;
import vazkii.botania.api.internal.MappableStackWrapper;
import vazkii.botania.api.recipe.RecipePetals;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.common.block.ModBlocks;
@@ -63,8 +62,6 @@ public class PagePetalRecipe<T extends RecipePetals> extends PageRecipe {
Object input = obj;
if(input instanceof String)
input = OreDictionary.getOres((String) input).get(0);
if(input instanceof MappableStackWrapper)
input = ((MappableStackWrapper) input).getStack();
renderItemAtAngle(gui, currentDegree, (ItemStack) input);