diff --git a/common/buildcraft/api/blueprints/BptBlock.java b/common/buildcraft/api/blueprints/BptBlock.java index f3e5d0f7..772e8239 100644 --- a/common/buildcraft/api/blueprints/BptBlock.java +++ b/common/buildcraft/api/blueprints/BptBlock.java @@ -8,6 +8,7 @@ */ package buildcraft.api.blueprints; +import java.util.ArrayList; import java.util.LinkedList; import net.minecraft.block.Block; @@ -69,7 +70,7 @@ public class BptBlock { if (slot.storedRequirements.size() != 0) { requirements.addAll(slot.storedRequirements); } else { - // requirements.add(new ItemStack(slot.blockId, 1, slot.meta)); + requirements.add(new ItemStack(slot.block, 1, slot.meta)); } } } @@ -130,8 +131,7 @@ public class BptBlock { * subprogram is permissive and doesn't take into account metadata. */ public boolean isValid(BptSlotInfo slot, IBptContext context) { - //return slot.blockId == context.world().getBlockId(slot.x, slot.y, slot.z) && slot.meta == context.world().getBlockMetadata(slot.x, slot.y, slot.z); - return false; + return slot.block == context.world().getBlock(slot.x, slot.y, slot.z) && slot.meta == context.world().getBlockMetadata(slot.x, slot.y, slot.z); } /** @@ -189,7 +189,7 @@ public class BptBlock { * save / load the block. */ public void initializeFromWorld(BptSlotInfo slot, IBptContext context, int x, int y, int z) { - /*if (Block.blocksList[slot.blockId] instanceof BlockContainer) { + if (slot.block instanceof BlockContainer) { TileEntity tile = context.world().getTileEntity(x, y, z); if (tile != null) { @@ -197,13 +197,14 @@ public class BptBlock { } } - if (Block.blocksList[slot.blockId] != null) { - ArrayList req = Block.blocksList[slot.blockId].getBlockDropped(context.world(), x, y, z, context.world().getBlockMetadata(x, y, z), 0); + if (slot.block != null) { + ArrayList req = slot.block.getDrops(context.world(), x, + y, z, context.world().getBlockMetadata(x, y, z), 0); if (req != null) { slot.storedRequirements.addAll(req); } - }*/ + } } /** diff --git a/common/buildcraft/api/bptblocks/BptBlockBed.java b/common/buildcraft/api/bptblocks/BptBlockBed.java index 743613c1..66118c9e 100644 --- a/common/buildcraft/api/bptblocks/BptBlockBed.java +++ b/common/buildcraft/api/bptblocks/BptBlockBed.java @@ -53,10 +53,11 @@ public class BptBlockBed extends BptBlock { @Override public void buildBlock(BptSlotInfo slot, IBptContext context) { - if ((slot.meta & 8) != 0) + if ((slot.meta & 8) != 0) { return; + } - //context.world().setBlock(slot.x, slot.y, slot.z, slot.block, slot.meta,1); + context.world().setBlock(slot.x, slot.y, slot.z, slot.block, slot.meta,1); int x2 = slot.x; int z2 = slot.z; @@ -76,7 +77,7 @@ public class BptBlockBed extends BptBlock { break; } - //context.world().setBlock(x2, slot.y, z2, slot.block, slot.meta + 8,1); + context.world().setBlock(x2, slot.y, z2, slot.block, slot.meta + 8,1); } @Override diff --git a/common/buildcraft/api/bptblocks/BptBlockDelegate.java b/common/buildcraft/api/bptblocks/BptBlockDelegate.java index 38b2bf35..7a297e95 100644 --- a/common/buildcraft/api/bptblocks/BptBlockDelegate.java +++ b/common/buildcraft/api/bptblocks/BptBlockDelegate.java @@ -12,6 +12,7 @@ import java.util.LinkedList; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; +import buildcraft.api.blueprints.BlueprintManager; import buildcraft.api.blueprints.BptBlock; import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; @@ -19,6 +20,7 @@ import buildcraft.api.blueprints.IBptContext; public class BptBlockDelegate extends BptBlock { final Block delegateTo; + BptBlock delegated; public BptBlockDelegate(Block block, Block delegateTo) { super(block); @@ -31,11 +33,7 @@ public class BptBlockDelegate extends BptBlock { BptSlotInfo newSlot = slot.clone(); slot.block = delegateTo; - //if (BlueprintManager.blockBptProps[delegateTo] != null) { - // BlueprintManager.blockBptProps[delegateTo].addRequirements(newSlot, context, requirements); - //} else { - // super.addRequirements(newSlot, context, requirements); - //} + getDelegated ().addRequirements(newSlot, context, requirements); } @Override @@ -43,12 +41,7 @@ public class BptBlockDelegate extends BptBlock { BptSlotInfo newSlot = slot.clone(); slot.block = delegateTo; - //if (BlueprintManager.blockBptProps[delegateTo] != null) - // return BlueprintManager.blockBptProps[delegateTo].isValid(newSlot, context); - //else - // return super.isValid(newSlot, context); - - return false; + return getDelegated ().isValid(newSlot, context); } @Override @@ -56,11 +49,15 @@ public class BptBlockDelegate extends BptBlock { BptSlotInfo newSlot = slot.clone(); slot.block = delegateTo; - //if (BlueprintManager.blockBptProps[delegateTo] != null) { - // BlueprintManager.blockBptProps[delegateTo].rotateLeft(newSlot, context); - //} else { - // super.rotateLeft(newSlot, context); - //} + getDelegated().rotateLeft(newSlot, context); + } + + private BptBlock getDelegated () { + if (delegated == null) { + delegated = BlueprintManager.getBptBlock(delegateTo); + } + + return delegated; } } diff --git a/common/buildcraft/api/bptblocks/BptBlockDirt.java b/common/buildcraft/api/bptblocks/BptBlockDirt.java index 99a7c335..4a35475a 100644 --- a/common/buildcraft/api/bptblocks/BptBlockDirt.java +++ b/common/buildcraft/api/bptblocks/BptBlockDirt.java @@ -11,6 +11,7 @@ package buildcraft.api.bptblocks; import java.util.LinkedList; import net.minecraft.block.Block; +import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import buildcraft.api.blueprints.BptBlock; import buildcraft.api.blueprints.BptSlotInfo; @@ -24,19 +25,18 @@ public class BptBlockDirt extends BptBlock { @Override public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - //requirements.add(new ItemStack(Block.dirt)); + requirements.add(new ItemStack(Blocks.dirt)); } @Override public void buildBlock(BptSlotInfo slot, IBptContext context) { - //context.world().setBlock(slot.x, slot.y, slot.z, Block.dirt.blockID, slot.meta,1); + context.world().setBlock(slot.x, slot.y, slot.z, Blocks.dirt, slot.meta,1); } @Override public boolean isValid(BptSlotInfo slot, IBptContext context) { - //int id = context.world().getBlockId(slot.x, slot.y, slot.z); + Block block = context.world().getBlock(slot.x, slot.y, slot.z); - //return id == Block.dirt.blockID || id == Block.grass.blockID || id == Block.tilledField.blockID; - return false; + return block == Blocks.dirt || block == Blocks.grass || block == Blocks.farmland; } } diff --git a/common/buildcraft/api/bptblocks/BptBlockDoor.java b/common/buildcraft/api/bptblocks/BptBlockDoor.java index c14f3021..59b54849 100644 --- a/common/buildcraft/api/bptblocks/BptBlockDoor.java +++ b/common/buildcraft/api/bptblocks/BptBlockDoor.java @@ -61,8 +61,8 @@ public class BptBlockDoor extends BptBlock { @Override public void buildBlock(BptSlotInfo slot, IBptContext context) { - //context.world().setBlock(slot.x, slot.y, slot.z, slot.blockId, slot.meta,1); - //context.world().setBlock(slot.x, slot.y + 1, slot.z, slot.blockId, slot.meta + 8,1); + context.world().setBlock(slot.x, slot.y, slot.z, slot.block, slot.meta,1); + context.world().setBlock(slot.x, slot.y + 1, slot.z, slot.block, slot.meta + 8,1); context.world().setBlockMetadataWithNotify(slot.x, slot.y + 1, slot.z, slot.meta + 8,1); context.world().setBlockMetadataWithNotify(slot.x, slot.y, slot.z, slot.meta,1); diff --git a/common/buildcraft/api/bptblocks/BptBlockFluid.java b/common/buildcraft/api/bptblocks/BptBlockFluid.java index ebcae1f3..fa96cb91 100644 --- a/common/buildcraft/api/bptblocks/BptBlockFluid.java +++ b/common/buildcraft/api/bptblocks/BptBlockFluid.java @@ -35,10 +35,11 @@ public class BptBlockFluid extends BptBlock { @Override public boolean isValid(BptSlotInfo slot, IBptContext context) { - //if (slot.meta == 0) - // return slot.blockId == context.world().getBlockId(slot.x, slot.y, slot.z) && context.world().getBlockMetadata(slot.x, slot.y, slot.z) == 0; - //else + if (slot.meta == 0) { + return slot.block == context.world().getBlock(slot.x, slot.y, slot.z) && context.world().getBlockMetadata(slot.x, slot.y, slot.z) == 0; + } else { return true; + } } @Override @@ -53,9 +54,9 @@ public class BptBlockFluid extends BptBlock { @Override public void buildBlock(BptSlotInfo slot, IBptContext context) { - //if (slot.meta == 0) { - // context.world().setBlock(slot.x, slot.y, slot.z, slot.blockId, 0,1); - //} + if (slot.meta == 0) { + context.world().setBlock(slot.x, slot.y, slot.z, slot.block, 0,1); + } } } diff --git a/common/buildcraft/api/bptblocks/BptBlockIgnore.java b/common/buildcraft/api/bptblocks/BptBlockIgnore.java index 0705472b..15939e12 100644 --- a/common/buildcraft/api/bptblocks/BptBlockIgnore.java +++ b/common/buildcraft/api/bptblocks/BptBlockIgnore.java @@ -24,7 +24,7 @@ public class BptBlockIgnore extends BptBlock { @Override public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - //requirements.add(new ItemStack(slot.blockId, 0, 0)); + requirements.add(new ItemStack(slot.block, 0, 0)); } @Override diff --git a/common/buildcraft/api/bptblocks/BptBlockIgnoreMeta.java b/common/buildcraft/api/bptblocks/BptBlockIgnoreMeta.java index 17c270b8..abe6c23e 100644 --- a/common/buildcraft/api/bptblocks/BptBlockIgnoreMeta.java +++ b/common/buildcraft/api/bptblocks/BptBlockIgnoreMeta.java @@ -24,12 +24,11 @@ public class BptBlockIgnoreMeta extends BptBlock { @Override public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - //requirements.add(new ItemStack(slot.blockId, 1, 0)); + requirements.add(new ItemStack(slot.block, 1, 0)); } @Override public boolean isValid(BptSlotInfo slot, IBptContext context) { - //return slot.blockId == context.world().getBlockId(slot.x, slot.y, slot.z); - return false; + return slot.block == context.world().getBlock(slot.x, slot.y, slot.z); } } diff --git a/common/buildcraft/api/bptblocks/BptBlockPumpkin.java b/common/buildcraft/api/bptblocks/BptBlockPumpkin.java index 0d8c9b84..f6897d6d 100644 --- a/common/buildcraft/api/bptblocks/BptBlockPumpkin.java +++ b/common/buildcraft/api/bptblocks/BptBlockPumpkin.java @@ -24,13 +24,12 @@ public class BptBlockPumpkin extends BptBlock { @Override public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - //requirements.add(new ItemStack(slot.blockId, 1, 0)); + requirements.add(new ItemStack(slot.block, 1, 0)); } @Override public boolean isValid(BptSlotInfo slot, IBptContext context) { - //return slot.blockId == context.world().getBlockId(slot.x, slot.y, slot.z); - return false; + return slot.block == context.world().getBlock(slot.x, slot.y, slot.z); } @Override diff --git a/common/buildcraft/api/bptblocks/BptBlockRedstoneRepeater.java b/common/buildcraft/api/bptblocks/BptBlockRedstoneRepeater.java index 4d5492b5..b055edcb 100644 --- a/common/buildcraft/api/bptblocks/BptBlockRedstoneRepeater.java +++ b/common/buildcraft/api/bptblocks/BptBlockRedstoneRepeater.java @@ -11,6 +11,7 @@ package buildcraft.api.bptblocks; import java.util.LinkedList; import net.minecraft.block.Block; +import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import buildcraft.api.blueprints.BptBlock; import buildcraft.api.blueprints.BptSlotInfo; @@ -24,7 +25,7 @@ public class BptBlockRedstoneRepeater extends BptBlock { @Override public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - //requirements.add(new ItemStack(Item.redstoneRepeater)); + requirements.add(new ItemStack(Items.repeater)); } @Override diff --git a/common/buildcraft/api/bptblocks/BptBlockRotateMeta.java b/common/buildcraft/api/bptblocks/BptBlockRotateMeta.java index 389d2ae5..61fd2b04 100644 --- a/common/buildcraft/api/bptblocks/BptBlockRotateMeta.java +++ b/common/buildcraft/api/bptblocks/BptBlockRotateMeta.java @@ -43,13 +43,12 @@ public class BptBlockRotateMeta extends BptBlock { @Override public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - //requirements.add(new ItemStack(slot.blockId, 1, 0)); + requirements.add(new ItemStack(slot.block, 1, 0)); } @Override public boolean isValid(BptSlotInfo slot, IBptContext context) { - //return slot.blockId == context.world().getBlockId(slot.x, slot.y, slot.z); - return false; + return slot.block == context.world().getBlock(slot.x, slot.y, slot.z); } @Override diff --git a/common/buildcraft/api/bptblocks/BptBlockSign.java b/common/buildcraft/api/bptblocks/BptBlockSign.java index 2b1f9c0c..e3b18510 100644 --- a/common/buildcraft/api/bptblocks/BptBlockSign.java +++ b/common/buildcraft/api/bptblocks/BptBlockSign.java @@ -11,7 +11,9 @@ package buildcraft.api.bptblocks; import java.util.LinkedList; import net.minecraft.block.Block; +import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; import buildcraft.api.blueprints.BptBlock; import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; @@ -28,7 +30,7 @@ public class BptBlockSign extends BptBlock { @Override public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - //requirements.add(new ItemStack(Item.sign)); + requirements.add(new ItemStack(Items.sign)); } @Override @@ -41,7 +43,7 @@ public class BptBlockSign extends BptBlock { } slot.meta = (int) (angle / 360.0 * 16.0); } else { - // slot.meta = ForgeDirection.values()[slot.meta].rotateLeft().ordinal(); + slot.meta = ForgeDirection.values()[slot.meta].getRotation(ForgeDirection.UP).ordinal(); } } } diff --git a/common/buildcraft/api/bptblocks/BptBlockStairs.java b/common/buildcraft/api/bptblocks/BptBlockStairs.java index a2f8d5c7..5d77d1fd 100644 --- a/common/buildcraft/api/bptblocks/BptBlockStairs.java +++ b/common/buildcraft/api/bptblocks/BptBlockStairs.java @@ -24,13 +24,12 @@ public class BptBlockStairs extends BptBlock { @Override public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - //requirements.add(new ItemStack(slot.blockId, 1, 0)); + requirements.add(new ItemStack(slot.block, 1, 0)); } @Override public boolean isValid(BptSlotInfo slot, IBptContext context) { - //return slot.blockId == context.world().getBlockId(slot.x, slot.y, slot.z); - return false; + return slot.block == context.world().getBlock(slot.x, slot.y, slot.z); } @Override diff --git a/common/buildcraft/api/bptblocks/BptBlockWallSide.java b/common/buildcraft/api/bptblocks/BptBlockWallSide.java index 03a1a964..9e0beae0 100644 --- a/common/buildcraft/api/bptblocks/BptBlockWallSide.java +++ b/common/buildcraft/api/bptblocks/BptBlockWallSide.java @@ -24,7 +24,7 @@ public class BptBlockWallSide extends BptBlock { @Override public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - //requirements.add(new ItemStack(slot.blockId, 1, 0)); + requirements.add(new ItemStack(slot.block, 1, 0)); } @Override diff --git a/common/buildcraft/api/core/StackWrapper.java b/common/buildcraft/api/core/StackKey.java similarity index 60% rename from common/buildcraft/api/core/StackWrapper.java rename to common/buildcraft/api/core/StackKey.java index a155c1cd..113cab3d 100644 --- a/common/buildcraft/api/core/StackWrapper.java +++ b/common/buildcraft/api/core/StackKey.java @@ -8,45 +8,51 @@ */ package buildcraft.api.core; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -public class StackWrapper { +/** + * This class is used whenever stacks needs to be stored as keys. + */ +public class StackKey { public final ItemStack stack; - public StackWrapper(ItemStack stack) { + public StackKey(ItemStack stack) { this.stack = stack; } @Override public int hashCode() { int hash = 5; - + hash = 67 * hash + stack.getItem().hashCode(); - hash = 67 * hash + stack.getItemDamage(); - + if (stack.stackTagCompound != null) { hash = 67 * hash + stack.stackTagCompound.hashCode(); } - + return hash; } @Override public boolean equals(Object obj) { - if (obj == null) + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } else if (getClass() != obj.getClass()) { return false; - final StackWrapper other = (StackWrapper) obj; - if (stack.getItem() != other.stack.getItem()) + } + + final StackKey other = (StackKey) obj; + + if (stack.getItem() != other.stack.getItem()) { return false; - if (stack.getHasSubtypes() && stack.getItemDamage() != other.stack.getItemDamage()) + } else if (stack.getHasSubtypes() && stack.getItemDamage() != other.stack.getItemDamage()) { return false; - if (stack.stackTagCompound != null && !stack.stackTagCompound.equals(other.stack.stackTagCompound)) + } else if (stack.stackTagCompound != null && !stack.stackTagCompound.equals(other.stack.stackTagCompound)) { return false; - return true; + } else { + return true; + } } } diff --git a/common/buildcraft/api/fuels/IronEngineCoolant.java b/common/buildcraft/api/fuels/IronEngineCoolant.java index 3e1de954..37682bf2 100644 --- a/common/buildcraft/api/fuels/IronEngineCoolant.java +++ b/common/buildcraft/api/fuels/IronEngineCoolant.java @@ -8,7 +8,7 @@ */ package buildcraft.api.fuels; -import buildcraft.api.core.StackWrapper; +import buildcraft.api.core.StackKey; import java.util.HashMap; import java.util.Map; @@ -22,10 +22,10 @@ import net.minecraftforge.fluids.FluidStack; public final class IronEngineCoolant { public static Map liquidCoolants = new HashMap(); - public static Map solidCoolants = new HashMap(); + public static Map solidCoolants = new HashMap(); public static FluidStack getFluidCoolant(ItemStack stack) { - return solidCoolants.get(new StackWrapper(stack)); + return solidCoolants.get(new StackKey(stack)); } public static Coolant getCoolant(ItemStack stack) { @@ -65,7 +65,7 @@ public final class IronEngineCoolant { */ public static void addCoolant(final ItemStack stack, final FluidStack coolant) { if (stack != null && stack.getItem() != null && coolant != null) { - solidCoolants.put(new StackWrapper(stack), coolant); + solidCoolants.put(new StackKey(stack), coolant); } } diff --git a/common/buildcraft/builders/TileBuilder.java b/common/buildcraft/builders/TileBuilder.java index ea493219..cbe4ce63 100644 --- a/common/buildcraft/builders/TileBuilder.java +++ b/common/buildcraft/builders/TileBuilder.java @@ -278,7 +278,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, result = null; } - debugForceBlueprintCompletion(result, context); + //debugForceBlueprintCompletion(result, context); return result; } @@ -636,4 +636,12 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, slot.buildBlock(context); } } + + public BptBuilderBase getBlueprint () { + if (bluePrintBuilder != null) { + return bluePrintBuilder; + } else { + return null; + } + } } \ No newline at end of file diff --git a/common/buildcraft/builders/gui/GuiBuilder.java b/common/buildcraft/builders/gui/GuiBuilder.java index 7274e6fc..f9ca432f 100644 --- a/common/buildcraft/builders/gui/GuiBuilder.java +++ b/common/buildcraft/builders/gui/GuiBuilder.java @@ -8,7 +8,10 @@ */ package buildcraft.builders.gui; +import java.util.Collection; + import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; @@ -76,23 +79,20 @@ public class GuiBuilder extends GuiAdvancedInterface { ((ItemSlot) slots[s]).stack = null; } - /*Blueprint blueprint = builder.getBlueprint(); - if(blueprint != null){ - Collection needs = blueprint.getCost(); + Collection needs = builder.getNeededItems(); - if (needs != null) { - int s = 0; + if (needs != null) { + int s = 0; - for (ItemStack stack : needs) { - if (s >= slots.length) { - break; - } - - ((ItemSlot) slots[s]).stack = stack.copy(); - s++; + for (ItemStack stack : needs) { + if (s >= slots.length) { + break; } + + ((ItemSlot) slots[s]).stack = stack.copy(); + s++; } - }*/ + } drawBackgroundSlots(); } diff --git a/common/buildcraft/core/blueprints/BptBuilderBlueprint.java b/common/buildcraft/core/blueprints/BptBuilderBlueprint.java index 2ad1f2f5..95b9c030 100644 --- a/common/buildcraft/core/blueprints/BptBuilderBlueprint.java +++ b/common/buildcraft/core/blueprints/BptBuilderBlueprint.java @@ -8,14 +8,17 @@ */ package buildcraft.core.blueprints; +import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.LinkedList; import java.util.ListIterator; -import java.util.TreeSet; +import java.util.Map.Entry; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraft.world.WorldSettings.GameType; +import buildcraft.api.core.StackKey; import buildcraft.core.IBuilderInventory; import buildcraft.core.blueprints.BptSlot.Mode; import buildcraft.core.utils.BCLog; @@ -29,26 +32,7 @@ public class BptBuilderBlueprint extends BptBuilderBase { LinkedList postProcessingList = new LinkedList(); - public TreeSet neededItems = new TreeSet(new Comparator() { - - @Override - public int compare(ItemStack o1, ItemStack o2) { - if (o1.stackSize > o2.stackSize) - return -1; - else if (o1.stackSize < o2.stackSize) - return 1; - //else if (o1.itemID > o2.itemID) - // return -1; - //else if (o1.itemID < o2.itemID) - // return 1; - else if (o1.getItemDamage() > o2.getItemDamage()) - return -1; - else if (o1.getItemDamage() < o2.getItemDamage()) - return 1; - - return 0; - } - }); + public LinkedList neededItems = new LinkedList (); public BptBuilderBlueprint(Blueprint bluePrint, World world, int x, int y, int z) { super(bluePrint, world, x, y, z); @@ -343,22 +327,7 @@ public class BptBuilderBlueprint extends BptBuilderBase { public void recomputeNeededItems() { neededItems.clear(); - /*TreeMap computeStacks = new TreeMap(new Comparator() { - - @Override - public int compare(ItemStack o1, ItemStack o2) { - if (o1.itemID > o2.itemID) - return 1; - else if (o1.itemID < o2.itemID) - return -1; - else if (o1.getItemDamage() > o2.getItemDamage()) - return 1; - else if (o1.getItemDamage() < o2.getItemDamage()) - return -1; - - return 0; - } - });*/ + HashMap computeStacks = new HashMap (); for (BptSlot slot : primaryList) { @@ -372,50 +341,70 @@ public class BptBuilderBlueprint extends BptBuilderBase { BCLog.logger.throwing("BptBuilderBlueprint", "recomputeIfNeeded", t); } - /*for (ItemStack stack : stacks) { - if (stack == null || stack.itemID == 0) { + for (ItemStack stack : stacks) { + if (stack == null || stack.getItem() == null || stack.stackSize == 0) { continue; } - if (!computeStacks.containsKey(stack)) { - computeStacks.put(stack.copy(), stack.stackSize); + StackKey key = new StackKey(stack); + + if (!computeStacks.containsKey(key)) { + computeStacks.put(key, stack.stackSize); } else { - Integer num = computeStacks.get(stack); + Integer num = computeStacks.get(key); num += stack.stackSize; - computeStacks.put(stack, num); + computeStacks.put(key, num); } - }*/ + } } for (BptSlot slot : secondaryList) { LinkedList stacks = slot.getRequirements(context); - /*for (ItemStack stack : stacks) { - if (stack == null || stack.itemID <= 0 || stack.itemID >= Item.itemsList.length || stack.stackSize == 0 || stack.getItem() == null) { + for (ItemStack stack : stacks) { + if (stack == null || stack.getItem() == null || stack.stackSize == 0) { continue; } - if (!computeStacks.containsKey(stack)) { - computeStacks.put(stack.copy(), stack.stackSize); + StackKey key = new StackKey(stack); + + if (!computeStacks.containsKey(key)) { + computeStacks.put(key, stack.stackSize); } else { - Integer num = computeStacks.get(stack); + Integer num = computeStacks.get(key); num += stack.stackSize; - computeStacks.put(stack, num); + computeStacks.put(key, num); } - }*/ + } } - /*for (ItemStack stack : computeStacks.keySet()) - if (stack.isItemStackDamageable()) { - neededItems.add(new ItemStack(stack.getItem())); - } else { - neededItems.add(new ItemStack(stack.itemID, computeStacks.get(stack), stack.getItemDamage())); + for (Entry e : computeStacks.entrySet()) { + ItemStack newStack = e.getKey().stack.copy(); + newStack.stackSize = e.getValue(); + neededItems.add(newStack); + } + + Collections.sort (neededItems, new Comparator() { + @Override + public int compare(ItemStack o1, ItemStack o2) { + if (o1.stackSize > o2.stackSize) { + return -1; + } else if (o1.stackSize < o2.stackSize) { + return 1; + } else if (o1.getItemDamage() > o2.getItemDamage()) { + return -1; + } else if (o1.getItemDamage() < o2.getItemDamage()) { + return 1; + } else { + return 0; + } } - */ + }); + } @Override diff --git a/common/buildcraft/energy/BptBlockEngine.java b/common/buildcraft/energy/BptBlockEngine.java index 8152c496..b280c1ff 100644 --- a/common/buildcraft/energy/BptBlockEngine.java +++ b/common/buildcraft/energy/BptBlockEngine.java @@ -38,7 +38,7 @@ public class BptBlockEngine extends BptBlock { @Override public void buildBlock(BptSlotInfo slot, IBptContext context) { - //context.world().setBlock(slot.x, slot.y, slot.z, slot.blockId, slot.meta,1); + context.world().setBlock(slot.x, slot.y, slot.z, slot.block, slot.meta,1); TileEngine engine = (TileEngine) context.world().getTileEntity(slot.x, slot.y, slot.z); diff --git a/common/buildcraft/factory/BptBlockTank.java b/common/buildcraft/factory/BptBlockTank.java index bc81c9a5..b1ea0acd 100644 --- a/common/buildcraft/factory/BptBlockTank.java +++ b/common/buildcraft/factory/BptBlockTank.java @@ -26,7 +26,7 @@ public class BptBlockTank extends BptBlock { @Override public void buildBlock(BptSlotInfo slot, IBptContext context) { - //context.world().setBlock(slot.x, slot.y, slot.z, slot.blockId, slot.meta,1); + context.world().setBlock(slot.x, slot.y, slot.z, slot.block, slot.meta,1); } } diff --git a/common/buildcraft/transport/BlockGenericPipe.java b/common/buildcraft/transport/BlockGenericPipe.java index 5fd97516..d6f65678 100644 --- a/common/buildcraft/transport/BlockGenericPipe.java +++ b/common/buildcraft/transport/BlockGenericPipe.java @@ -1076,8 +1076,9 @@ public class BlockGenericPipe extends BlockBuildCraft { } public static boolean placePipe(Pipe pipe, World world, int i, int j, int k, Block block, int meta) { - if (world.isRemote) + if (world.isRemote) { return true; + } boolean placed = world.setBlock(i, j, k, block, meta, 3); @@ -1091,13 +1092,13 @@ public class BlockGenericPipe extends BlockBuildCraft { } public static Pipe getPipe(IBlockAccess blockAccess, int i, int j, int k) { - TileEntity tile = blockAccess.getTileEntity(i, j, k); - if (!(tile instanceof TileGenericPipe) || tile.isInvalid()) + if (!(tile instanceof TileGenericPipe) || tile.isInvalid()) { return null; - - return ((TileGenericPipe) tile).pipe; + } else { + return ((TileGenericPipe) tile).pipe; + } } public static boolean isFullyDefined(Pipe pipe) { diff --git a/common/buildcraft/transport/PipeTransportItems.java b/common/buildcraft/transport/PipeTransportItems.java index 81415b9e..70e716c9 100644 --- a/common/buildcraft/transport/PipeTransportItems.java +++ b/common/buildcraft/transport/PipeTransportItems.java @@ -252,8 +252,9 @@ public class PipeTransportItems extends PipeTransport { private void moveSolids() { items.flush(); - if (!container.getWorldObj().isRemote) + if (!container.getWorldObj().isRemote) { items.purgeCorruptedItems(); + } items.iterating = true; for (TravelingItem item : items) { diff --git a/common/buildcraft/transport/blueprints/BptBlockPipe.java b/common/buildcraft/transport/blueprints/BptBlockPipe.java index 41a59581..2b2f202a 100644 --- a/common/buildcraft/transport/blueprints/BptBlockPipe.java +++ b/common/buildcraft/transport/blueprints/BptBlockPipe.java @@ -11,6 +11,7 @@ package buildcraft.transport.blueprints; import java.util.LinkedList; import net.minecraft.block.Block; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import buildcraft.api.blueprints.BptBlock; import buildcraft.api.blueprints.BptSlotInfo; @@ -28,113 +29,115 @@ public class BptBlockPipe extends BptBlock { public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { int pipeId = slot.cpt.getInteger("pipeId"); - //requirements.add(new ItemStack(pipeId, 1, 0)); + requirements.add(new ItemStack((Item) Item.itemRegistry.getObjectById(pipeId))); -// if (slot.cpt.hasKey("wire0")) { -// requirements.add(new ItemStack(BuildCraftTransport.pipeWire)); -// } -// -// if (slot.cpt.hasKey("wire1")) { -// requirements.add(new ItemStack(BuildCraftTransport.bluePipeWire)); -// } -// -// if (slot.cpt.hasKey("wire2")) { -// requirements.add(new ItemStack(BuildCraftTransport.greenPipeWire)); -// } -// -// if (slot.cpt.hasKey("wire3")) { -// requirements.add(new ItemStack(BuildCraftTransport.yellowPipeWire)); -// } + /*if (slot.cpt.hasKey("wire0")) { + requirements.add(new ItemStack(BuildCraftTransport.pipeWire, 1, 0)); + } -// if (slot.cpt.hasKey("gate")) { -// int gateId = slot.cpt.getInteger("gate"); -// if (slot.cpt.hasKey("hasPulser") && slot.cpt.getBoolean("hasPulser")) { -// requirements.add(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, gateId - 1)); -// } else { -// requirements.add(new ItemStack(BuildCraftTransport.pipeGate, 1, gateId - 1)); -// } -// } + if (slot.cpt.hasKey("wire1")) { + requirements.add(new ItemStack(BuildCraftTransport.pipeWire, 1, 1)); + } - //if (BuildCraftCore.itemBptProps[pipeId] != null) { - // BuildCraftCore.itemBptProps[pipeId].addRequirements(slot, requirements); - //} + if (slot.cpt.hasKey("wire2")) { + requirements.add(new ItemStack(BuildCraftTransport.pipeWire, 1, 2)); + } + + if (slot.cpt.hasKey("wire3")) { + requirements.add(new ItemStack(BuildCraftTransport.pipeWire, 1, 3)); + } + + if (slot.cpt.hasKey("gate")) { + int gateId = slot.cpt.getInteger("gate"); + if (slot.cpt.hasKey("hasPulser") && slot.cpt.getBoolean("hasPulser")) { + requirements.add(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, gateId - 1)); + } else { + requirements.add(new ItemStack(BuildCraftTransport.pipeGate, 1, gateId - 1)); + } + } + + if (BuildCraftCore.itemBptProps[pipeId] != null) { + BuildCraftCore.itemBptProps[pipeId].addRequirements(slot, requirements); + }*/ } @Override public boolean isValid(BptSlotInfo slot, IBptContext context) { Pipe pipe = BlockGenericPipe.getPipe(context.world(), slot.x, slot.y, slot.z); - //if (BlockGenericPipe.isValid(pipe)) - // return pipe.itemID == slot.cpt.getInteger("pipeId"); - //else - // return false; - - return false; + if (BlockGenericPipe.isValid(pipe)) { + return pipe.item == Item.itemRegistry.getObjectById(slot.cpt + .getInteger("pipeId")); + } else { + return false; + } } @Override public void rotateLeft(BptSlotInfo slot, IBptContext context) { int pipeId = slot.cpt.getInteger("pipeId"); - //if (BuildCraftCore.itemBptProps[pipeId] != null) { - // BuildCraftCore.itemBptProps[pipeId].rotateLeft(slot, context); - //} + /*if (BuildCraftCore.itemBptProps[pipeId] != null) { + BuildCraftCore.itemBptProps[pipeId].rotateLeft(slot, context); + }*/ } @Override public void buildBlock(BptSlotInfo slot, IBptContext context) { int pipeId = slot.cpt.getInteger("pipeId"); - //Pipe pipe = BlockGenericPipe.createPipe(pipeId); + Pipe pipe = BlockGenericPipe.createPipe((Item) Item.itemRegistry + .getObjectById(pipeId)); - //for (int i = 0; i < pipe.wireSet.length; ++i) - // if (slot.cpt.hasKey("wire" + i)) { - // pipe.wireSet[i] = true; - // } + for (int i = 0; i < pipe.wireSet.length; ++i) { + if (slot.cpt.hasKey("wire" + i)) { + pipe.wireSet[i] = true; + } + } -// if (slot.cpt.hasKey("gate")) { -// // / TODO: Does not save/load custom gates -// int gateId = slot.cpt.getInteger("gate"); -// GateVanilla newGate; -// if (slot.cpt.hasKey("hasPulser") && slot.cpt.getBoolean("hasPulser")) { -// newGate = new GateVanilla(pipe, new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, gateId - 1)); -// } else { -// newGate = new GateVanilla(pipe, new ItemStack(BuildCraftTransport.pipeGate, 1, gateId - 1)); -// } -// pipe.gate = newGate; -// -// for (int i = 0; i < 8; ++i) { -// if (slot.cpt.hasKey("trigger" + i)) { -//// pipe.gate.actions[i] = ActionManager.triggers[slot.cpt.getInteger("trigger" + i)]; -// } -// -// if (slot.cpt.hasKey("triggerParameter" + i)) { -// ItemStack s = ItemStack.loadItemStackFromNBT((NBTTagCompound) slot.cpt.getTag("triggerParameter" + i)); -// -// if (s != null) { -//// pipe.triggerParameters[i] = new TriggerParameter(); -//// pipe.triggerParameters[i].set(s); -// } -// } -// -// if (slot.cpt.hasKey("action" + i)) { -//// pipe.activatedActions[i] = ActionManager.actions[slot.cpt.getInteger("action" + i)]; -// } -// } -// } + /*if (slot.cpt.hasKey("gate")) { + int gateId = slot.cpt.getInteger("gate"); + GateVanilla newGate; + if (slot.cpt.hasKey("hasPulser") && slot.cpt.getBoolean("hasPulser")) { + newGate = new GateVanilla(pipe, new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, gateId - 1)); + } else { + newGate = new GateVanilla(pipe, new ItemStack(BuildCraftTransport.pipeGate, 1, gateId - 1)); + } + pipe.gate = newGate; - //BlockGenericPipe.placePipe(pipe, context.world(), slot.x, slot.y, slot.z, slot.blockId, slot.meta); + for (int i = 0; i < 8; ++i) { + if (slot.cpt.hasKey("trigger" + i)) { + pipe.gate.actions[i] = ActionManager.triggers[slot.cpt.getInteger("trigger" + i)]; + } - //if (BuildCraftCore.itemBptProps[pipeId] != null) { - // BuildCraftCore.itemBptProps[pipeId].buildBlock(slot, context); - //} + if (slot.cpt.hasKey("triggerParameter" + i)) { + ItemStack s = ItemStack.loadItemStackFromNBT((NBTTagCompound) slot.cpt.getTag("triggerParameter" + i)); + + if (s != null) { + pipe.triggerParameters[i] = new TriggerParameter(); + pipe.triggerParameters[i].set(s); + } + } + + if (slot.cpt.hasKey("action" + i)) { + pipe.activatedActions[i] = ActionManager.actions[slot.cpt.getInteger("action" + i)]; + } + } + }*/ + + BlockGenericPipe.placePipe(pipe, context.world(), slot.x, slot.y, + slot.z, slot.block, slot.meta); + + /*if (BuildCraftCore.itemBptProps[pipeId] != null) { + BuildCraftCore.itemBptProps[pipeId].buildBlock(slot, context); + }*/ } @Override public void initializeFromWorld(BptSlotInfo bptSlot, IBptContext context, int x, int y, int z) { Pipe pipe = BlockGenericPipe.getPipe(context.world(), x, y, z); - if (BlockGenericPipe.isValid(pipe)) { + /*if (BlockGenericPipe.isValid(pipe)) { //bptSlot.cpt.setInteger("pipeId", pipe.itemID); for (int i = 0; i < pipe.wireSet.length; ++i) @@ -143,34 +146,34 @@ public class BptBlockPipe extends BptBlock { } // / TODO: Does not save/load custom gates -// if (pipe.hasGate()) { -// bptSlot.cpt.setInteger("gate", pipe.gate.kind.ordinal()); -// if (pipe.gate instanceof GateVanilla) { -// bptSlot.cpt.setBoolean("hasPulser", ((GateVanilla) pipe.gate).hasPulser()); -// } -// -// for (int i = 0; i < 8; ++i) { -//// if (pipe.activatedTriggers[i] != null) { -//// bptSlot.cpt.setInteger("trigger" + i, pipe.activatedTriggers[i].getId()); -//// } -//// -//// if (pipe.triggerParameters[i] != null) { -//// NBTTagCompound subCpt = new NBTTagCompound(); -//// pipe.triggerParameters[i].getItemStack().writeToNBT(subCpt); -//// -//// bptSlot.cpt.setTag("triggerParameter" + i, subCpt); -//// } -//// -//// if (pipe.activatedActions[i] != null) { -//// bptSlot.cpt.setInteger("action" + i, pipe.activatedActions[i].getId()); -//// } -// } -// } + if (pipe.hasGate()) { + bptSlot.cpt.setInteger("gate", pipe.gate.kind.ordinal()); + if (pipe.gate instanceof GateVanilla) { + bptSlot.cpt.setBoolean("hasPulser", ((GateVanilla) pipe.gate).hasPulser()); + } - //if (BuildCraftCore.itemBptProps[pipe.itemID] != null) { - // BuildCraftCore.itemBptProps[pipe.itemID].initializeFromWorld(bptSlot, context, x, y, z); - //} - } + for (int i = 0; i < 8; ++i) { + if (pipe.activatedTriggers[i] != null) { + bptSlot.cpt.setInteger("trigger" + i, pipe.activatedTriggers[i].getId()); + } + + if (pipe.triggerParameters[i] != null) { + NBTTagCompound subCpt = new NBTTagCompound(); + pipe.triggerParameters[i].getItemStack().writeToNBT(subCpt); + + bptSlot.cpt.setTag("triggerParameter" + i, subCpt); + } + + if (pipe.activatedActions[i] != null) { + bptSlot.cpt.setInteger("action" + i, pipe.activatedActions[i].getId()); + } + } + } + + if (BuildCraftCore.itemBptProps[pipe.itemID] != null) { + BuildCraftCore.itemBptProps[pipe.itemID].initializeFromWorld(bptSlot, context, x, y, z); + } + }*/ } @Override