Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package tconstruct.library.modifier;

import com.github.bsideup.jabel.Desugar;

@Desugar
public record ModificationInfo(int total, int[] toRemove) {}
17 changes: 11 additions & 6 deletions src/main/java/tconstruct/modifiers/accessory/GloveSpeed.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@

import tconstruct.library.accessory.AccessoryCore;
import tconstruct.library.modifier.IModifyable;
import tconstruct.library.modifier.ModificationInfo;
import tconstruct.modifiers.tools.ItemModTypeFilter;

public class GloveSpeed extends ItemModTypeFilter {

String tooltipName;
int max = 100;

public GloveSpeed(int effect, ItemStack[] items, int[] values) {
super(effect, "Redstone", items, values);
tooltipName = ("\u00a74" + StatCollector.translateToLocal("modifier.tooltip.Haste"));
this.max = 100;
}

@Override
Expand All @@ -27,12 +28,13 @@ protected boolean canModify(ItemStack input, ItemStack[] modifiers) {
if (!Arrays.asList(((AccessoryCore) input.getItem()).getTraits()).contains("glove")) return false;

NBTTagCompound tags = getModifierTag(input);
if (!tags.hasKey(key)) return tags.getInteger("Modifiers") > 0 && matchingAmount(modifiers) <= max; // This
// line
// fails?
if (!tags.hasKey(key))
return tags.getInteger("Modifiers") > 0 && matchingAmount(modifiers, input).total() <= max; // This
// line
// fails?

int[] keyPair = tags.getIntArray(key);
if (keyPair[0] + matchingAmount(modifiers) <= keyPair[1]) return true;
if (keyPair[0] + matchingAmount(modifiers, input).total() <= keyPair[1]) return true;
else if (keyPair[0] == keyPair[1]) return tags.getInteger("Modifiers") > 0;
}

Expand All @@ -43,7 +45,10 @@ protected boolean canModify(ItemStack input, ItemStack[] modifiers) {
public void modify(ItemStack[] modifiers, ItemStack input) {
NBTTagCompound tags = getModifierTag(input);
int[] keyPair;
int increase = matchingAmount(modifiers);
ModificationInfo modificationInfo = matchingAmount(modifiers, input);
int increase = modificationInfo.total();
tags.setIntArray("ToRemove", modificationInfo.toRemove());

if (tags.hasKey(key)) {
keyPair = tags.getIntArray(key);
if (keyPair[0] % max == 0) {
Expand Down
67 changes: 58 additions & 9 deletions src/main/java/tconstruct/modifiers/tools/ItemModTypeFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import java.util.List;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

import tconstruct.library.modifier.ItemModifier;
import tconstruct.library.modifier.ModificationInfo;

public abstract class ItemModTypeFilter extends ItemModifier {

public final List<Integer> increase;
protected int max;

public ItemModTypeFilter(int effect, String dataKey, ItemStack[] items, int[] values) {
super(items, effect, dataKey);
Expand Down Expand Up @@ -51,21 +54,67 @@ public boolean matches(ItemStack[] input, ItemStack tool) {
return minimumMatch;
}

public int matchingAmount(ItemStack[] input) {
// Needed because Lapis modifier does not put its max in the keyPair
public ModificationInfo matchingAmount(ItemStack[] input, ItemStack tool) {
return matchingAmount(input, tool, max);
}

public ModificationInfo matchingAmount(ItemStack[] input, ItemStack tool, int modifierMax) {

NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
int availableAmount;
if (tags.hasKey(key)) {
int[] keyPair = tags.getIntArray(key);
if (keyPair[0] % modifierMax == 0) {
availableAmount = modifierMax;
} else {
// Blame Lapis modifier
int upperLimit = keyPair.length == 2 ? modifierMax : keyPair[1];
availableAmount = upperLimit - keyPair[0];
}
} else {
availableAmount = modifierMax;
}
int amount = 0;

ArrayList<Integer> toRemove = new ArrayList<>();

for (ItemStack inputStack : input) {
if (inputStack != null) {
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 (inputStack == null) {
continue;
}
for (int iter = 0; iter < stacks.size(); iter++) {
ItemStack stack = stacks.get(iter);
int perItemIncrease = increase.get(iter);
int maxItems = availableAmount / perItemIncrease;
int itemsUsed;
int usedAmount = 0;

if (stack.getItemDamage() == Short.MAX_VALUE) {

if (this.areItemsEquivalent(inputStack, stack)) {
itemsUsed = Math.min(maxItems, inputStack.stackSize);
usedAmount = perItemIncrease * itemsUsed;
amount += usedAmount;
availableAmount -= usedAmount;
toRemove.add(itemsUsed);
}
} else {
if (this.areItemStacksEquivalent(inputStack, stack)) {
itemsUsed = Math.min(maxItems, inputStack.stackSize);
usedAmount = perItemIncrease * itemsUsed;
amount += usedAmount;
availableAmount -= usedAmount;
toRemove.add(itemsUsed);
}
}
}
}
return amount;
int[] toRemoveArray = new int[toRemove.size()];
for (int i = 0; i < toRemove.size(); i++) {
toRemoveArray[i] = toRemove.get(i);
}
return new ModificationInfo(amount, toRemoveArray);
}

/**
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/tconstruct/modifiers/tools/ModAntiSpider.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,40 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

import tconstruct.library.modifier.ModificationInfo;

public class ModAntiSpider extends ItemModTypeFilter {

String tooltipName;
int max = 4;
String guiType;

public ModAntiSpider(String type, int effect, ItemStack[] items, int[] values) {
super(effect, "ModAntiSpider", items, values);
tooltipName = "\u00a72Bane of Arthropods";
guiType = type;
this.max = 4;
}

@Override
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, tool).total() <= max;

if (matchingAmount(input) > max) return false;
if (matchingAmount(input, tool).total() > max) return false;

int[] keyPair = tags.getIntArray(key);
if (keyPair[0] + matchingAmount(input) <= keyPair[1]) return true;
if (keyPair[0] + matchingAmount(input, tool).total() <= 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) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
int increase = matchingAmount(input);
ModificationInfo modificationInfo = matchingAmount(input, tool);
int increase = modificationInfo.total();
tags.setIntArray("ToRemove", modificationInfo.toRemove());

if (tags.hasKey(key)) {
int[] keyPair = tags.getIntArray(key);

Expand Down
20 changes: 12 additions & 8 deletions src/main/java/tconstruct/modifiers/tools/ModAttack.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import net.minecraft.nbt.NBTTagCompound;

import tconstruct.library.modifier.IModifyable;
import tconstruct.library.modifier.ModificationInfo;
import tconstruct.library.tools.ToolCore;

public class ModAttack extends ItemModTypeFilter {

String tooltipName;
int max;
int threshold;
String guiType;
String modifierType;
Expand All @@ -22,7 +22,7 @@ public ModAttack(String type, int effect, ItemStack[] items, int[] value) {
super(effect, "ModAttack", items, value);
tooltipName = "\u00a7fSharpness";
guiType = type;
max = 72;
this.max = 72;
threshold = 24;
modifierType = "Tool";
ammoOnly = false;
Expand All @@ -33,7 +33,7 @@ public ModAttack(String type, int effect, ItemStack[] items, int[] value, boolea
super(effect, "ModAttack", items, value);
tooltipName = "\u00a7fSharpness";
guiType = type;
max = 48;
this.max = 48;
threshold = 24;
modifierType = "Tool";
this.ammoOnly = ammoOnly;
Expand Down Expand Up @@ -61,13 +61,14 @@ protected boolean canModify(ItemStack tool, ItemStack[] input) {
IModifyable toolItem = (IModifyable) tool.getItem();
if (!validType(toolItem)) return false;

if (matchingAmount(input) > max) return false;
if (matchingAmount(input, tool).total() > 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, tool).total() <= max;

int[] keyPair = tags.getIntArray(key);
if (keyPair[0] + matchingAmount(input) <= keyPair[1]) return true;
if (keyPair[0] + matchingAmount(input, tool).total() <= keyPair[1]) return true;
else if (keyPair[0] == keyPair[1]) return tags.getInteger("Modifiers") > 0;
}
return false;
Expand All @@ -83,9 +84,13 @@ public boolean validType(IModifyable input) {
public void modify(ItemStack[] input, ItemStack tool) {
IModifyable toolItem = (IModifyable) tool.getItem();
NBTTagCompound tags = tool.getTagCompound().getCompoundTag(toolItem.getBaseTagName());

ModificationInfo modificationInfo = matchingAmount(input, tool);
int increase = modificationInfo.total();
tags.setIntArray("ToRemove", modificationInfo.toRemove());

if (tags.hasKey(key)) {
int[] keyPair = tags.getIntArray(key);
int increase = matchingAmount(input);
int overThreshold = increase / threshold;

int leftToBoost = threshold - (keyPair[0] % threshold);
Expand Down Expand Up @@ -113,7 +118,6 @@ public void modify(ItemStack[] input, ItemStack tool) {
int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
int increase = matchingAmount(input);
int overThreshold = increase / threshold;
String modName = "\u00a7f" + guiType + " (" + increase + "/" + max + ")";
int tooltipIndex = addToolTip(tool, tooltipName, modName);
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/tconstruct/modifiers/tools/ModBlaze.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

import tconstruct.library.modifier.ModificationInfo;
import tconstruct.library.tools.ToolCore;

public class ModBlaze extends ItemModTypeFilter {

String tooltipName;
int max;

public ModBlaze(int effect, ItemStack[] items, int[] values) {
super(effect, "Blaze", items, values);
tooltipName = "\u00a76Fiery";
max = 25;
this.max = 25;
}

@Override
Expand All @@ -25,13 +25,14 @@ protected boolean canModify(ItemStack tool, ItemStack[] input) {
ToolCore toolItem = (ToolCore) tool.getItem();
if (!validType(toolItem)) return false;

if (matchingAmount(input) > max) return false;
if (matchingAmount(input, tool).total() > 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, tool).total() <= max;

int[] keyPair = tags.getIntArray(key);
if (keyPair[0] + matchingAmount(input) <= keyPair[1]) return true;
if (keyPair[0] + matchingAmount(input, tool).total() <= keyPair[1]) return true;
else if (keyPair[0] == keyPair[1]) return tags.getInteger("Modifiers") > 0;
}
return false;
Expand All @@ -40,7 +41,10 @@ protected boolean canModify(ItemStack tool, ItemStack[] input) {
@Override
public void modify(ItemStack[] input, ItemStack tool) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
int increase = matchingAmount(input);
ModificationInfo modificationInfo = matchingAmount(input, tool);
int increase = modificationInfo.total();
tags.setIntArray("ToRemove", modificationInfo.toRemove());

if (tags.hasKey(key)) {
int[] keyPair = tags.getIntArray(key);
if (keyPair[0] % max == 0) {
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/tconstruct/modifiers/tools/ModLapis.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;

import tconstruct.library.modifier.ModificationInfo;
import tconstruct.library.tools.ToolCore;

public class ModLapis extends ItemModTypeFilter {

String tooltipName;
int max = 450;

public ModLapis(int effect, ItemStack[] items, int[] values) {
super(effect, "Lapis", items, values);
tooltipName = "\u00a79Luck";
this.max = 450;
}

@Override
Expand All @@ -29,16 +30,17 @@ protected boolean canModify(ItemStack tool, ItemStack[] input) {
ToolCore toolItem = (ToolCore) tool.getItem();
if (!validType(toolItem)) return false;

if (matchingAmount(input) > max) return false;
if (matchingAmount(input, tool).total() > max) return false;

NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");

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, tool).total() <= max;

int[] keyPair = tags.getIntArray(key);
return keyPair[0] + matchingAmount(input) <= max;
return keyPair[0] + matchingAmount(input, tool).total() <= max;
}
return false;
}
Expand All @@ -59,7 +61,10 @@ public void modify(ItemStack[] input, ItemStack tool) {
tags.setInteger("Modifiers", modifiers);
}

int increase = matchingAmount(input);
ModificationInfo modificationInfo = matchingAmount(input, tool, 450);
int increase = modificationInfo.total();
tags.setIntArray("ToRemove", modificationInfo.toRemove());

int[] keyPair = tags.getIntArray(key);
keyPair[0] += increase;
tags.setIntArray(key, keyPair);
Expand Down
Loading