Fix JABBA-related issues with crafting station slots (#54)

* Fix shift-merging tools voiding items

fixes <https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/11392>

* Change 0-sized ItemStacks into null stacks in crafting station attached slots

Fixes <https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/10425>

* Update buildscript

* spotlessApply
This commit is contained in:
Raven Szewczyk authored and GitHub committed 2022-09-22 20:51:23 +02:00
1 parent 18bfeaff32
commit 39be06c23b
571 files changed
+25959 -28223

No files matched your search

@@ -4,84 +4,60 @@ import java.util.*;
import net.minecraft.item.ItemStack;
import tconstruct.library.modifier.ItemModifier;
public abstract class ItemModTypeFilter extends ItemModifier
{
public abstract class ItemModTypeFilter extends ItemModifier {
public final List<Integer> increase;
public ItemModTypeFilter(int effect, String dataKey, ItemStack[] items, int[] values)
{
public ItemModTypeFilter(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++)
{
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;
public boolean matches(ItemStack[] input, ItemStack tool) {
if (!canModify(tool, input)) return false;
boolean minimumMatch = false;
for (ItemStack inputStack : input)
{
if (inputStack == null)
continue;
for (ItemStack inputStack : input) {
if (inputStack == null) continue;
boolean match = false;
for (Object check : stacks)
{
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 (stack.getItemDamage() == Short.MAX_VALUE) {
if (this.areItemsEquivalent(inputStack, stack)) match = true;
} else {
if (this.areItemStacksEquivalent(inputStack, stack)) match = true;
}
}
if (!match)
return false;
if (!match) return false;
minimumMatch = true;
}
return minimumMatch;
}
public int matchingAmount (ItemStack[] input)
{
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++)
{
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);
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);
}
}
}
@@ -90,14 +66,14 @@ public abstract class ItemModTypeFilter extends ItemModifier
}
/** 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)
{
public void addStackToMatchList(ItemStack stack, int amount) {
if (stack == null)
throw new NullPointerException("ItemStack added to " + this.getClass().getSimpleName() + " cannot be null.");
throw new NullPointerException(
"ItemStack added to " + this.getClass().getSimpleName() + " cannot be null.");
stacks.add(stack);
increase.add(amount);
}
@@ -1,42 +1,35 @@
package tconstruct.modifiers.tools;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.crafting.PatternBuilder;
import tconstruct.library.modifier.IModifyable;
import tconstruct.library.modifier.ItemModifier;
import tconstruct.library.tools.AbilityHelper;
import tconstruct.library.tools.ToolCore;
import tconstruct.library.weaponry.AmmoItem;
import tconstruct.library.weaponry.IAmmo;
import tconstruct.weaponry.weapons.Shuriken;
import java.util.HashSet;
import java.util.Set;
public class ModAmmoRestock extends ItemModifier {
public ModAmmoRestock()
{
public ModAmmoRestock() {
super(new ItemStack[0], 0, "");
}
@Override
public boolean matches (ItemStack[] input, ItemStack tool)
{
public boolean matches(ItemStack[] input, ItemStack tool) {
return canModify(tool, input);
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
if(!(tool.getItem() instanceof AmmoItem))
return false;
protected boolean canModify(ItemStack tool, ItemStack[] input) {
if (!(tool.getItem() instanceof AmmoItem)) return false;
IAmmo ammo = (IAmmo)tool.getItem();
IAmmo ammo = (IAmmo) tool.getItem();
// full?
if(ammo.getAmmoCount(tool) >= ammo.getMaxAmmo(tool))
return false;
if (ammo.getAmmoCount(tool) >= ammo.getMaxAmmo(tool)) return false;
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
// correct material?
@@ -44,17 +37,15 @@ public class ModAmmoRestock extends ItemModifier {
Set<Integer> materials = new HashSet<Integer>();
materials.add(tags.getInteger("Head"));
// shuriken allow all their components
if(tool.getItem() instanceof Shuriken) {
if (tool.getItem() instanceof Shuriken) {
materials.add(tags.getInteger("Handle"));
materials.add(tags.getInteger("Accessory"));
materials.add(tags.getInteger("Extra"));
}
boolean areInputsValid = true;
for (ItemStack curInput : input)
{
if (curInput != null && !materials.contains(PatternBuilder.instance.getPartID(curInput)))
{
for (ItemStack curInput : input) {
if (curInput != null && !materials.contains(PatternBuilder.instance.getPartID(curInput))) {
areInputsValid = false;
break;
}
@@ -63,43 +54,35 @@ public class ModAmmoRestock extends ItemModifier {
return areInputsValid;
}
private int calculateIncrease (ItemStack tool, int materialValue, int itemsUsed)
{
private int calculateIncrease(ItemStack tool, int materialValue, int itemsUsed) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
float dur = tags.getInteger("BaseDurability") * ((AmmoItem)tool.getItem()).getAmmoModifier();
float increase = (5 * itemsUsed + (dur * 0.4f * materialValue/2f));
float dur = tags.getInteger("BaseDurability") * ((AmmoItem) tool.getItem()).getAmmoModifier();
float increase = (5 * itemsUsed + (dur * 0.4f * materialValue / 2f));
int modifiers = tags.getInteger("Modifiers");
float mods = 1.0f;
if (modifiers == 2)
mods = 0.9f;
else if (modifiers == 1)
mods = 0.8f;
else if (modifiers == 0)
mods = 0.7f;
if (modifiers == 2) mods = 0.9f;
else if (modifiers == 1) mods = 0.8f;
else if (modifiers == 0) mods = 0.7f;
increase *= mods;
int repair = tags.getInteger("RepairCount");
float repairCount = (100 - repair) / 100f;
if (repairCount < 0.5f)
repairCount = 0.5f;
if (repairCount < 0.5f) repairCount = 0.5f;
increase *= repairCount;
increase /= ((ToolCore) tool.getItem()).getRepairCost();
return (int)increase;
return (int) increase;
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
public void modify(ItemStack[] input, ItemStack tool) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
int itemsUsed = 0;
int materialValue = 0;
for (ItemStack curInput : input)
{
if (curInput != null)
{
for (ItemStack curInput : input) {
if (curInput != null) {
materialValue += PatternBuilder.instance.getPartValue(curInput);
itemsUsed++;
}
@@ -110,16 +93,13 @@ public class ModAmmoRestock extends ItemModifier {
repair += itemsUsed;
tags.setInteger("RepairCount", repair);
((IAmmo)tool.getItem()).addAmmo(increase, tool);
((IAmmo) tool.getItem()).addAmmo(increase, tool);
}
@Override
public void addMatchingEffect (ItemStack tool)
{
}
public void addMatchingEffect(ItemStack tool) {}
public boolean validType (IModifyable input)
{
public boolean validType(IModifyable input) {
return input.getModifyType().equals("Tool") || input.getModifyType().equals("Armor");
}
}
@@ -3,51 +3,38 @@ package tconstruct.modifiers.tools;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class ModAntiSpider extends ItemModTypeFilter
{
public class ModAntiSpider extends ItemModTypeFilter {
String tooltipName;
int max = 4;
String guiType;
public ModAntiSpider(String type, int effect, ItemStack[] items, int[] values)
{
public ModAntiSpider(String type, int effect, ItemStack[] items, int[] values) {
super(effect, "ModAntiSpider", items, values);
tooltipName = "\u00a72Bane of Arthropods";
guiType = type;
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
protected boolean canModify(ItemStack tool, ItemStack[] input) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
if (!tags.hasKey(key))
return tags.getInteger("Modifiers") > 0 && matchingAmount(input) <= max;
if (!tags.hasKey(key)) return tags.getInteger("Modifiers") > 0 && matchingAmount(input) <= max;
if (matchingAmount(input) > max)
return false;
if (matchingAmount(input) > max) return false;
int keyPair[] = tags.getIntArray(key);
if (keyPair[0] + matchingAmount(input) <= keyPair[1])
return true;
else if (keyPair[0] == keyPair[1])
return tags.getInteger("Modifiers") > 0;
else
return false;
if (keyPair[0] + matchingAmount(input) <= keyPair[1]) return true;
else if (keyPair[0] == keyPair[1]) return tags.getInteger("Modifiers") > 0;
else return false;
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
public void modify(ItemStack[] input, ItemStack tool) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
int increase = matchingAmount(input);
if (tags.hasKey(key))
{
if (tags.hasKey(key)) {
int[] keyPair = tags.getIntArray(key);
if (keyPair[0] % max == 0)
{
if (keyPair[0] % max == 0) {
keyPair[0] += increase;
keyPair[1] += max;
tags.setIntArray(key, keyPair);
@@ -55,29 +42,24 @@ public class ModAntiSpider extends ItemModTypeFilter
int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
}
else
{
} else {
keyPair[0] += increase;
tags.setIntArray(key, keyPair);
}
updateModTag(tool, keyPair);
}
else
{
} else {
int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
String modName = "\u00a72" + guiType + " (" + increase + "/" + max + ")";
int tooltipIndex = addToolTip(tool, tooltipName, modName);
int[] keyPair = new int[] { increase, max, tooltipIndex };
int[] keyPair = new int[] {increase, max, tooltipIndex};
tags.setIntArray(key, keyPair);
}
}
void updateModTag (ItemStack tool, int[] keys)
{
void updateModTag(ItemStack tool, int[] keys) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
String tip = "ModifierTip" + keys[2];
String modName = "\u00a72" + guiType + " (" + keys[0] + "/" + keys[1] + ")";
@@ -1,14 +1,12 @@
package tconstruct.modifiers.tools;
import java.util.Arrays;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.modifier.IModifyable;
import tconstruct.library.tools.ToolCore;
import java.util.Arrays;
public class ModAttack extends ItemModTypeFilter
{
public class ModAttack extends ItemModTypeFilter {
String tooltipName;
int max;
int threshold;
@@ -17,8 +15,7 @@ public class ModAttack extends ItemModTypeFilter
boolean ammoOnly;
// Regular weapons
public ModAttack(String type, int effect, ItemStack[] items, int[] value)
{
public ModAttack(String type, int effect, ItemStack[] items, int[] value) {
super(effect, "ModAttack", items, value);
tooltipName = "\u00a7fSharpness";
guiType = type;
@@ -29,8 +26,7 @@ public class ModAttack extends ItemModTypeFilter
}
// projectiles
public ModAttack(String type, int effect, ItemStack[] items, int[] value, boolean ammoOnly)
{
public ModAttack(String type, int effect, ItemStack[] items, int[] value, boolean ammoOnly) {
super(effect, "ModAttack", items, value);
tooltipName = "\u00a7fSharpness";
guiType = type;
@@ -41,8 +37,8 @@ public class ModAttack extends ItemModTypeFilter
}
// gloves
public ModAttack(String type, int effect, ItemStack[] items, int[] value, int max, int threshold, String modifierType)
{
public ModAttack(
String type, int effect, ItemStack[] items, int[] value, int max, int threshold, String modifierType) {
super(effect, "ModAttack", items, value);
tooltipName = "\u00a7fKnuckles";
guiType = type;
@@ -53,64 +49,49 @@ public class ModAttack extends ItemModTypeFilter
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
if(tool.getItem() instanceof ToolCore)
{
if(Arrays.asList(((ToolCore) tool.getItem()).getTraits()).contains("ammo") != ammoOnly)
return false;
protected boolean canModify(ItemStack tool, ItemStack[] input) {
if (tool.getItem() instanceof ToolCore) {
if (Arrays.asList(((ToolCore) tool.getItem()).getTraits()).contains("ammo") != ammoOnly) return false;
}
if (tool.getItem() instanceof IModifyable)
{
if (tool.getItem() instanceof IModifyable) {
IModifyable toolItem = (IModifyable) tool.getItem();
if (!validType(toolItem))
return false;
if (!validType(toolItem)) return false;
if (matchingAmount(input) > max)
return false;
if (matchingAmount(input) > max) return false;
NBTTagCompound tags = tool.getTagCompound().getCompoundTag(toolItem.getBaseTagName());
if (!tags.hasKey(key))
return tags.getInteger("Modifiers") > 0 && matchingAmount(input) <= max;
if (!tags.hasKey(key)) return tags.getInteger("Modifiers") > 0 && matchingAmount(input) <= max;
int keyPair[] = tags.getIntArray(key);
if (keyPair[0] + matchingAmount(input) <= keyPair[1])
return true;
else if (keyPair[0] == keyPair[1])
return tags.getInteger("Modifiers") > 0;
if (keyPair[0] + matchingAmount(input) <= keyPair[1]) return true;
else if (keyPair[0] == keyPair[1]) return tags.getInteger("Modifiers") > 0;
}
return false;
}
@Override
public boolean validType (IModifyable input)
{
public boolean validType(IModifyable input) {
String type = input.getModifyType();
return type.equals(modifierType);
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
public void modify(ItemStack[] input, ItemStack tool) {
IModifyable toolItem = (IModifyable) tool.getItem();
NBTTagCompound tags = tool.getTagCompound().getCompoundTag(toolItem.getBaseTagName());
if (tags.hasKey(key))
{
if (tags.hasKey(key)) {
int[] keyPair = tags.getIntArray(key);
int increase = matchingAmount(input);
int leftToBoost = threshold - (keyPair[0] % threshold);
if (increase >= leftToBoost)
{
if (increase >= leftToBoost) {
int attack = tags.getInteger("Attack");
attack += 1;
tags.setInteger("Attack", attack);
}
if (keyPair[0] % max == 0)
{
if (keyPair[0] % max == 0) {
keyPair[0] += increase;
keyPair[1] += max;
tags.setIntArray(key, keyPair);
@@ -118,24 +99,20 @@ public class ModAttack extends ItemModTypeFilter
int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
}
else
{
} else {
keyPair[0] += increase;
tags.setIntArray(key, keyPair);
}
updateModTag(tool, keyPair);
}
else
{
} else {
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 };
int[] keyPair = new int[] {increase, max, tooltipIndex};
tags.setIntArray(key, keyPair);
int attack = tags.getInteger("Attack");
@@ -144,8 +121,7 @@ public class ModAttack extends ItemModTypeFilter
}
}
void updateModTag (ItemStack tool, int[] keys)
{
void updateModTag(ItemStack tool, int[] keys) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag(getTagName(tool));
String tip = "ModifierTip" + keys[2];
String modName = "\u00a7f" + guiType + " (" + keys[0] + "/" + keys[1] + ")";
@@ -3,21 +3,17 @@ package tconstruct.modifiers.tools;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class ModAutoSmelt extends ModBoolean
{
public class ModAutoSmelt extends ModBoolean {
public ModAutoSmelt(ItemStack[] items, int effect, String tag, String c, String tip)
{
public ModAutoSmelt(ItemStack[] items, int effect, String tag, String c, String tip) {
super(items, effect, tag, c, tip);
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
protected boolean canModify(ItemStack tool, ItemStack[] input) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
if (tags.getBoolean("Silk Touch"))
return false;
return tags.getInteger("Modifiers") > 0 && !tags.getBoolean(key); //Will fail if the modifier is false or the tag doesn't exist
if (tags.getBoolean("Silk Touch")) return false;
return tags.getInteger("Modifiers") > 0
&& !tags.getBoolean(key); // Will fail if the modifier is false or the tag doesn't exist
}
}
@@ -5,55 +5,41 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.tools.ToolCore;
public class ModBlaze extends ItemModTypeFilter
{
public class ModBlaze extends ItemModTypeFilter {
String tooltipName;
int max;
public ModBlaze(int effect, ItemStack[] items, int[] values)
{
public ModBlaze(int effect, ItemStack[] items, int[] values) {
super(effect, "Blaze", items, values);
tooltipName = "\u00a76Fiery";
max = 25;
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
if (tool.getItem() instanceof ToolCore)
{
protected boolean canModify(ItemStack tool, ItemStack[] input) {
if (tool.getItem() instanceof ToolCore) {
ToolCore toolItem = (ToolCore) tool.getItem();
if (!validType(toolItem))
return false;
if (!validType(toolItem)) return false;
if (matchingAmount(input) > max)
return false;
if (matchingAmount(input) > max) return false;
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
if (!tags.hasKey(key))
return tags.getInteger("Modifiers") > 0 && matchingAmount(input) <= max;
if (!tags.hasKey(key)) return tags.getInteger("Modifiers") > 0 && matchingAmount(input) <= max;
int keyPair[] = tags.getIntArray(key);
if (keyPair[0] + matchingAmount(input) <= keyPair[1])
return true;
else if (keyPair[0] == keyPair[1])
return tags.getInteger("Modifiers") > 0;
if (keyPair[0] + matchingAmount(input) <= keyPair[1]) return true;
else if (keyPair[0] == keyPair[1]) return tags.getInteger("Modifiers") > 0;
}
return false;
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
public void modify(ItemStack[] input, ItemStack tool) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
int increase = matchingAmount(input);
if (tags.hasKey(key))
{
if (tags.hasKey(key)) {
int[] keyPair = tags.getIntArray(key);
if (keyPair[0] % max == 0)
{
if (keyPair[0] % max == 0) {
keyPair[0] += increase;
keyPair[1] += max;
tags.setIntArray(key, keyPair);
@@ -61,41 +47,34 @@ public class ModBlaze extends ItemModTypeFilter
int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
}
else
{
} else {
keyPair[0] += increase;
tags.setIntArray(key, keyPair);
}
updateModTag(tool, keyPair);
}
else
{
} else {
int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
String modName = "\u00a76Blaze (" + increase + "/" + max + ")";
int tooltipIndex = addToolTip(tool, tooltipName, modName);
int[] keyPair = new int[] { increase, max, tooltipIndex };
int[] keyPair = new int[] {increase, max, tooltipIndex};
tags.setIntArray(key, keyPair);
}
int fiery = tags.getInteger("Fiery");
fiery += (increase);
tags.setInteger("Fiery", fiery);
}
void updateModTag (ItemStack tool, int[] keys)
{
void updateModTag(ItemStack tool, int[] keys) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
String tip = "ModifierTip" + keys[2];
String modName = "\u00a76Blaze (" + keys[0] + "/" + keys[1] + ")";
tags.setString(tip, modName);
}
public boolean validType (ToolCore tool)
{
public boolean validType(ToolCore tool) {
List list = Arrays.asList(tool.getTraits());
return list.contains("melee") || list.contains("ammo");
}
@@ -6,28 +6,25 @@ import tconstruct.library.modifier.ItemModifier;
/* Adds a boolean NBTTag */
public class ModBoolean extends ItemModifier
{
public class ModBoolean extends ItemModifier {
String color;
String tooltipName;
public ModBoolean(ItemStack[] items, int effect, String tag, String c, String tip)
{
public ModBoolean(ItemStack[] items, int effect, String tag, String c, String tip) {
super(items, effect, tag);
color = c;
tooltipName = tip;
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
protected boolean canModify(ItemStack tool, ItemStack[] input) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
return tags.getInteger("Modifiers") > 0 && !tags.getBoolean(key); //Will fail if the modifier is false or the tag doesn't exist
return tags.getInteger("Modifiers") > 0
&& !tags.getBoolean(key); // Will fail if the modifier is false or the tag doesn't exist
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
public void modify(ItemStack[] input, ItemStack tool) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
tags.setBoolean(key, true);
@@ -6,26 +6,20 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.*;
import tconstruct.library.tools.ToolCore;
public class ModButtertouch extends ModBoolean
{
public class ModButtertouch extends ModBoolean {
public ModButtertouch(ItemStack[] items, int effect)
{
public ModButtertouch(ItemStack[] items, int effect) {
super(items, effect, "Silk Touch", "\u00a7e", "Silky");
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
if (tool.getItem() instanceof ToolCore)
{
protected boolean canModify(ItemStack tool, ItemStack[] input) {
if (tool.getItem() instanceof ToolCore) {
ToolCore toolItem = (ToolCore) tool.getItem();
if (!validType(toolItem))
return false;
if (!validType(toolItem)) return false;
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
if (!tags.getBoolean("Lava") && !tags.hasKey("Lapis"))
{
if (!tags.getBoolean("Lava") && !tags.hasKey("Lapis")) {
return tags.getInteger("Modifiers") > 0 && !tags.getBoolean(key);
}
}
@@ -33,8 +27,7 @@ public class ModButtertouch extends ModBoolean
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
public void modify(ItemStack[] input, ItemStack tool) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
tags.setBoolean(key, true);
addEnchantment(tool, Enchantment.silkTouch, 1);
@@ -45,57 +38,48 @@ public class ModButtertouch extends ModBoolean
int attack = tags.getInteger("Attack");
attack -= 3;
if (attack < 0)
attack = 0;
if (attack < 0) attack = 0;
tags.setInteger("Attack", attack);
int miningSpeed = tags.getInteger("MiningSpeed");
miningSpeed -= 300;
if (miningSpeed < 0)
miningSpeed = 0;
if (miningSpeed < 0) miningSpeed = 0;
tags.setInteger("MiningSpeed", miningSpeed);
if (tags.hasKey("MiningSpeed2"))
{
if (tags.hasKey("MiningSpeed2")) {
int miningSpeed2 = tags.getInteger("MiningSpeed2");
miningSpeed2 -= 300;
if (miningSpeed2 < 0)
miningSpeed2 = 0;
if (miningSpeed2 < 0) miningSpeed2 = 0;
tags.setInteger("MiningSpeed2", miningSpeed2);
}
addToolTip(tool, color + tooltipName, color + key);
}
public void addEnchantment (ItemStack tool, Enchantment enchant, int level) //TODO: Move this to ItemModifier
{
public void addEnchantment(ItemStack tool, Enchantment enchant, int level) // TODO: Move this to ItemModifier
{
NBTTagList tags = new NBTTagList();
Map enchantMap = EnchantmentHelper.getEnchantments(tool);
Iterator iterator = enchantMap.keySet().iterator();
int index;
int lvl;
boolean hasEnchant = false;
while (iterator.hasNext())
{
while (iterator.hasNext()) {
NBTTagCompound enchantTag = new NBTTagCompound();
index = ((Integer) iterator.next()).intValue();
lvl = (Integer) enchantMap.get(index);
if (index == enchant.effectId)
{
if (index == enchant.effectId) {
hasEnchant = true;
enchantTag.setShort("id", (short) index);
enchantTag.setShort("lvl", (short) ((byte) level));
tags.appendTag(enchantTag);
}
else
{
} else {
enchantTag.setShort("id", (short) index);
enchantTag.setShort("lvl", (short) ((byte) lvl));
tags.appendTag(enchantTag);
}
}
if (!hasEnchant)
{
if (!hasEnchant) {
NBTTagCompound enchantTag = new NBTTagCompound();
enchantTag.setShort("id", (short) enchant.effectId);
enchantTag.setShort("lvl", (short) ((byte) level));
@@ -104,8 +88,7 @@ public class ModButtertouch extends ModBoolean
tool.stackTagCompound.setTag("ench", tags);
}
public boolean validType (ToolCore tool)
{
public boolean validType(ToolCore tool) {
List list = Arrays.asList(tool.getTraits());
return list.contains("weapon") || list.contains("harvest");
}
@@ -5,26 +5,19 @@ import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.modifier.ItemModifier;
import tconstruct.library.tools.ToolCore;
public class ModCreativeToolModifier extends ItemModifier
{
public ModCreativeToolModifier(ItemStack[] items)
{
public class ModCreativeToolModifier extends ItemModifier {
public ModCreativeToolModifier(ItemStack[] items) {
super(items, 0, "");
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
if (tool.getItem() instanceof ToolCore)
{
protected boolean canModify(ItemStack tool, ItemStack[] input) {
if (tool.getItem() instanceof ToolCore) {
ToolCore toolItem = (ToolCore) tool.getItem();
for (ItemStack stack : input)
{
if (stack != null && stack.hasTagCompound())
{
for (ItemStack stack : input) {
if (stack != null && stack.hasTagCompound()) {
String targetLock = stack.getTagCompound().getString("TargetLock");
if (!targetLock.equals("") && !targetLock.equals(toolItem.getToolName()))
return false;
if (!targetLock.equals("") && !targetLock.equals(toolItem.getToolName())) return false;
}
}
return true;
@@ -33,15 +26,12 @@ public class ModCreativeToolModifier extends ItemModifier
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
public void modify(ItemStack[] input, ItemStack tool) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
int modifiers = tags.getInteger("Modifiers");
modifiers += 1;
tags.setInteger("Modifiers", modifiers);
}
public void addMatchingEffect (ItemStack tool)
{
}
public void addMatchingEffect(ItemStack tool) {}
}
@@ -7,16 +7,14 @@ import tconstruct.util.config.PHConstruct;
/* Adds an integer NBTTag */
public class ModDurability extends ItemModifier
{
public class ModDurability extends ItemModifier {
String tooltipName;
String color;
int durability;
float modifier;
int miningLevel;
public ModDurability(ItemStack[] items, int effect, int dur, float mod, int level, String k, String tip, String c)
{
public ModDurability(ItemStack[] items, int effect, int dur, float mod, int level, String k, String tip, String c) {
super(items, effect, k);
durability = dur;
modifier = mod;
@@ -26,17 +24,14 @@ public class ModDurability extends ItemModifier
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
protected boolean canModify(ItemStack tool, ItemStack[] input) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
if (tags.hasKey(key))
return false;
if (tags.hasKey(key)) return false;
return super.canModify(tool, input);
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
public void modify(ItemStack[] input, ItemStack tool) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
int base = tags.getInteger("BaseDurability");
@@ -47,18 +42,15 @@ public class ModDurability extends ItemModifier
modDur += modifier;
int total = (int) ((base + bonus) * (modDur + 1f));
if (total <= 0)
total = 1;
if (total <= 0) total = 1;
tags.setInteger("TotalDurability", total);
tags.setInteger("BonusDurability", bonus);
tags.setFloat("ModDurability", modDur);
if (PHConstruct.miningLevelIncrease)
{
if (PHConstruct.miningLevelIncrease) {
int mLevel = tags.getInteger("HarvestLevel");
if (mLevel < miningLevel)
tags.setInteger("HarvestLevel", miningLevel);
if (mLevel < miningLevel) tags.setInteger("HarvestLevel", miningLevel);
}
int modifiers = tags.getInteger("Modifiers");
@@ -69,5 +61,4 @@ public class ModDurability extends ItemModifier
String modTip = color + key;
addToolTip(tool, tooltipName, modTip);
}
}
@@ -4,21 +4,16 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.modifier.*;
public class ModExtraModifier extends ItemModifier
{
public ModExtraModifier(ItemStack[] items, String dataKey)
{
public class ModExtraModifier extends ItemModifier {
public ModExtraModifier(ItemStack[] items, String dataKey) {
super(items, 0, dataKey);
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] recipe)
{
if (tool != null && tool.getItem() instanceof IModifyable)
{
protected boolean canModify(ItemStack tool, ItemStack[] recipe) {
if (tool != null && tool.getItem() instanceof IModifyable) {
NBTTagCompound tags = this.getModifierTag(tool);
if (tags.getBoolean(key))
{
if (tags.getBoolean(key)) {
return false;
}
return true;
@@ -27,8 +22,7 @@ public class ModExtraModifier extends ItemModifier
}
@Override
public void modify (ItemStack[] recipe, ItemStack input)
{
public void modify(ItemStack[] recipe, ItemStack input) {
NBTTagCompound tags = this.getModifierTag(input);
tags.setBoolean(key, true);
int modifiers = tags.getInteger("Modifiers");
@@ -36,7 +30,5 @@ public class ModExtraModifier extends ItemModifier
tags.setInteger("Modifiers", modifiers);
}
public void addMatchingEffect (ItemStack tool)
{
}
public void addMatchingEffect(ItemStack tool) {}
}
@@ -2,9 +2,6 @@ package tconstruct.modifiers.tools;
import cofh.api.energy.IEnergyContainerItem;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.modifier.IModifyable;
@@ -13,81 +10,70 @@ import tconstruct.util.config.PHConstruct;
/* TE3 support */
public class ModFlux extends ModBoolean
{
public class ModFlux extends ModBoolean {
public ArrayList<ItemStack> batteries = new ArrayList<ItemStack>();
public int modifiersRequired = 1; // LALALALA totally not hidden IguanaTweaks Support LALALALA
public ModFlux()
{
public ModFlux() {
super(new ItemStack[0], 9, "Flux", "\u00a7e", "");
}
@Override
public boolean matches (ItemStack[] input, ItemStack tool)
{
public boolean matches(ItemStack[] input, ItemStack tool) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
// not on ammo weapons, since they don't have durability technically
String[] traits = ((IModifyable)tool.getItem()).getTraits();
for(String trait : traits)
if("ammo".equals(trait))
return false;
String[] traits = ((IModifyable) tool.getItem()).getTraits();
for (String trait : traits) if ("ammo".equals(trait)) return false;
ItemStack foundBattery = null;
// try to find the battery in the input
for (ItemStack stack : input)
for (ItemStack battery : batteries)
{
if (stack == null)
continue;
if (stack.getItem() != battery.getItem())
continue;
if (!(stack.getItem() instanceof IEnergyContainerItem))
continue;
for (ItemStack battery : batteries) {
if (stack == null) continue;
if (stack.getItem() != battery.getItem()) continue;
if (!(stack.getItem() instanceof IEnergyContainerItem)) continue;
// we don't allow multiple batteries to be added
if (foundBattery != null)
return false;
if (foundBattery != null) return false;
// battery found, gogogo
foundBattery = stack;
}
// no battery present
if (foundBattery == null)
return false;
if (foundBattery == null) return false;
int maxEnergy = ((IEnergyContainerItem) foundBattery.getItem()).getMaxEnergyStored(foundBattery);
// battery too big for our tool?
if(PHConstruct.balancedFluxModifier && tags.getInteger("TotalDurability") < maxEnergy/1000) // durability needs to be at least 1/1000th of the charge
return false;
if (PHConstruct.balancedFluxModifier
&& tags.getInteger("TotalDurability")
< maxEnergy / 1000) // durability needs to be at least 1/1000th of the charge
return false;
// check if we already have a flux modifier
if (tags.getBoolean(key))
{
if (tags.getBoolean(key)) {
// only allow if it's an upgrade
// remark: we use the ToolCores function here instead of accessing the tag directly, to achieve backwards compatibility with tools without tags.
// remark: we use the ToolCores function here instead of accessing the tag directly, to achieve backwards
// compatibility with tools without tags.
int a = ((IEnergyContainerItem) foundBattery.getItem()).getMaxEnergyStored(foundBattery);
int b = ((ToolCore) tool.getItem()).getMaxEnergyStored(tool);
return ((IEnergyContainerItem) foundBattery.getItem()).getMaxEnergyStored(foundBattery) > ((ToolCore) tool.getItem()).getMaxEnergyStored(tool);
return ((IEnergyContainerItem) foundBattery.getItem()).getMaxEnergyStored(foundBattery)
> ((ToolCore) tool.getItem()).getMaxEnergyStored(tool);
}
// otherwise check if we have enough modfiers
else if (tags.getInteger("Modifiers") < modifiersRequired)
return false;
else if (tags.getInteger("Modifiers") < modifiersRequired) return false;
// all requirements satisfied!
return true;
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
public void modify(ItemStack[] input, ItemStack tool) {
NBTTagCompound tags = tool.getTagCompound();
// update modifiers (only applies if it's not an upgrade)
if (!tags.hasKey(key))
{
if (!tags.hasKey(key)) {
int modifiers = tags.getCompoundTag("InfiTool").getInteger("Modifiers");
modifiers -= modifiersRequired;
tags.getCompoundTag("InfiTool").setInteger("Modifiers", modifiers);
@@ -99,14 +85,10 @@ public class ModFlux extends ModBoolean
// find the battery in the input
ItemStack inputBattery = null;
for (ItemStack stack : input)
for (ItemStack battery : batteries)
{
if (stack == null)
continue;
if (stack.getItem() != battery.getItem())
continue;
if (!(stack.getItem() instanceof IEnergyContainerItem))
continue;
for (ItemStack battery : batteries) {
if (stack == null) continue;
if (stack.getItem() != battery.getItem()) continue;
if (!(stack.getItem() instanceof IEnergyContainerItem)) continue;
// we're guaranteed to only find one battery because more are prevented above
inputBattery = stack;
@@ -119,16 +101,14 @@ public class ModFlux extends ModBoolean
int charge = energyContainer.getEnergyStored(inputBattery);
// add already present charge in the tool
if (tags.hasKey("Energy"))
charge += tags.getInteger("Energy");
if (tags.hasKey("Energy")) charge += tags.getInteger("Energy");
int maxCharge = energyContainer.getMaxEnergyStored(inputBattery);
ItemStack subject42 = inputBattery.copy();
int progress = 0, change = 1; // prevent endless loops with creative battery, blah
// fill the battery full
while (progress < maxCharge && change > 0)
{
while (progress < maxCharge && change > 0) {
change = energyContainer.receiveEnergy(subject42, 100000, false);
progress += change;
}
@@ -140,8 +120,7 @@ public class ModFlux extends ModBoolean
// completely empty the battery
progress = 0;
change = 1;
while (progress < maxCharge && change > 0)
{
while (progress < maxCharge && change > 0) {
change = energyContainer.extractEnergy(subject42, 100000, false);
progress += change;
}
@@ -157,6 +136,7 @@ public class ModFlux extends ModBoolean
tags.setInteger(key, 1);
ToolCore toolcore = (ToolCore) tool.getItem();
//tool.setItemDamage(1 + (toolcore.getMaxEnergyStored(tool) - charge) * (tool.getMaxDamage() - 1) / toolcore.getMaxEnergyStored(tool));
// tool.setItemDamage(1 + (toolcore.getMaxEnergyStored(tool) - charge) * (tool.getMaxDamage() - 1) /
// toolcore.getMaxEnergyStored(tool));
}
}
@@ -6,23 +6,21 @@ import tconstruct.library.modifier.ItemModifier;
/* Adds an integer NBTTag */
public class ModInteger extends ItemModifier
{
public class ModInteger extends ItemModifier {
String color;
String tooltipName;
int initialIncrease;
int secondaryIncrease;
public ModInteger(ItemStack[] items, int effect, String dataKey, int increase, String c, String tip)
{
public ModInteger(ItemStack[] items, int effect, String dataKey, int increase, String c, String tip) {
super(items, effect, dataKey);
initialIncrease = secondaryIncrease = increase;
color = c;
tooltipName = tip;
}
public ModInteger(ItemStack[] items, int effect, String dataKey, int increase1, int increase2, String c, String tip)
{
public ModInteger(
ItemStack[] items, int effect, String dataKey, int increase1, int increase2, String c, String tip) {
super(items, effect, dataKey);
initialIncrease = increase1;
secondaryIncrease = increase2;
@@ -31,17 +29,13 @@ public class ModInteger extends ItemModifier
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
public void modify(ItemStack[] input, ItemStack tool) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
if (tags.hasKey(key))
{
if (tags.hasKey(key)) {
int increase = tags.getInteger(key);
increase += secondaryIncrease;
tags.setInteger(key, increase);
}
else
{
} else {
tags.setInteger(key, initialIncrease);
}
@@ -51,5 +45,4 @@ public class ModInteger extends ItemModifier
addToolTip(tool, color + tooltipName, color + key);
}
}
@@ -6,55 +6,44 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.*;
import tconstruct.library.tools.ToolCore;
public class ModLapis extends ItemModTypeFilter
{
public class ModLapis extends ItemModTypeFilter {
String tooltipName;
int max = 450;
public ModLapis(int effect, ItemStack[] items, int[] values)
{
public ModLapis(int effect, ItemStack[] items, int[] values) {
super(effect, "Lapis", items, values);
tooltipName = "\u00a79Luck";
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
if (tool.getItem() instanceof ToolCore)
{
protected boolean canModify(ItemStack tool, ItemStack[] input) {
if (tool.getItem() instanceof ToolCore) {
ToolCore toolItem = (ToolCore) tool.getItem();
if (!validType(toolItem))
return false;
if (!validType(toolItem)) return false;
if (matchingAmount(input) > max)
return false;
if (matchingAmount(input) > max) return false;
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
if (tags.getBoolean("Silk Touch"))
return false;
if (tags.getBoolean("Silk Touch")) return false;
if (!tags.hasKey(key))
return tags.getInteger("Modifiers") > 0 && matchingAmount(input) <= max;
if (!tags.hasKey(key)) return tags.getInteger("Modifiers") > 0 && matchingAmount(input) <= max;
int keyPair[] = tags.getIntArray(key);
if (keyPair[0] + matchingAmount(input) <= max)
return true;
if (keyPair[0] + matchingAmount(input) <= max) return true;
}
return false;
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
public void modify(ItemStack[] input, ItemStack tool) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
if (!tags.hasKey(key))
{
if (!tags.hasKey(key)) {
tags.setBoolean(key, true);
String modName = "\u00a79Lapis (0/450)";
int tooltipIndex = addToolTip(tool, "\u00a79Luck", modName);
int[] keyPair = new int[] { 0, tooltipIndex };
int[] keyPair = new int[] {0, tooltipIndex};
tags.setIntArray(key, keyPair);
int modifiers = tags.getInteger("Modifiers");
@@ -70,135 +59,92 @@ public class ModLapis extends ItemModTypeFilter
String[] types = toolcore.getTraits();
boolean weapon = false;
boolean harvest = false;
for (String s : types)
{
if (s.equals("harvest"))
harvest = true;
else if (s.equals("weapon"))
weapon = true;
for (String s : types) {
if (s.equals("harvest")) harvest = true;
else if (s.equals("weapon")) weapon = true;
}
if (weapon)
{
if (keyPair[0] >= 450)
addEnchantment(tool, Enchantment.looting, 3);
else if (keyPair[0] >= 300)
addEnchantment(tool, Enchantment.looting, 2);
else if (keyPair[0] >= 100)
addEnchantment(tool, Enchantment.looting, 1);
if (weapon) {
if (keyPair[0] >= 450) addEnchantment(tool, Enchantment.looting, 3);
else if (keyPair[0] >= 300) addEnchantment(tool, Enchantment.looting, 2);
else if (keyPair[0] >= 100) addEnchantment(tool, Enchantment.looting, 1);
}
if (harvest)
{
if (keyPair[0] >= 450)
addEnchantment(tool, Enchantment.fortune, 3);
else if (keyPair[0] >= 300)
addEnchantment(tool, Enchantment.fortune, 2);
else if (keyPair[0] >= 100)
addEnchantment(tool, Enchantment.fortune, 1);
if (harvest) {
if (keyPair[0] >= 450) addEnchantment(tool, Enchantment.fortune, 3);
else if (keyPair[0] >= 300) addEnchantment(tool, Enchantment.fortune, 2);
else if (keyPair[0] >= 100) addEnchantment(tool, Enchantment.fortune, 1);
}
updateModTag(tool, keyPair);
}
public void midStreamModify (ItemStack tool, ToolCore toolItem)
{
public void midStreamModify(ItemStack tool, ToolCore toolItem) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
if (!tags.hasKey(key))
return;
if (!tags.hasKey(key)) return;
int keyPair[] = tags.getIntArray(key);
if (keyPair[0] == max)
return;
if (keyPair[0] == max) return;
if (random.nextInt(50) == 0)
{
if (random.nextInt(50) == 0) {
keyPair[0] += 1;
tags.setIntArray(key, keyPair);
updateModTag(tool, keyPair);
}
List list = Arrays.asList(toolItem.getTraits());
if (list.contains("weapon"))
{
if (keyPair[0] >= 450)
{
if (list.contains("weapon")) {
if (keyPair[0] >= 450) {
addEnchantment(tool, Enchantment.looting, 3);
}
else if (keyPair[0] >= 350)
{
} else if (keyPair[0] >= 350) {
int chance = keyPair[0] - 300;
if (random.nextInt(1000 - chance) == 0)
addEnchantment(tool, Enchantment.looting, 3);
}
else if (keyPair[0] >= 125)
{
if (random.nextInt(1000 - chance) == 0) addEnchantment(tool, Enchantment.looting, 3);
} else if (keyPair[0] >= 125) {
int chance = keyPair[0] - 175;
if (random.nextInt(600 - chance) == 0)
addEnchantment(tool, Enchantment.looting, 2);
}
else if (keyPair[0] >= 10)
{
if (random.nextInt(600 - chance) == 0) addEnchantment(tool, Enchantment.looting, 2);
} else if (keyPair[0] >= 10) {
int chance = keyPair[0] - 25;
if (random.nextInt(250 - chance) == 0)
addEnchantment(tool, Enchantment.looting, 1);
if (random.nextInt(250 - chance) == 0) addEnchantment(tool, Enchantment.looting, 1);
}
}
if (list.contains("harvest"))
{
if (keyPair[0] >= 450)
{
if (list.contains("harvest")) {
if (keyPair[0] >= 450) {
addEnchantment(tool, Enchantment.fortune, 3);
}
else if (keyPair[0] >= 350)
{
} else if (keyPair[0] >= 350) {
int chance = keyPair[0] - 300;
if (random.nextInt(1000 - chance) == 0)
addEnchantment(tool, Enchantment.fortune, 3);
}
else if (keyPair[0] >= 125)
{
if (random.nextInt(1000 - chance) == 0) addEnchantment(tool, Enchantment.fortune, 3);
} else if (keyPair[0] >= 125) {
int chance = keyPair[0] - 175;
if (random.nextInt(600 - chance) == 0)
addEnchantment(tool, Enchantment.fortune, 2);
}
else if (keyPair[0] >= 10)
{
if (random.nextInt(600 - chance) == 0) addEnchantment(tool, Enchantment.fortune, 2);
} else if (keyPair[0] >= 10) {
int chance = keyPair[0] - 25;
if (random.nextInt(250 - chance) == 0)
addEnchantment(tool, Enchantment.fortune, 1);
if (random.nextInt(250 - chance) == 0) addEnchantment(tool, Enchantment.fortune, 1);
}
}
}
public void addEnchantment (ItemStack tool, Enchantment enchant, int level)
{
public void addEnchantment(ItemStack tool, Enchantment enchant, int level) {
NBTTagList tags = new NBTTagList();
Map enchantMap = EnchantmentHelper.getEnchantments(tool);
Iterator iterator = enchantMap.keySet().iterator();
int index;
int lvl;
boolean hasEnchant = false;
while (iterator.hasNext())
{
while (iterator.hasNext()) {
NBTTagCompound enchantTag = new NBTTagCompound();
index = ((Integer) iterator.next()).intValue();
lvl = (Integer) enchantMap.get(index);
if (index == enchant.effectId)
{
if (index == enchant.effectId) {
hasEnchant = true;
enchantTag.setShort("id", (short) index);
enchantTag.setShort("lvl", (short) ((byte) level));
tags.appendTag(enchantTag);
}
else
{
} else {
enchantTag.setShort("id", (short) index);
enchantTag.setShort("lvl", (short) ((byte) lvl));
tags.appendTag(enchantTag);
}
}
if (!hasEnchant)
{
if (!hasEnchant) {
NBTTagCompound enchantTag = new NBTTagCompound();
enchantTag.setShort("id", (short) enchant.effectId);
enchantTag.setShort("lvl", (short) ((byte) level));
@@ -207,16 +153,14 @@ public class ModLapis extends ItemModTypeFilter
tool.stackTagCompound.setTag("ench", tags);
}
void updateModTag (ItemStack tool, int[] keys)
{
void updateModTag(ItemStack tool, int[] keys) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
String tip = "ModifierTip" + keys[1];
String modName = "\u00a79Lapis (" + keys[0] + "/" + max + ")";
tags.setString(tip, modName);
}
public boolean validType (ToolCore tool)
{
public boolean validType(ToolCore tool) {
List list = Arrays.asList(tool.getTraits());
return !list.contains("ammo") && (list.contains("weapon") || list.contains("harvest"));
}
@@ -5,54 +5,40 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.tools.ToolCore;
public class ModPiston extends ItemModTypeFilter
{
public class ModPiston extends ItemModTypeFilter {
String tooltipName;
int max = 10;
public ModPiston(int effect, ItemStack[] items, int[] values)
{
public ModPiston(int effect, ItemStack[] items, int[] values) {
super(effect, "Piston", items, values);
tooltipName = "\u00a77Knockback";
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
if (tool.getItem() instanceof ToolCore)
{
protected boolean canModify(ItemStack tool, ItemStack[] input) {
if (tool.getItem() instanceof ToolCore) {
ToolCore toolItem = (ToolCore) tool.getItem();
if (!validType(toolItem))
return false;
if (!validType(toolItem)) return false;
if (matchingAmount(input) > max)
return false;
if (matchingAmount(input) > max) return false;
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
if (!tags.hasKey(key))
return tags.getInteger("Modifiers") > 0 && matchingAmount(input) <= max;
if (!tags.hasKey(key)) return tags.getInteger("Modifiers") > 0 && matchingAmount(input) <= max;
int keyPair[] = tags.getIntArray(key);
if (keyPair[0] + matchingAmount(input) <= keyPair[1])
return true;
else if (keyPair[0] == keyPair[1])
return tags.getInteger("Modifiers") > 0;
if (keyPair[0] + matchingAmount(input) <= keyPair[1]) return true;
else if (keyPair[0] == keyPair[1]) return tags.getInteger("Modifiers") > 0;
}
return false;
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
public void modify(ItemStack[] input, ItemStack tool) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
int increase = matchingAmount(input);
if (tags.hasKey(key))
{
if (tags.hasKey(key)) {
int[] keyPair = tags.getIntArray(key);
if (keyPair[0] % max == 0)
{
if (keyPair[0] % max == 0) {
keyPair[0] += increase;
keyPair[1] += max;
tags.setIntArray(key, keyPair);
@@ -60,22 +46,18 @@ public class ModPiston extends ItemModTypeFilter
int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
}
else
{
} else {
keyPair[0] += increase;
tags.setIntArray(key, keyPair);
}
updateModTag(tool, keyPair);
}
else
{
} else {
int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
String modName = "\u00a74Knockback (" + increase + "/" + max + ")";
int tooltipIndex = addToolTip(tool, tooltipName, modName);
int[] keyPair = new int[] { increase, max, tooltipIndex };
int[] keyPair = new int[] {increase, max, tooltipIndex};
tags.setIntArray(key, keyPair);
}
@@ -85,16 +67,14 @@ public class ModPiston extends ItemModTypeFilter
tags.setFloat("Knockback", knockback);
}
void updateModTag (ItemStack tool, int[] keys)
{
void updateModTag(ItemStack tool, int[] keys) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
String tip = "ModifierTip" + keys[2];
String modName = "\u00a77Knockback (" + keys[0] + "/" + keys[1] + ")";
tags.setString(tip, modName);
}
public boolean validType (ToolCore tool)
{
public boolean validType(ToolCore tool) {
List list = Arrays.asList(tool.getTraits());
return list.contains("weapon") || list.contains("ammo");
}
@@ -5,28 +5,20 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.modifier.ItemModifier;
public class ModPotion extends ItemModifier
{
public class ModPotion extends ItemModifier {
public ModPotion(ItemStack[] items, int effect, String dataKey)
{
super(new ItemStack[] { new ItemStack(Items.potionitem, 1, Short.MAX_VALUE) }, 0, "");
public ModPotion(ItemStack[] items, int effect, String dataKey) {
super(new ItemStack[] {new ItemStack(Items.potionitem, 1, Short.MAX_VALUE)}, 0, "");
}
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
protected boolean canModify(ItemStack tool, ItemStack[] input) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
NBTTagCompound potion = tool.getTagCompound().getCompoundTag("Potion");
if (potion == null)
return true;
if (potion == null) return true;
return false;
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
}
public void modify(ItemStack[] input, ItemStack tool) {}
}
@@ -6,56 +6,44 @@ import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.modifier.IModifyable;
import tconstruct.library.tools.ToolCore;
public class ModRedstone extends ItemModTypeFilter
{
public class ModRedstone extends ItemModTypeFilter {
public String tooltipName;
public int max = 50;
public ModRedstone(int effect, ItemStack[] items, int[] values)
{
public ModRedstone(int effect, ItemStack[] items, int[] values) {
super(effect, "Redstone", items, values);
tooltipName = "\u00a74Haste";
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
if (tool.getItem() instanceof ToolCore)
{
protected boolean canModify(ItemStack tool, ItemStack[] input) {
if (tool.getItem() instanceof ToolCore) {
ToolCore toolItem = (ToolCore) tool.getItem();
if (!validType(toolItem))
return false;
if (!validType(toolItem)) return false;
if (matchingAmount(input) > max)
return false;
if (matchingAmount(input) > max) return false;
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
if (!tags.hasKey(key))
return tags.getInteger("Modifiers") > 0 && matchingAmount(input) <= max;
if (!tags.hasKey(key)) return tags.getInteger("Modifiers") > 0 && matchingAmount(input) <= max;
int keyPair[] = tags.getIntArray(key);
if (keyPair[0] + matchingAmount(input) <= keyPair[1])
return true;
else if (keyPair[0] == keyPair[1])
return tags.getInteger("Modifiers") > 0;
if (keyPair[0] + matchingAmount(input) <= keyPair[1]) return true;
else if (keyPair[0] == keyPair[1]) return tags.getInteger("Modifiers") > 0;
}
return false;
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
public void modify(ItemStack[] input, ItemStack tool) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
int[] keyPair;
int increase = matchingAmount(input);
int current = 0;
if (tags.hasKey(key))
{
if (tags.hasKey(key)) {
keyPair = tags.getIntArray(key);
if (keyPair[0] % max == 0)
{
if (keyPair[0] % max == 0) {
keyPair[0] += increase;
keyPair[1] += max;
tags.setIntArray(key, keyPair);
@@ -63,23 +51,19 @@ public class ModRedstone extends ItemModTypeFilter
int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
}
else
{
} else {
keyPair[0] += increase;
tags.setIntArray(key, keyPair);
}
current = keyPair[0];
updateModTag(tool, keyPair);
}
else
{
} else {
int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
String modName = "\u00a74Redstone (" + increase + "/" + max + ")";
int tooltipIndex = addToolTip(tool, tooltipName, modName);
keyPair = new int[] { increase, max, tooltipIndex };
keyPair = new int[] {increase, max, tooltipIndex};
current = keyPair[0];
tags.setIntArray(key, keyPair);
}
@@ -87,25 +71,19 @@ public class ModRedstone extends ItemModTypeFilter
int miningSpeed = tags.getInteger("MiningSpeed");
int boost = 8 + ((current - 1) / 50 * 2);
Item temp = tool.getItem();
if (temp instanceof ToolCore)
{
if (temp instanceof ToolCore) {
ToolCore toolcore = (ToolCore) temp;
if (toolcore.durabilityTypeHandle() == 2)
boost += 2;
if (toolcore.durabilityTypeAccessory() == 2)
boost += 2;
if (toolcore.durabilityTypeExtra() == 2)
boost += 2;
if (toolcore.durabilityTypeHandle() == 2) boost += 2;
if (toolcore.durabilityTypeAccessory() == 2) boost += 2;
if (toolcore.durabilityTypeExtra() == 2) boost += 2;
}
miningSpeed += (increase * boost);
tags.setInteger("MiningSpeed", miningSpeed);
String[] type = { "MiningSpeed2", "MiningSpeedHandle", "MiningSpeedExtra" };
String[] type = {"MiningSpeed2", "MiningSpeedHandle", "MiningSpeedExtra"};
for (int i = 0; i < 3; i++)
{
if (tags.hasKey(type[i]))
{
for (int i = 0; i < 3; i++) {
if (tags.hasKey(type[i])) {
int speed = tags.getInteger(type[i]);
speed += (increase * boost);
tags.setInteger(type[i], speed);
@@ -113,26 +91,22 @@ public class ModRedstone extends ItemModTypeFilter
}
}
void updateModTag (ItemStack tool, int[] keys)
{
void updateModTag(ItemStack tool, int[] keys) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
String tip = "ModifierTip" + keys[2];
String modName = "\u00a74Redstone (" + keys[0] + "/" + keys[1] + ")";
tags.setString(tip, modName);
}
public boolean validType (IModifyable input)
{
public boolean validType(IModifyable input) {
return input.getModifyType().equals("Tool");
}
public boolean validType (ToolCore tool)
{
public boolean validType(ToolCore tool) {
List list = Arrays.asList(tool.getTraits());
// handled by the windup modifier
if(list.contains("windup"))
return false;
if (list.contains("windup")) return false;
return list.contains("harvest") || list.contains("utility");
}
}
@@ -3,26 +3,20 @@ package tconstruct.modifiers.tools;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class ModReinforced extends ModInteger
{
public class ModReinforced extends ModInteger {
public ModReinforced(ItemStack[] items, int effect, int increase)
{
public ModReinforced(ItemStack[] items, int effect, int increase) {
super(items, effect, "Reinforced", 1, "\u00a75", "Reinforced");
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
public void modify(ItemStack[] input, ItemStack tool) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
if (tags.hasKey(key))
{
if (tags.hasKey(key)) {
int increase = tags.getInteger(key);
increase += secondaryIncrease;
tags.setInteger(key, increase);
}
else
{
} else {
tags.setInteger(key, initialIncrease);
}
@@ -37,28 +31,22 @@ public class ModReinforced extends ModInteger
addToolTip(tool, color + tooltipName, color + key);
}
protected int addToolTip (ItemStack tool, String tooltip, String modifierTip)
{
protected int addToolTip(ItemStack tool, String tooltip, String modifierTip) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
int tipNum = 0;
while (true)
{
while (true) {
tipNum++;
String tip = "Tooltip" + tipNum;
if (!tags.hasKey(tip))
{
if (!tags.hasKey(tip)) {
tags.setString(tip, "");
String modTip = "ModifierTip" + tipNum;
String tag = tags.getString(modTip);
tags.setString(modTip, getProperName(modifierTip, tag));
return tipNum;
}
else
{
} else {
String modTip = "ModifierTip" + tipNum;
String tag = tags.getString(modTip);
if (tag.contains(modifierTip))
{
if (tag.contains(modifierTip)) {
tags.setString(tip, "");
tag = tags.getString(modTip);
tags.setString(modTip, getProperName(modifierTip, tag));
@@ -8,60 +8,48 @@ import tconstruct.library.tools.*;
/* Little mod for actually adding the lapis modifier */
public class ModRepair extends ItemModifier
{
public class ModRepair extends ItemModifier {
public ModRepair()
{
public ModRepair() {
super(new ItemStack[0], 0, "");
}
@Override
public boolean matches (ItemStack[] input, ItemStack tool)
{
public boolean matches(ItemStack[] input, ItemStack tool) {
return canModify(tool, input);
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
protected boolean canModify(ItemStack tool, ItemStack[] input) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
if (tags.getInteger("Damage") > 0)
{
if (tags.getInteger("Damage") > 0) {
int headID = tags.getInteger("Head");
boolean areInputsValid = true;
for (ItemStack curInput : input)
{
if (curInput != null && headID != PatternBuilder.instance.getPartID(curInput))
{
for (ItemStack curInput : input) {
if (curInput != null && headID != PatternBuilder.instance.getPartID(curInput)) {
areInputsValid = false;
break;
}
}
if (areInputsValid)
{
if (areInputsValid) {
return calculateIfNecessary(tool, input);
}
}
return false;
}
private boolean calculateIfNecessary (ItemStack tool, ItemStack[] input)
{
private boolean calculateIfNecessary(ItemStack tool, ItemStack[] input) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
int damage = tags.getInteger("Damage");
int numInputs = 0;
int materialValue = 0;
for (ItemStack curInput : input)
{
if (curInput != null)
{
for (ItemStack curInput : input) {
if (curInput != null) {
materialValue += PatternBuilder.instance.getPartValue(curInput);
numInputs++;
}
}
if (numInputs == 0)
return false;
if (numInputs == 0) return false;
int totalRepairValue = calculateIncrease(tool, materialValue, numInputs);
float averageRepairValue = totalRepairValue / numInputs;
@@ -69,8 +57,7 @@ public class ModRepair extends ItemModifier
return numInputs == 1 || (damage - totalRepairValue >= -averageRepairValue);
}
private int calculateIncrease (ItemStack tool, int materialValue, int itemsUsed)
{
private int calculateIncrease(ItemStack tool, int materialValue, int itemsUsed) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
int damage = tags.getInteger("Damage");
int dur = tags.getInteger("BaseDurability");
@@ -78,27 +65,22 @@ public class ModRepair extends ItemModifier
int modifiers = tags.getInteger("Modifiers");
float mods = 1.0f;
if (modifiers == 2)
mods = 0.9f;
else if (modifiers == 1)
mods = 0.8f;
else if (modifiers == 0)
mods = 0.7f;
if (modifiers == 2) mods = 0.9f;
else if (modifiers == 1) mods = 0.8f;
else if (modifiers == 0) mods = 0.7f;
increase *= mods;
int repair = tags.getInteger("RepairCount");
float repairCount = (100 - repair) / 100f;
if (repairCount < 0.5f)
repairCount = 0.5f;
if (repairCount < 0.5f) repairCount = 0.5f;
increase *= repairCount;
increase /= ((ToolCore) tool.getItem()).getRepairCost();
return increase;
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
public void modify(ItemStack[] input, ItemStack tool) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
tags.setBoolean("Broken", false);
int damage = tags.getInteger("Damage");
@@ -106,10 +88,8 @@ public class ModRepair extends ItemModifier
int itemsUsed = 0;
int materialValue = 0;
for (ItemStack curInput : input)
{
if (curInput != null)
{
for (ItemStack curInput : input) {
if (curInput != null) {
materialValue += PatternBuilder.instance.getPartValue(curInput);
itemsUsed++;
}
@@ -121,15 +101,12 @@ public class ModRepair extends ItemModifier
tags.setInteger("RepairCount", repair);
damage -= increase;
if (damage < 0)
damage = 0;
if (damage < 0) damage = 0;
tags.setInteger("Damage", damage);
AbilityHelper.damageTool(tool, 0, null, true);
}
@Override
public void addMatchingEffect (ItemStack tool)
{
}
public void addMatchingEffect(ItemStack tool) {}
}
@@ -3,51 +3,38 @@ package tconstruct.modifiers.tools;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class ModSmite extends ItemModTypeFilter
{
public class ModSmite extends ItemModTypeFilter {
String tooltipName;
int max = 36;
String tagName;
public ModSmite(String type, int effect, ItemStack[] items, int[] values)
{
public ModSmite(String type, int effect, ItemStack[] items, int[] values) {
super(effect, "ModSmite", items, values);
tooltipName = "\u00a7eSmite";
tagName = type;
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
if (matchingAmount(input) > max)
return false;
protected boolean canModify(ItemStack tool, ItemStack[] input) {
if (matchingAmount(input) > max) return false;
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
if (!tags.hasKey(key))
return tags.getInteger("Modifiers") > 0 && matchingAmount(input) <= max;
if (!tags.hasKey(key)) return tags.getInteger("Modifiers") > 0 && matchingAmount(input) <= max;
int keyPair[] = tags.getIntArray(key);
if (keyPair[0] + matchingAmount(input) <= keyPair[1])
return true;
else if (keyPair[0] == keyPair[1])
return tags.getInteger("Modifiers") > 0;
else
return false;
if (keyPair[0] + matchingAmount(input) <= keyPair[1]) return true;
else if (keyPair[0] == keyPair[1]) return tags.getInteger("Modifiers") > 0;
else return false;
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
public void modify(ItemStack[] input, ItemStack tool) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
int increase = matchingAmount(input);
if (tags.hasKey(key))
{
if (tags.hasKey(key)) {
int[] keyPair = tags.getIntArray(key);
if (keyPair[0] % max == 0)
{
if (keyPair[0] % max == 0) {
keyPair[0] += increase;
keyPair[1] += max;
tags.setIntArray(key, keyPair);
@@ -55,29 +42,24 @@ public class ModSmite extends ItemModTypeFilter
int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
}
else
{
} else {
keyPair[0] += increase;
tags.setIntArray(key, keyPair);
}
updateModTag(tool, keyPair);
}
else
{
} else {
int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
String modName = "\u00a7e" + tagName + " (" + increase + "/" + max + ")";
int tooltipIndex = addToolTip(tool, tooltipName, modName);
int[] keyPair = new int[] { increase, max, tooltipIndex };
int[] keyPair = new int[] {increase, max, tooltipIndex};
tags.setIntArray(key, keyPair);
}
}
void updateModTag (ItemStack tool, int[] keys)
{
void updateModTag(ItemStack tool, int[] keys) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
String tip = "ModifierTip" + keys[2];
String modName = "\u00a7e" + tagName + " (" + keys[0] + "/" + keys[1] + ")";
@@ -7,60 +7,48 @@ import tconstruct.library.modifier.IModifyable;
import tconstruct.library.modifier.ItemModifier;
import tconstruct.library.tools.*;
public class ModToolRepair extends ItemModifier
{
public class ModToolRepair extends ItemModifier {
public ModToolRepair()
{
public ModToolRepair() {
super(new ItemStack[0], 0, "");
}
@Override
public boolean matches (ItemStack[] input, ItemStack tool)
{
public boolean matches(ItemStack[] input, ItemStack tool) {
return canModify(tool, input);
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
protected boolean canModify(ItemStack tool, ItemStack[] input) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
if (tags.getInteger("Damage") > 0)
{
if (tags.getInteger("Damage") > 0) {
int headID = tags.getInteger("Head");
boolean areInputsValid = true;
for (ItemStack curInput : input)
{
if (curInput != null && headID != PatternBuilder.instance.getPartID(curInput))
{
for (ItemStack curInput : input) {
if (curInput != null && headID != PatternBuilder.instance.getPartID(curInput)) {
areInputsValid = false;
break;
}
}
if (areInputsValid)
{
if (areInputsValid) {
return calculateIfNecessary(tool, input);
}
}
return false;
}
private boolean calculateIfNecessary (ItemStack tool, ItemStack[] input)
{
private boolean calculateIfNecessary(ItemStack tool, ItemStack[] input) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
int damage = tags.getInteger("Damage");
int numInputs = 0;
int materialValue = 0;
for (ItemStack curInput : input)
{
if (curInput != null)
{
for (ItemStack curInput : input) {
if (curInput != null) {
materialValue += PatternBuilder.instance.getPartValue(curInput);
numInputs++;
}
}
if (numInputs == 0)
return false;
if (numInputs == 0) return false;
int totalRepairValue = calculateIncrease(tool, materialValue, numInputs);
float averageRepairValue = totalRepairValue / numInputs;
@@ -68,8 +56,7 @@ public class ModToolRepair extends ItemModifier
return numInputs == 1 || (damage - totalRepairValue >= -averageRepairValue);
}
private int calculateIncrease (ItemStack tool, int materialValue, int itemsUsed)
{
private int calculateIncrease(ItemStack tool, int materialValue, int itemsUsed) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
int damage = tags.getInteger("Damage");
int dur = tags.getInteger("BaseDurability");
@@ -77,27 +64,22 @@ public class ModToolRepair extends ItemModifier
int modifiers = tags.getInteger("Modifiers");
float mods = 1.0f;
if (modifiers == 2)
mods = 0.9f;
else if (modifiers == 1)
mods = 0.8f;
else if (modifiers == 0)
mods = 0.7f;
if (modifiers == 2) mods = 0.9f;
else if (modifiers == 1) mods = 0.8f;
else if (modifiers == 0) mods = 0.7f;
increase *= mods;
int repair = tags.getInteger("RepairCount");
float repairCount = (100 - repair) / 100f;
if (repairCount < 0.5f)
repairCount = 0.5f;
if (repairCount < 0.5f) repairCount = 0.5f;
increase *= repairCount;
increase /= ((ToolCore) tool.getItem()).getRepairCost();
return increase;
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
public void modify(ItemStack[] input, ItemStack tool) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
tags.setBoolean("Broken", false);
int damage = tags.getInteger("Damage");
@@ -105,10 +87,8 @@ public class ModToolRepair extends ItemModifier
int itemsUsed = 0;
int materialValue = 0;
for (ItemStack curInput : input)
{
if (curInput != null)
{
for (ItemStack curInput : input) {
if (curInput != null) {
materialValue += PatternBuilder.instance.getPartValue(curInput);
itemsUsed++;
}
@@ -120,20 +100,16 @@ public class ModToolRepair extends ItemModifier
tags.setInteger("RepairCount", repair);
damage -= increase;
if (damage < 0)
damage = 0;
if (damage < 0) damage = 0;
tags.setInteger("Damage", damage);
AbilityHelper.damageTool(tool, 0, null, true);
}
@Override
public void addMatchingEffect (ItemStack tool)
{
}
public void addMatchingEffect(ItemStack tool) {}
public boolean validType (IModifyable input)
{
public boolean validType(IModifyable input) {
return input.getModifyType().equals("Tool") || input.getModifyType().equals("Armor");
}
}
@@ -1,45 +1,38 @@
package tconstruct.modifiers.tools;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.tools.ToolCore;
import java.util.Arrays;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.tools.ToolCore;
public class ModWindup extends ModRedstone {
public ModWindup(int effect, ItemStack[] items, int[] values) {
super(effect, items, values);
}
public boolean validType (ToolCore tool)
{
public boolean validType(ToolCore tool) {
List list = Arrays.asList(tool.getTraits());
return list.contains("windup");
}
@Override
protected boolean canModify(ItemStack tool, ItemStack[] input) {
if(!super.canModify(tool, input))
return false;
if (!super.canModify(tool, input)) return false;
float drawSSpeed = tool.getTagCompound().getCompoundTag("InfiTool").getFloat("DrawSpeed");
return drawSSpeed > 0.25f * 20f; // can't get below 1/4s
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
public void modify(ItemStack[] input, ItemStack tool) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
int[] keyPair;
int increase = matchingAmount(input);
int current = 0;
if (tags.hasKey(key))
{
if (tags.hasKey(key)) {
keyPair = tags.getIntArray(key);
if (keyPair[0] % max == 0)
{
if (keyPair[0] % max == 0) {
keyPair[0] += increase;
keyPair[1] += max;
tags.setIntArray(key, keyPair);
@@ -47,23 +40,19 @@ public class ModWindup extends ModRedstone {
int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
}
else
{
} else {
keyPair[0] += increase;
tags.setIntArray(key, keyPair);
}
current = keyPair[0];
updateModTag(tool, keyPair);
}
else
{
} else {
int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
String modName = "\u00a74Redstone (" + increase + "/" + max + ")";
int tooltipIndex = addToolTip(tool, tooltipName, modName);
keyPair = new int[] { increase, max, tooltipIndex };
keyPair = new int[] {increase, max, tooltipIndex};
current = keyPair[0];
tags.setIntArray(key, keyPair);
}
@@ -72,11 +61,10 @@ public class ModWindup extends ModRedstone {
float boost = 0.10f * current;
// with added bonus for multiple modifiers of redstone
// so every 50 redstone you get a bonus speed
for(int i = 0; i < current/50; i++)
boost += 2.0f;
for (int i = 0; i < current / 50; i++) boost += 2.0f;
int baseDrawSpeed = tags.getInteger("BaseDrawSpeed");
int drawSpeed = baseDrawSpeed - (int)boost;
int drawSpeed = baseDrawSpeed - (int) boost;
drawSpeed = Math.max(5, drawSpeed); // 0.25f is the minimum
tags.setInteger("DrawSpeed", drawSpeed);
}