Rewrote ModAttack to accept multiple items

This commit is contained in:
mDiyo committed 2013-12-12 03:08:05 -08:00
1 parent 977287e440
commit 086cc97ddc
12 files changed
+152 -50

No files matched your search

@@ -3,25 +3,21 @@ package tconstruct.modifiers.tools;
import java.util.Arrays;
import java.util.List;
import tconstruct.library.tools.ToolCore;
import tconstruct.library.tools.ToolMod;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.tools.ToolCore;
public class ModAttack extends ToolMod
public class ModAttack extends ToolModTypeFilter
{
String tooltipName;
int increase;
int max = 72;
String guiType;
public ModAttack(String type, ItemStack[] items, int effect, int inc)
public ModAttack(String type, int effect, ItemStack[] items, int[] value)
{
super(items, effect, "ModAttack");
super(effect, "ModAttack", items, value);
tooltipName = "\u00a7fSharpness";
guiType = type;
increase = inc;
}
@Override
@@ -36,14 +32,13 @@ public class ModAttack extends ToolMod
return tags.getInteger("Modifiers") > 0;
int keyPair[] = tags.getIntArray(key);
if (keyPair[0] + increase <= keyPair[1])
if (keyPair[0] + matchingAmount(input) <= keyPair[1])
return true;
else if (keyPair[0] == keyPair[1])
return tags.getInteger("Modifiers") > 0;
else
return false;
return false;
}
@Override
@@ -58,6 +53,7 @@ public class ModAttack extends ToolMod
amount = 36;
int[] keyPair = tags.getIntArray(key);
int increase = matchingAmount(input);
int leftToBoost = amount - (keyPair[0] % amount);
if (increase >= leftToBoost)
@@ -90,6 +86,7 @@ public class ModAttack extends ToolMod
int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
int increase = matchingAmount(input);
String modName = "\u00a7f" + guiType + " (" + increase + "/" + max + ")";
int tooltipIndex = addToolTip(tool, tooltipName, modName);
int[] keyPair = new int[] { increase, max, tooltipIndex };
@@ -112,8 +109,6 @@ public class ModAttack extends ToolMod
public boolean validType (ToolCore tool)
{
return true;
/*List list = Arrays.asList(tool.toolCategories());
return list.contains("melee") || list.contains("harvest") || list.contains("ammo");*/
}
public boolean nerfType (ToolCore tool)
@@ -55,7 +55,7 @@ public class TActiveOmniMod extends ActiveToolMod
{
if (entity instanceof EntityPlayer && ((EntityPlayer) entity).capabilities.isCreativeMode)
return false;
TRepo.modL.midStreamModify(stack, tool);
TRepo.modLapis.midStreamModify(stack, tool);
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
World world = entity.worldObj;
@@ -151,7 +151,7 @@ public class TActiveOmniMod extends ActiveToolMod
@Override
public int baseAttackDamage (int earlyModDamage, int damage, ToolCore tool, NBTTagCompound tags, NBTTagCompound toolTags, ItemStack stack, EntityLivingBase player, Entity entity)
{
TRepo.modL.midStreamModify(stack, tool);
TRepo.modLapis.midStreamModify(stack, tool);
return 0;
}
@@ -0,0 +1,103 @@
package tconstruct.modifiers.tools;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import tconstruct.library.tools.ToolMod;
public abstract class ToolModTypeFilter extends ToolMod//boobs.java
{
public final List<Integer> increase;
public ToolModTypeFilter(int effect, String dataKey, ItemStack[] items, int[] values)
{
super(items, effect, dataKey);
assert items.length == values.length : "Itemstacks and their values for tool modifiers must be the same length";
this.increase = new ArrayList<Integer>();
for (int i = 0; i < values.length; i++)
{
increase.add(values[i]);
}
}
/** Checks to see if the inputs match the stored items
* Note: Filters types, doesn't care about amount
*
* @param input The ItemStacks to compare against
* @param tool Item to modify, used for restrictions
* @return Whether the recipe matches the input
*/
@Override
public boolean matches (ItemStack[] input, ItemStack tool)
{
if (!canModify(tool, input))
return false;
boolean minimumMatch = false;
for (ItemStack inputStack : input)
{
if (inputStack == null)
continue;
boolean match = false;
for (Object check : stacks)
{
ItemStack stack = (ItemStack) check;
System.out.println("First stack: "+stack);
System.out.println("Second stack: "+inputStack);
if (stack.getItemDamage() == Short.MAX_VALUE)
{
if (inputStack.isItemEqual(stack))
match = true;
}
else
{
if (this.areItemStacksEquivalent(inputStack, stack))
match = true;
}
}
if (!match)
{
System.out.println("Not a match");
return false;
}
minimumMatch = true;
}
System.out.println("Object: " + minimumMatch);
return minimumMatch;
}
public int matchingAmount (ItemStack[] input)
{
int amount = 0;
for (ItemStack i : input)
{
if (i == null)
continue;
else
{
for (int iter = 0; iter < stacks.size(); iter++)
{
ItemStack check = (ItemStack) stacks.get(iter);
if (ItemStack.areItemStacksEqual(i, check))
amount += increase.get(iter);
}
}
}
return amount;
}
/** Adds a new itemstack to the list of increases
*
* @param stack ItemStack to compare against
* @param increase Amount to increase
*/
public void addStackToMatchList (ItemStack stack, int amount)
{
if (stack == null)
throw new NullPointerException("ItemStack added to " + this.getClass().getSimpleName() + " cannot be null.");
stacks.add(stack);
increase.add(amount);
}
}