From fdb3e85346df08d19ba2a56f96a21fd5ea719e47 Mon Sep 17 00:00:00 2001 From: Andrew Hill Date: Fri, 14 Sep 2012 19:44:15 +1000 Subject: [PATCH] place the actual block consumed, rather than what is in the template in almost all cases there is no difference, but there have been reports that mod items with inventories get the inventories duplicated. this should fix that. --- .../buildcraft/api/blueprints/BptBlock.java | 8 ++++++- .../core/blueprints/BptBuilderBlueprint.java | 22 ++++++++++++++----- .../buildcraft/core/blueprints/BptSlot.java | 5 +++-- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/common/buildcraft/api/blueprints/BptBlock.java b/common/buildcraft/api/blueprints/BptBlock.java index 770140d9..d813b087 100644 --- a/common/buildcraft/api/blueprints/BptBlock.java +++ b/common/buildcraft/api/blueprints/BptBlock.java @@ -91,11 +91,15 @@ public class BptBlock { * fullfilled, and once with the real inventory. Implementer is responsible * for updating req (with the remaining requirements if any) and stack * (after usage) + * + * returns: what was used (similer to req, but created from stack, so that any NBT based differences are drawn from the correct source) */ - public void useItem(BptSlotInfo slot, IBptContext context, ItemStack req, ItemStack stack) { + public ItemStack useItem(BptSlotInfo slot, IBptContext context, ItemStack req, ItemStack stack) { + ItemStack result = stack.copy(); if (stack.isItemStackDamageable()) { if (req.getItemDamage() + stack.getItemDamage() <= stack.getMaxDamage()) { stack.setItemDamage(req.getItemDamage() + stack.getItemDamage()); + result.setItemDamage(req.getItemDamage()); req.stackSize = 0; } @@ -104,6 +108,7 @@ public class BptBlock { } } else { if (stack.stackSize >= req.stackSize) { + result.stackSize = req.stackSize; stack.stackSize -= req.stackSize; req.stackSize = 0; } else { @@ -119,6 +124,7 @@ public class BptBlock { stack.stackSize = 1; stack.setItemDamage(0); } + return result; } /** diff --git a/common/buildcraft/core/blueprints/BptBuilderBlueprint.java b/common/buildcraft/core/blueprints/BptBuilderBlueprint.java index 0f9c7fe4..f2d30a46 100644 --- a/common/buildcraft/core/blueprints/BptBuilderBlueprint.java +++ b/common/buildcraft/core/blueprints/BptBuilderBlueprint.java @@ -11,6 +11,7 @@ package buildcraft.core.blueprints; import java.util.Comparator; import java.util.LinkedList; +import java.util.ListIterator; import java.util.TreeMap; import java.util.TreeSet; @@ -48,7 +49,7 @@ public class BptBuilderBlueprint extends BptBuilderBase { return -1; else if (o1.getItemDamage() < o2.getItemDamage()) return 1; - + return 0; } }); @@ -239,10 +240,12 @@ public class BptBuilderBlueprint extends BptBuilderBase { for (ItemStack invStk : tmpInv) if (invStk != null && reqStk.itemID == invStk.itemID && invStk.stackSize > 0) { - if (!invStk.isItemStackDamageable() && (reqStk.getItemDamage() != invStk.getItemDamage())) - continue; + if (!invStk.isItemStackDamageable() && (reqStk.getItemDamage() != invStk.getItemDamage())){ + continue; // it doesn't match, try again + } try { + slot.useItem(context, reqStk, invStk); } catch (Throwable t) { // Defensive code against errors in implementers @@ -278,7 +281,12 @@ public class BptBuilderBlueprint extends BptBuilderBase { } - for (ItemStack reqStk : tmpReq) { + ListIterator itr = tmpReq.listIterator(); + + while(itr.hasNext()) { + ItemStack reqStk = itr.next(); + boolean smallStack = reqStk.stackSize == 1; + ItemStack usedStack = reqStk; int size = inv.getSizeInventory(); for (int i = 0; i <= size; ++i) { if (!inv.isBuildingMaterial(i)) { @@ -293,7 +301,7 @@ public class BptBuilderBlueprint extends BptBuilderBase { continue; try { - slot.useItem(context, reqStk, invStk); + usedStack = slot.useItem(context, reqStk, invStk); } catch (Throwable t) { // Defensive code against errors in implementers t.printStackTrace(); @@ -312,6 +320,8 @@ public class BptBuilderBlueprint extends BptBuilderBase { if (reqStk.stackSize != 0) return; + if(smallStack) + itr.set(usedStack); // set to the actual item used. } return; @@ -332,7 +342,7 @@ public class BptBuilderBlueprint extends BptBuilderBase { return 1; else if (o1.getItemDamage() < o2.getItemDamage()) return -1; - + return 0; } }); diff --git a/common/buildcraft/core/blueprints/BptSlot.java b/common/buildcraft/core/blueprints/BptSlot.java index 1aeecf59..c4b1d43d 100644 --- a/common/buildcraft/core/blueprints/BptSlot.java +++ b/common/buildcraft/core/blueprints/BptSlot.java @@ -50,8 +50,9 @@ public class BptSlot extends BptSlotInfo { BlueprintManager.blockBptProps[blockId].buildBlock(this, context); } - public void useItem(IBptContext context, ItemStack req, ItemStack stack) { - BlueprintManager.blockBptProps[blockId].useItem(this, context, req, stack); + // returns what was used + public ItemStack useItem(IBptContext context, ItemStack req, ItemStack stack) { + return BlueprintManager.blockBptProps[blockId].useItem(this, context, req, stack); } @SuppressWarnings("unchecked")