First armor modifier

This commit is contained in:
mDiyo committed 2013-12-12 21:05:26 -08:00
1 parent 8b154a9cb4
commit 90f09b7e2d
12 files changed
+299 -19

No files matched your search

@@ -0,0 +1,87 @@
package tconstruct.modifiers.armor;
import java.util.EnumSet;
import java.util.UUID;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import tconstruct.library.armor.ArmorCore;
import tconstruct.library.armor.EnumArmorPart;
public class AModMoveSpeed extends ArmorModTypeFilter
{
final boolean modifierType;
public AModMoveSpeed(int effect, EnumSet<EnumArmorPart> armorTypes, ItemStack[] items, int[] values, boolean type)
{
super(effect, "ExoSpeed" + (type ? "Percent" : "Flat"), armorTypes, items, values);
this.modifierType = type;
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
NBTTagCompound tags = tool.getTagCompound().getCompoundTag(getTagName());
int amount = matchingAmount(input);
return tags.getInteger("Modifiers") >= amount;
}
@Override
public void modify (ItemStack[] input, ItemStack armor)
{
NBTTagCompound baseTag = armor.getTagCompound();
NBTTagCompound armorTag = armor.getTagCompound().getCompoundTag(getTagName());
int amount = matchingAmount(input);
int modifiers = armorTag.getInteger("Modifiers");
modifiers -= amount;
armorTag.setInteger("Modifiers", modifiers);
if (armorTag.hasKey(key))
{
amount += armorTag.getInteger(key);
}
armorTag.setInteger(key, amount);
NBTTagList attributes;
if (baseTag.hasKey("AttributeModifiers"))
{
attributes = baseTag.getTagList("AttributeModifiers");
for (int iter = 0; iter < attributes.tagCount(); iter++)
{
NBTTagCompound tag = (NBTTagCompound) attributes.tagAt(iter);
if (tag.getString("AttributeName").equals(key))
attributes.removeTag(iter);
}
}
else
{
attributes = new NBTTagList();
baseTag.setTag("AttributeModifiers", attributes);
}
attributes.appendTag(getAttributeTag("generic.movementSpeed", key, amount / 100d, modifierType, getUUIDFromItem(armor)));
}
private static final UUID head = UUID.fromString("2ba6c8ae-4a19-49c6-aab4-ca3a5eb7c730");
private static final UUID chest = UUID.fromString("2ba6c8ae-4a19-49c6-aab4-ca3a5eb7c731");
private static final UUID pants = UUID.fromString("2ba6c8ae-4a19-49c6-aab4-ca3a5eb7c732");
private static final UUID shoes = UUID.fromString("2ba6c8ae-4a19-49c6-aab4-ca3a5eb7c733");
UUID getUUIDFromItem (ItemStack stack)
{
ArmorCore item = (ArmorCore) stack.getItem();
switch (item.armorPart)
{
case HELMET:
return head;
case CHEST:
return chest;
case PANTS:
return pants;
case SHOES:
return shoes;
}
return null;
}
}
@@ -0,0 +1,108 @@
package tconstruct.modifiers.armor;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.item.ItemStack;
import tconstruct.library.armor.ArmorMod;
import tconstruct.library.armor.EnumArmorPart;
public abstract class ArmorModTypeFilter extends ArmorMod
{
public final List<Integer> increase;
public ArmorModTypeFilter(int effect, String dataKey, EnumSet<EnumArmorPart> armorTypes, ItemStack[] items, int[] values)
{
super(effect, dataKey, armorTypes, items);
assert items.length == values.length : "Itemstacks and their values for armor 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;
if (stack.getItemDamage() == Short.MAX_VALUE)
{
if (this.areItemsEquivalent(inputStack, stack))
match = true;
}
else
{
if (this.areItemStacksEquivalent(inputStack, stack))
match = true;
}
}
if (!match)
return false;
minimumMatch = true;
}
return minimumMatch;
}
public int matchingAmount (ItemStack[] input)
{
int amount = 0;
for (ItemStack inputStack : input)
{
if (inputStack == null)
continue;
else
{
for (int iter = 0; iter < stacks.size(); iter++)
{
ItemStack stack = (ItemStack) stacks.get(iter);
if (stack.getItemDamage() == Short.MAX_VALUE)
{
if (this.areItemsEquivalent(inputStack, stack))
amount += increase.get(iter);
}
else
{
if (this.areItemStacksEquivalent(inputStack, stack))
amount += increase.get(iter);
}
}
}
}
return amount;
}
/** Adds a new itemstack to the list for increases
*
* @param stack ItemStack to compare against
* @param amount 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);
}
}
@@ -6,7 +6,7 @@ import java.util.List;
import net.minecraft.item.ItemStack;
import tconstruct.library.tools.ToolMod;
public abstract class ToolModTypeFilter extends ToolMod//boobs.java
public abstract class ToolModTypeFilter extends ToolMod
{
public final List<Integer> increase;