diff --git a/src/main/java/tconstruct/library/modifier/ModificationInfo.java b/src/main/java/tconstruct/library/modifier/ModificationInfo.java new file mode 100644 index 00000000..e61b66c4 --- /dev/null +++ b/src/main/java/tconstruct/library/modifier/ModificationInfo.java @@ -0,0 +1,6 @@ +package tconstruct.library.modifier; + +import com.github.bsideup.jabel.Desugar; + +@Desugar +public record ModificationInfo(int total, int[] toRemove) {} diff --git a/src/main/java/tconstruct/modifiers/accessory/GloveSpeed.java b/src/main/java/tconstruct/modifiers/accessory/GloveSpeed.java index a9adf96b..bbc0df45 100644 --- a/src/main/java/tconstruct/modifiers/accessory/GloveSpeed.java +++ b/src/main/java/tconstruct/modifiers/accessory/GloveSpeed.java @@ -8,16 +8,17 @@ import net.minecraft.util.StatCollector; 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 @@ -27,12 +28,13 @@ public class GloveSpeed extends ItemModTypeFilter { 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; } @@ -43,7 +45,10 @@ public class GloveSpeed extends ItemModTypeFilter { 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) { diff --git a/src/main/java/tconstruct/modifiers/tools/ItemModTypeFilter.java b/src/main/java/tconstruct/modifiers/tools/ItemModTypeFilter.java index 3ffd8fed..cbedc216 100644 --- a/src/main/java/tconstruct/modifiers/tools/ItemModTypeFilter.java +++ b/src/main/java/tconstruct/modifiers/tools/ItemModTypeFilter.java @@ -4,12 +4,15 @@ import java.util.ArrayList; 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 increase; + protected int max; public ItemModTypeFilter(int effect, String dataKey, ItemStack[] items, int[] values) { super(items, effect, dataKey); @@ -51,21 +54,67 @@ public abstract class ItemModTypeFilter extends ItemModifier { 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 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); } /** diff --git a/src/main/java/tconstruct/modifiers/tools/ModAntiSpider.java b/src/main/java/tconstruct/modifiers/tools/ModAntiSpider.java index 36f987b2..d2a96c99 100644 --- a/src/main/java/tconstruct/modifiers/tools/ModAntiSpider.java +++ b/src/main/java/tconstruct/modifiers/tools/ModAntiSpider.java @@ -3,27 +3,29 @@ package tconstruct.modifiers.tools; 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; } @@ -31,7 +33,10 @@ public class ModAntiSpider extends ItemModTypeFilter { @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); diff --git a/src/main/java/tconstruct/modifiers/tools/ModAttack.java b/src/main/java/tconstruct/modifiers/tools/ModAttack.java index 657eec9f..5e102ea3 100644 --- a/src/main/java/tconstruct/modifiers/tools/ModAttack.java +++ b/src/main/java/tconstruct/modifiers/tools/ModAttack.java @@ -6,12 +6,12 @@ import net.minecraft.item.ItemStack; 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; @@ -22,7 +22,7 @@ public class ModAttack extends ItemModTypeFilter { super(effect, "ModAttack", items, value); tooltipName = "\u00a7fSharpness"; guiType = type; - max = 72; + this.max = 72; threshold = 24; modifierType = "Tool"; ammoOnly = false; @@ -33,7 +33,7 @@ public class ModAttack extends ItemModTypeFilter { super(effect, "ModAttack", items, value); tooltipName = "\u00a7fSharpness"; guiType = type; - max = 48; + this.max = 48; threshold = 24; modifierType = "Tool"; this.ammoOnly = ammoOnly; @@ -61,13 +61,14 @@ public class ModAttack extends ItemModTypeFilter { 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; @@ -83,9 +84,13 @@ public class ModAttack extends ItemModTypeFilter { 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); @@ -113,7 +118,6 @@ public class ModAttack extends ItemModTypeFilter { 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); diff --git a/src/main/java/tconstruct/modifiers/tools/ModBlaze.java b/src/main/java/tconstruct/modifiers/tools/ModBlaze.java index ac4d588b..62ffdde9 100644 --- a/src/main/java/tconstruct/modifiers/tools/ModBlaze.java +++ b/src/main/java/tconstruct/modifiers/tools/ModBlaze.java @@ -6,17 +6,17 @@ import java.util.List; 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 @@ -25,13 +25,14 @@ public class ModBlaze extends ItemModTypeFilter { 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; @@ -40,7 +41,10 @@ public class ModBlaze extends ItemModTypeFilter { @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) { diff --git a/src/main/java/tconstruct/modifiers/tools/ModLapis.java b/src/main/java/tconstruct/modifiers/tools/ModLapis.java index 7752ac33..f1934565 100644 --- a/src/main/java/tconstruct/modifiers/tools/ModLapis.java +++ b/src/main/java/tconstruct/modifiers/tools/ModLapis.java @@ -11,16 +11,17 @@ import net.minecraft.item.ItemStack; 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 @@ -29,16 +30,17 @@ public class ModLapis extends ItemModTypeFilter { 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; } @@ -59,7 +61,10 @@ public class ModLapis extends ItemModTypeFilter { 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); diff --git a/src/main/java/tconstruct/modifiers/tools/ModPiston.java b/src/main/java/tconstruct/modifiers/tools/ModPiston.java index 5f4c005e..f8cf9cf5 100644 --- a/src/main/java/tconstruct/modifiers/tools/ModPiston.java +++ b/src/main/java/tconstruct/modifiers/tools/ModPiston.java @@ -6,16 +6,17 @@ import java.util.List; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import tconstruct.library.modifier.ModificationInfo; import tconstruct.library.tools.ToolCore; public class ModPiston extends ItemModTypeFilter { String tooltipName; - int max = 10; public ModPiston(int effect, ItemStack[] items, int[] values) { super(effect, "Piston", items, values); tooltipName = "\u00a77Knockback"; + this.max = 10; } @Override @@ -24,13 +25,14 @@ public class ModPiston extends ItemModTypeFilter { 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; @@ -39,7 +41,10 @@ public class ModPiston extends ItemModTypeFilter { @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) { diff --git a/src/main/java/tconstruct/modifiers/tools/ModRedstone.java b/src/main/java/tconstruct/modifiers/tools/ModRedstone.java index 54055dfc..ea577d7f 100644 --- a/src/main/java/tconstruct/modifiers/tools/ModRedstone.java +++ b/src/main/java/tconstruct/modifiers/tools/ModRedstone.java @@ -8,16 +8,17 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import tconstruct.library.modifier.IModifyable; +import tconstruct.library.modifier.ModificationInfo; import tconstruct.library.tools.ToolCore; public class ModRedstone extends ItemModTypeFilter { public String tooltipName; - public int max = 50; public ModRedstone(int effect, ItemStack[] items, int[] values) { super(effect, "Redstone", items, values); tooltipName = "\u00a74Haste"; + this.max = 50; } @Override @@ -26,14 +27,15 @@ public class ModRedstone extends ItemModTypeFilter { 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; } @@ -44,7 +46,10 @@ public class ModRedstone extends ItemModTypeFilter { public void modify(ItemStack[] input, ItemStack tool) { NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool"); int[] keyPair; - int increase = matchingAmount(input); + ModificationInfo modificationInfo = matchingAmount(input, tool); + int increase = modificationInfo.total(); + tags.setIntArray("ToRemove", modificationInfo.toRemove()); + int current; if (tags.hasKey(key)) { keyPair = tags.getIntArray(key); diff --git a/src/main/java/tconstruct/modifiers/tools/ModSmite.java b/src/main/java/tconstruct/modifiers/tools/ModSmite.java index 35027830..afe06ef2 100644 --- a/src/main/java/tconstruct/modifiers/tools/ModSmite.java +++ b/src/main/java/tconstruct/modifiers/tools/ModSmite.java @@ -3,27 +3,29 @@ package tconstruct.modifiers.tools; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import tconstruct.library.modifier.ModificationInfo; + public class ModSmite extends ItemModTypeFilter { String tooltipName; - int max = 36; String tagName; public ModSmite(String type, int effect, ItemStack[] items, int[] values) { super(effect, "ModSmite", items, values); tooltipName = "\u00a7eSmite"; tagName = type; + this.max = 36; } @Override protected boolean canModify(ItemStack tool, ItemStack[] input) { - 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; else return false; } @@ -31,7 +33,10 @@ public class ModSmite extends ItemModTypeFilter { @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); diff --git a/src/main/java/tconstruct/modifiers/tools/ModWindup.java b/src/main/java/tconstruct/modifiers/tools/ModWindup.java index 9d17431d..0a1f2a01 100644 --- a/src/main/java/tconstruct/modifiers/tools/ModWindup.java +++ b/src/main/java/tconstruct/modifiers/tools/ModWindup.java @@ -6,6 +6,7 @@ import java.util.List; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import tconstruct.library.modifier.ModificationInfo; import tconstruct.library.tools.ToolCore; public class ModWindup extends ModRedstone { @@ -31,7 +32,10 @@ public class ModWindup extends ModRedstone { public void modify(ItemStack[] input, ItemStack tool) { NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool"); int[] keyPair; - int increase = matchingAmount(input); + ModificationInfo modificationInfo = matchingAmount(input, tool); + int increase = modificationInfo.total(); + tags.setIntArray("ToRemove", modificationInfo.toRemove()); + int current; if (tags.hasKey(key)) { keyPair = tags.getIntArray(key); diff --git a/src/main/java/tconstruct/tools/inventory/SlotCraftingStation.java b/src/main/java/tconstruct/tools/inventory/SlotCraftingStation.java index 1a68d657..9f5cbf15 100644 --- a/src/main/java/tconstruct/tools/inventory/SlotCraftingStation.java +++ b/src/main/java/tconstruct/tools/inventory/SlotCraftingStation.java @@ -4,6 +4,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.SlotCrafting; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import tconstruct.library.modifier.IModifyable; import tconstruct.library.tools.AbilityHelper; @@ -23,7 +24,28 @@ public class SlotCraftingStation extends SlotCrafting { @Override public void onPickupFromSlot(EntityPlayer player, ItemStack stack) { ItemStack tool = this.matrix.getStackInSlot(4); - if (stack.getItem() instanceof IModifyable && tool != null && tool.getItem() instanceof IModifyable) { + if (stack.getItem() instanceof IModifyable modifyable && tool != null + && tool.getItem() instanceof IModifyable) { + NBTTagCompound tags = stack.getTagCompound().getCompoundTag(modifyable.getBaseTagName()); + int[] toRemoveArray = tags.hasKey("ToRemove") ? tags.getIntArray("ToRemove") : null; + int toRemoveIndex = 0; + IInventory inventory = this.matrix; + + for (int i = 0; i <= inventory.getSizeInventory(); i++) { + if (i == 4) continue; + ItemStack item = inventory.getStackInSlot(i); + if (item == null) { + continue; + } + if (toRemoveArray == null) { + inventory.decrStackSize(i, 1); + } else { + inventory.decrStackSize(i, toRemoveArray[toRemoveIndex]); + toRemoveIndex++; + } + } + tags.removeTag("ToRemove"); + matrix.setInventorySlotContents(4, null); player.worldObj.playSoundEffect( player.posX, @@ -32,7 +54,8 @@ public class SlotCraftingStation extends SlotCrafting { "tinker:little_saw", 1.0F, (AbilityHelper.random.nextFloat() - AbilityHelper.random.nextFloat()) * 0.2F + 1.0F); + } else { + super.onPickupFromSlot(player, stack); } - super.onPickupFromSlot(player, stack); } } diff --git a/src/main/java/tconstruct/tools/inventory/SlotTool.java b/src/main/java/tconstruct/tools/inventory/SlotTool.java index 439aeabc..3990e55d 100644 --- a/src/main/java/tconstruct/tools/inventory/SlotTool.java +++ b/src/main/java/tconstruct/tools/inventory/SlotTool.java @@ -55,8 +55,23 @@ public class SlotTool extends Slot { if (stack.getItem() instanceof IModifyable) { NBTTagCompound tags = stack.getTagCompound() .getCompoundTag(((IModifyable) stack.getItem()).getBaseTagName()); + int[] toRemoveArray = tags.hasKey("ToRemove") ? tags.getIntArray("ToRemove") : null; + int toRemoveIndex = 0; + boolean full = (inventory.getStackInSlot(2) != null || inventory.getStackInSlot(3) != null); - for (int i = 2; i <= 3; i++) inventory.decrStackSize(i, 1); + for (int i = 2; i <= 3; i++) { + ItemStack item = inventory.getStackInSlot(i); + if (item == null) { + continue; + } + if (toRemoveArray == null) { + inventory.decrStackSize(i, 1); + } else { + inventory.decrStackSize(i, toRemoveArray[toRemoveIndex]); + toRemoveIndex++; + } + } + tags.removeTag("ToRemove"); ItemStack compare = inventory.getStackInSlot(1); int amount = compare.getItem() instanceof IModifyable ? compare.stackSize : 1; inventory.decrStackSize(1, amount); diff --git a/src/main/java/tconstruct/tools/inventory/SlotToolForge.java b/src/main/java/tconstruct/tools/inventory/SlotToolForge.java index 41c69967..c33bdaf3 100644 --- a/src/main/java/tconstruct/tools/inventory/SlotToolForge.java +++ b/src/main/java/tconstruct/tools/inventory/SlotToolForge.java @@ -25,9 +25,25 @@ public class SlotToolForge extends SlotTool { if (stack.getItem() instanceof IModifyable) { NBTTagCompound tags = stack.getTagCompound() .getCompoundTag(((IModifyable) stack.getItem()).getBaseTagName()); + int[] toRemoveArray = tags.hasKey("ToRemove") ? tags.getIntArray("ToRemove") : null; + int toRemoveIndex = 0; + boolean full = (inventory.getStackInSlot(2) != null || inventory.getStackInSlot(3) != null || inventory.getStackInSlot(4) != null); - for (int i = 2; i <= 4; i++) inventory.decrStackSize(i, 1); + for (int i = 2; i <= 4; i++) { + ItemStack item = inventory.getStackInSlot(i); + if (item == null) { + continue; + } + if (toRemoveArray == null) { + inventory.decrStackSize(i, 1); + } else { + inventory.decrStackSize(i, toRemoveArray[toRemoveIndex]); + toRemoveIndex++; + } + } + tags.removeTag("ToRemove"); + ItemStack compare = inventory.getStackInSlot(1); int amount = compare.getItem() instanceof IModifyable ? compare.stackSize : 1; inventory.decrStackSize(1, amount); diff --git a/src/main/java/tconstruct/tools/inventory/ToolForgeContainer.java b/src/main/java/tconstruct/tools/inventory/ToolForgeContainer.java index 8e5dfdee..a156c631 100644 --- a/src/main/java/tconstruct/tools/inventory/ToolForgeContainer.java +++ b/src/main/java/tconstruct/tools/inventory/ToolForgeContainer.java @@ -74,9 +74,23 @@ public class ToolForgeContainer extends ToolStationContainer { if (stack.getItem() instanceof IModifyable) { NBTTagCompound tags = stack.getTagCompound() .getCompoundTag(((IModifyable) stack.getItem()).getBaseTagName()); + int[] toRemoveArray = tags.hasKey("ToRemove") ? tags.getIntArray("ToRemove") : null; + int toRemoveIndex = 0; + boolean full = (logic.getStackInSlot(2) != null || logic.getStackInSlot(3) != null || logic.getStackInSlot(4) != null); - for (int i = 2; i <= 4; i++) logic.decrStackSize(i, 1); + for (int i = 2; i <= 4; i++) { + ItemStack item = logic.getStackInSlot(i); + if (item == null) { + continue; + } + if (toRemoveArray == null) { + logic.decrStackSize(i, 1); + } else { + logic.decrStackSize(i, toRemoveArray[toRemoveIndex]); + toRemoveIndex++; + } + } ItemStack compare = logic.getStackInSlot(1); int amount = compare.getItem() instanceof IModifyable ? compare.stackSize : 1; logic.decrStackSize(1, amount); diff --git a/src/main/java/tconstruct/tools/inventory/ToolStationContainer.java b/src/main/java/tconstruct/tools/inventory/ToolStationContainer.java index 56070615..75ec3b2b 100644 --- a/src/main/java/tconstruct/tools/inventory/ToolStationContainer.java +++ b/src/main/java/tconstruct/tools/inventory/ToolStationContainer.java @@ -124,8 +124,23 @@ public class ToolStationContainer extends ActiveContainer { if (stack.getItem() instanceof IModifyable) { NBTTagCompound tags = stack.getTagCompound() .getCompoundTag(((IModifyable) stack.getItem()).getBaseTagName()); + int[] toRemoveArray = tags.hasKey("ToRemove") ? tags.getIntArray("ToRemove") : null; + int toRemoveIndex = 0; + boolean full = (logic.getStackInSlot(2) != null || logic.getStackInSlot(3) != null); - for (int i = 2; i <= 3; i++) logic.decrStackSize(i, 1); + for (int i = 2; i <= 3; i++) { + ItemStack item = logic.getStackInSlot(i); + if (item == null) { + continue; + } + if (toRemoveArray == null) { + logic.decrStackSize(i, 1); + } else { + logic.decrStackSize(i, toRemoveArray[toRemoveIndex]); + toRemoveIndex++; + } + } + tags.removeTag("ToRemove"); ItemStack compare = logic.getStackInSlot(1); int amount = compare.getItem() instanceof IModifyable ? compare.stackSize : 1; logic.decrStackSize(1, amount);