From 26572907bc69919c114158b27bc9040d1576fed5 Mon Sep 17 00:00:00 2001 From: Taelnia Date: Sat, 16 Nov 2013 20:19:54 -0500 Subject: [PATCH 1/8] Changes to AssemblyRecipe to support OreDict - Moved AssemblyRecipes to Init phase in BuildCraftTransport so that the OreDictionary is completed by then - Added new AssemblyRecipe constructor that can take ore tag strings paired with a desired stack size - Changed pipe wires over to new constructor --- common/buildcraft/BuildCraftTransport.java | 22 +++--- .../api/recipes/AssemblyRecipe.java | 77 +++++++++++++++++-- 2 files changed, 83 insertions(+), 16 deletions(-) diff --git a/common/buildcraft/BuildCraftTransport.java b/common/buildcraft/BuildCraftTransport.java index 309cd3fe..94b33b1a 100644 --- a/common/buildcraft/BuildCraftTransport.java +++ b/common/buildcraft/BuildCraftTransport.java @@ -313,32 +313,24 @@ public class BuildCraftTransport { redPipeWire.setUnlocalizedName("redPipeWire"); LanguageRegistry.addName(redPipeWire, "Red Pipe Wire"); CoreProxy.proxy.registerItem(redPipeWire); - AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[]{new ItemStack(Item.dyePowder, 1, 1), new ItemStack(Item.redstone, 1), - new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(redPipeWire, 8))); Property bluePipeWireId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "bluePipeWire.id", DefaultProps.BLUE_PIPE_WIRE); bluePipeWire = new ItemBuildCraft(bluePipeWireId.getInt()).setPassSneakClick(true); bluePipeWire.setUnlocalizedName("bluePipeWire"); LanguageRegistry.addName(bluePipeWire, "Blue Pipe Wire"); CoreProxy.proxy.registerItem(bluePipeWire); - AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[]{new ItemStack(Item.dyePowder, 1, 4), new ItemStack(Item.redstone, 1), - new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(bluePipeWire, 8))); Property greenPipeWireId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "greenPipeWire.id", DefaultProps.GREEN_PIPE_WIRE); greenPipeWire = new ItemBuildCraft(greenPipeWireId.getInt()).setPassSneakClick(true); greenPipeWire.setUnlocalizedName("greenPipeWire"); LanguageRegistry.addName(greenPipeWire, "Green Pipe Wire"); CoreProxy.proxy.registerItem(greenPipeWire); - AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[]{new ItemStack(Item.dyePowder, 1, 2), new ItemStack(Item.redstone, 1), - new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(greenPipeWire, 8))); Property yellowPipeWireId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "yellowPipeWire.id", DefaultProps.YELLOW_PIPE_WIRE); yellowPipeWire = new ItemBuildCraft(yellowPipeWireId.getInt()).setPassSneakClick(true); yellowPipeWire.setUnlocalizedName("yellowPipeWire"); LanguageRegistry.addName(yellowPipeWire, "Yellow Pipe Wire"); CoreProxy.proxy.registerItem(yellowPipeWire); - AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[]{new ItemStack(Item.dyePowder, 1, 11), new ItemStack(Item.redstone, 1), - new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(yellowPipeWire, 8))); Property pipeGateId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "pipeGate.id", DefaultProps.GATE_ID); pipeGate = new ItemGate(pipeGateId.getInt(), 0); @@ -365,9 +357,6 @@ public class BuildCraftTransport { filteredBufferBlock = new BlockFilteredBuffer(filteredBufferId.getInt()); CoreProxy.proxy.registerBlock(filteredBufferBlock.setUnlocalizedName("filteredBufferBlock")); CoreProxy.proxy.addName(filteredBufferBlock, "Filtered Buffer"); - - AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[]{new ItemStack(pipeStructureCobblestone)}, 1000, new ItemStack(plugItem, 8))); - } finally { BuildCraftCore.mainConfiguration.save(); } @@ -449,6 +438,17 @@ public class BuildCraftTransport { //Facade turning helper GameRegistry.addRecipe(facadeItem.new FacadeRecipe()); + + // Assembly table recipes, moved from PreInit phase to Init, all mods should be done adding to the OreDictionary by now + AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new Object[]{"dyeRed", 1, new ItemStack(Item.redstone, 1), + new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(redPipeWire, 8))); + AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new Object[]{"dyeBlue", 1, new ItemStack(Item.redstone, 1), + new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(bluePipeWire, 8))); + AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new Object[]{"dyeGreen", 1, new ItemStack(Item.redstone, 1), + new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(greenPipeWire, 8))); + AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new Object[]{"dyeYellow", 1, new ItemStack(Item.redstone, 1), + new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(yellowPipeWire, 8))); + AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[]{new ItemStack(pipeStructureCobblestone)}, 1000, new ItemStack(plugItem, 8))); } @EventHandler diff --git a/common/buildcraft/api/recipes/AssemblyRecipe.java b/common/buildcraft/api/recipes/AssemblyRecipe.java index 573db282..b3abbdbc 100644 --- a/common/buildcraft/api/recipes/AssemblyRecipe.java +++ b/common/buildcraft/api/recipes/AssemblyRecipe.java @@ -1,7 +1,9 @@ package buildcraft.api.recipes; +import java.util.ArrayList; import java.util.LinkedList; import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; public class AssemblyRecipe { @@ -11,34 +13,99 @@ public class AssemblyRecipe { public final ItemStack output; public final float energy; + public final Object[] inputOreDict; + public AssemblyRecipe(ItemStack[] input, int energy, ItemStack output) { this.input = input; this.output = output; this.energy = energy; + this.inputOreDict = input; + } + + /** This version of AssemblyRecipe supports the OreDictionary + * + * @param input Object[] containing either an ItemStack, or a paired string and integer(ex: "dyeBlue", 1) + * @param energy MJ cost to produce + * @param output resulting ItemStack + */ + public AssemblyRecipe(Object[] input, int energy, ItemStack output) { + this.output = output; + this.energy = energy; + + this.inputOreDict = new Object[input.length]; + + int count = 0; + for (int idx = 0; idx < input.length; idx++) { + if (input[idx] == null) { + continue; + } + + ItemStack in; + + if (input[idx] instanceof ItemStack) { + inputOreDict[idx] = input[idx]; + count++; + } else if (input[idx] instanceof String) { + ArrayList oreListWithStackSize = new ArrayList(); + + for (ItemStack oreItem : OreDictionary.getOres((String)input[idx])) { + ItemStack sizeAdjustedOreItem = oreItem.copy(); + + //Desired recipe stacksize is on next index + sizeAdjustedOreItem.stackSize = (int)input[idx + 1]; + + oreListWithStackSize.add(sizeAdjustedOreItem); + } + + inputOreDict[idx++] = oreListWithStackSize; + count++; + } + } + + // create the recipe item array + this.input = new ItemStack[count]; + count = 0; + for(Object recipeItem : inputOreDict) { + if (recipeItem == null) { + continue; + } + + // since the API recipe item array is an ItemStack, just grab the first item from the OreDict list + this.input[count++] = recipeItem instanceof ItemStack ? (ItemStack)recipeItem: ((ArrayList)recipeItem).get(0); + } } public boolean canBeDone(ItemStack[] items) { - for (ItemStack in : input) { + for (Object in : inputOreDict) { if (in == null) { continue; } int found = 0; // Amount of ingredient found in inventory + int expected = in instanceof ItemStack ? ((ItemStack)in).stackSize: in instanceof ArrayList ? ((ArrayList)in).get(0).stackSize: 1; for (ItemStack item : items) { if (item == null) { continue; } - if (item.isItemEqual(in)) { - found += item.stackSize; // Adds quantity of stack to amount - // found + if (in instanceof ItemStack) { + if (item.isItemEqual((ItemStack)in)) { + found += item.stackSize; // Adds quantity of stack to amount found + } + } else if (in instanceof ArrayList) { + for (ItemStack oreItem : (ArrayList)in) { + if(OreDictionary.itemMatches(oreItem, item, true)) { + found += item.stackSize; + break; + } + } } } - if (found < in.stackSize) + if (found < expected) return false; // Return false if the amount of ingredient found // is not enough } From f1bec62b90e4fc27ac2a1de97f51a74dbed50cb9 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Tue, 19 Nov 2013 05:26:30 -0800 Subject: [PATCH 2/8] Rewrite previous Assembly Table commit Yeah...there were better ways to do that... --- common/buildcraft/BuildCraftTransport.java | 20 ++- .../api/recipes/AssemblyRecipe.java | 119 +++++++----------- .../buildcraft/silicon/TileAssemblyTable.java | 57 ++++----- 3 files changed, 83 insertions(+), 113 deletions(-) diff --git a/common/buildcraft/BuildCraftTransport.java b/common/buildcraft/BuildCraftTransport.java index 94b33b1a..1976130b 100644 --- a/common/buildcraft/BuildCraftTransport.java +++ b/common/buildcraft/BuildCraftTransport.java @@ -266,7 +266,7 @@ public class BuildCraftTransport { pipeWaterproof.setUnlocalizedName("pipeWaterproof"); LanguageRegistry.addName(pipeWaterproof, "Pipe Sealant"); CoreProxy.proxy.registerItem(pipeWaterproof); - + genericPipeBlock = new BlockGenericPipe(genericPipeId.getInt()); CoreProxy.proxy.registerBlock(genericPipeBlock.setUnlocalizedName("pipeBlock"), ItemBlock.class); @@ -411,7 +411,7 @@ public class BuildCraftTransport { for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { actionPipeDirection[direction.ordinal()] = new ActionPipeDirection(-1, direction); } - + for (PowerMode limit : PowerMode.VALUES) { actionPowerLimiter[limit.ordinal()] = new ActionPowerLimiter(-1, limit); } @@ -425,7 +425,7 @@ public class BuildCraftTransport { // Add pipe recipes for (PipeRecipe pipe : pipeRecipes) { if (pipe.isShapeless) { - CoreProxy.proxy.addShapelessRecipe(pipe.result, pipe.input); + CoreProxy.proxy.addShapelessRecipe(pipe.result, pipe.input); } else { CoreProxy.proxy.addCraftingRecipe(pipe.result, pipe.input); } @@ -440,20 +440,16 @@ public class BuildCraftTransport { GameRegistry.addRecipe(facadeItem.new FacadeRecipe()); // Assembly table recipes, moved from PreInit phase to Init, all mods should be done adding to the OreDictionary by now - AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new Object[]{"dyeRed", 1, new ItemStack(Item.redstone, 1), - new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(redPipeWire, 8))); - AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new Object[]{"dyeBlue", 1, new ItemStack(Item.redstone, 1), - new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(bluePipeWire, 8))); - AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new Object[]{"dyeGreen", 1, new ItemStack(Item.redstone, 1), - new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(greenPipeWire, 8))); - AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new Object[]{"dyeYellow", 1, new ItemStack(Item.redstone, 1), - new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(yellowPipeWire, 8))); + AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(500, new ItemStack(redPipeWire, 8), "dyeRed", 1, new ItemStack(Item.redstone), new ItemStack(Item.ingotIron))); + AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(500, new ItemStack(bluePipeWire, 8), "dyeBlue", 1, new ItemStack(Item.redstone), new ItemStack(Item.ingotIron))); + AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(500, new ItemStack(greenPipeWire, 8), "dyeGreen", 1, new ItemStack(Item.redstone), new ItemStack(Item.ingotIron))); + AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(500, new ItemStack(yellowPipeWire, 8), "dyeYellow", 1, new ItemStack(Item.redstone), new ItemStack(Item.ingotIron))); AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[]{new ItemStack(pipeStructureCobblestone)}, 1000, new ItemStack(plugItem, 8))); } @EventHandler public void processIMCRequests(IMCEvent event) { - InterModComms.processIMC(event); + InterModComms.processIMC(event); } public static Item buildPipe(int defaultID, Class clas, String descr, Object... ingredients) { diff --git a/common/buildcraft/api/recipes/AssemblyRecipe.java b/common/buildcraft/api/recipes/AssemblyRecipe.java index b3abbdbc..6ab39418 100644 --- a/common/buildcraft/api/recipes/AssemblyRecipe.java +++ b/common/buildcraft/api/recipes/AssemblyRecipe.java @@ -8,106 +8,79 @@ import net.minecraftforge.oredict.OreDictionary; public class AssemblyRecipe { public static LinkedList assemblyRecipes = new LinkedList(); - - public final ItemStack[] input; + public final Object[] input; public final ItemStack output; public final float energy; - public final Object[] inputOreDict; - public AssemblyRecipe(ItemStack[] input, int energy, ItemStack output) { this.input = input; this.output = output; this.energy = energy; - this.inputOreDict = input; } - /** This version of AssemblyRecipe supports the OreDictionary - * - * @param input Object[] containing either an ItemStack, or a paired string and integer(ex: "dyeBlue", 1) - * @param energy MJ cost to produce - * @param output resulting ItemStack - */ - public AssemblyRecipe(Object[] input, int energy, ItemStack output) { + /** + * This version of AssemblyRecipe supports the OreDictionary + * + * @param input Object... containing either an ItemStack, or a paired string + * and integer(ex: "dyeBlue", 1) + * @param energy MJ cost to produce + * @param output resulting ItemStack + */ + public AssemblyRecipe(int energy, ItemStack output, Object... input) { this.output = output; this.energy = energy; + this.input = input; - this.inputOreDict = new Object[input.length]; - - int count = 0; - for (int idx = 0; idx < input.length; idx++) { - if (input[idx] == null) { - continue; + for (int i = 0; i < input.length; i++) { + if (input[i] instanceof String) { + input[i] = OreDictionary.getOres((String) input[i]); } - - ItemStack in; - - if (input[idx] instanceof ItemStack) { - inputOreDict[idx] = input[idx]; - count++; - } else if (input[idx] instanceof String) { - ArrayList oreListWithStackSize = new ArrayList(); - - for (ItemStack oreItem : OreDictionary.getOres((String)input[idx])) { - ItemStack sizeAdjustedOreItem = oreItem.copy(); - - //Desired recipe stacksize is on next index - sizeAdjustedOreItem.stackSize = (int)input[idx + 1]; - - oreListWithStackSize.add(sizeAdjustedOreItem); - } - - inputOreDict[idx++] = oreListWithStackSize; - count++; - } - } - - // create the recipe item array - this.input = new ItemStack[count]; - count = 0; - for(Object recipeItem : inputOreDict) { - if (recipeItem == null) { - continue; - } - - // since the API recipe item array is an ItemStack, just grab the first item from the OreDict list - this.input[count++] = recipeItem instanceof ItemStack ? (ItemStack)recipeItem: ((ArrayList)recipeItem).get(0); } } - public boolean canBeDone(ItemStack[] items) { - - for (Object in : inputOreDict) { - - if (in == null) { + public boolean canBeDone(ItemStack... items) { + for (int i = 0; i < input.length; i++) { + if (input[i] == null) continue; - } - int found = 0; // Amount of ingredient found in inventory - int expected = in instanceof ItemStack ? ((ItemStack)in).stackSize: in instanceof ArrayList ? ((ArrayList)in).get(0).stackSize: 1; + if (input[i] instanceof ItemStack) { + ItemStack requirement = (ItemStack) input[i]; + int found = 0; // Amount of ingredient found in inventory + int expected = requirement.stackSize; + for (ItemStack item : items) { + if (item == null) + continue; + + if (item.isItemEqual(requirement)) + found += item.stackSize; // Adds quantity of stack to amount found - for (ItemStack item : items) { - if (item == null) { - continue; } - if (in instanceof ItemStack) { - if (item.isItemEqual((ItemStack)in)) { - found += item.stackSize; // Adds quantity of stack to amount found - } - } else if (in instanceof ArrayList) { - for (ItemStack oreItem : (ArrayList)in) { - if(OreDictionary.itemMatches(oreItem, item, true)) { + // Return false if the amount of ingredient found + // is not enough + if (found < expected) + return false; + } else if (input[i] instanceof ArrayList) { + ArrayList oreList = (ArrayList) input[i]; + int found = 0; // Amount of ingredient found in inventory + int expected = (Integer) input[i++ + 1]; + + for (ItemStack item : items) { + if (item == null) + continue; + for (ItemStack oreItem : oreList) { + if (OreDictionary.itemMatches(oreItem, item, true)) { found += item.stackSize; break; } } } - } - if (found < expected) - return false; // Return false if the amount of ingredient found - // is not enough + // Return false if the amount of ingredient found + // is not enough + if (found < expected) + return false; + } } return true; diff --git a/common/buildcraft/silicon/TileAssemblyTable.java b/common/buildcraft/silicon/TileAssemblyTable.java index dd017f39..ffc6ae5e 100644 --- a/common/buildcraft/silicon/TileAssemblyTable.java +++ b/common/buildcraft/silicon/TileAssemblyTable.java @@ -4,12 +4,16 @@ import buildcraft.api.gates.IAction; import buildcraft.api.recipes.AssemblyRecipe; import buildcraft.core.DefaultProps; import buildcraft.core.IMachine; +import buildcraft.core.inventory.ITransactor; import buildcraft.core.inventory.StackHelper; +import buildcraft.core.inventory.Transactor; +import buildcraft.core.inventory.filters.ArrayStackFilter; import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketNBT; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.Utils; import cpw.mods.fml.common.FMLCommonHandler; +import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.LinkedList; import net.minecraft.entity.item.EntityItem; @@ -99,34 +103,7 @@ public class TileAssemblyTable extends TileEntity implements IMachine, IInventor if (currentRecipe.canBeDone(items)) { - for (ItemStack in : currentRecipe.input) { - if (in == null) { - continue; // Optimisation, reduces calculation for a null ingredient - } - - int found = 0; // Amount of ingredient found in inventory - - for (int i = 0; i < items.length; ++i) { - if (items[i] == null) { - continue; // Broken out of large if statement, increases clarity - } - - if (StackHelper.instance().isCraftingEquivalent(in, items[i], true)) { - - int supply = items[i].stackSize; - int toBeFound = in.stackSize - found; - - if (supply >= toBeFound) { - found += decrStackSize(i, toBeFound).stackSize; // Adds the amount of ingredient taken (in this case the total still needed) - } else { - found += decrStackSize(i, supply).stackSize; // Adds the amount of ingredient taken (in this case the total in that slot) - } - if (found >= in.stackSize) { - break; // Breaks out of the for loop when the required amount of ingredient has been taken - } - } - } - } + useItems(); ItemStack remaining = currentRecipe.output.copy(); remaining.stackSize -= Utils.addToRandomInventoryAround(worldObj, xCoord, yCoord, zCoord, remaining); @@ -146,6 +123,30 @@ public class TileAssemblyTable extends TileEntity implements IMachine, IInventor } } + private void useItems() { + ITransactor tran = Transactor.getTransactorFor(this); + Object[] input = currentRecipe.input; + for (int i = 0; i < input.length; i++) { + if (input[i] instanceof ItemStack) { + ItemStack requirement = (ItemStack) input[i]; + for (int num = 0; num < requirement.stackSize; num++) { + tran.remove(new ArrayStackFilter(requirement), ForgeDirection.UNKNOWN, true); + } + } else if (input[i] instanceof ArrayList) { + ArrayList oreList = (ArrayList) input[i]; + int required = (Integer) input[i + 1]; + for (ItemStack ore : oreList) { + for (int num = 0; num < required; num++) { + if (tran.remove(new ArrayStackFilter(ore), ForgeDirection.UNKNOWN, true) != null) + required--; + } + if (required <= 0) + break; + } + } + } + } + public float getCompletionRatio(float ratio) { if (currentRecipe == null) return 0; From d870fcb1829da8a4fe47e95cecfaa4b8427a69d0 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Tue, 19 Nov 2013 06:11:20 -0800 Subject: [PATCH 3/8] Fix Emerald Pipe Button Tooltip Closes #1322 --- .../transport/pipes/PipeItemsEmerald.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/common/buildcraft/transport/pipes/PipeItemsEmerald.java b/common/buildcraft/transport/pipes/PipeItemsEmerald.java index dcc7fb20..2c13ee40 100644 --- a/common/buildcraft/transport/pipes/PipeItemsEmerald.java +++ b/common/buildcraft/transport/pipes/PipeItemsEmerald.java @@ -40,15 +40,12 @@ import buildcraft.transport.PipeIconProvider; public class PipeItemsEmerald extends PipeItemsWood implements IClientState, IGuiReturnHandler { public static enum ButtonState implements IMultiButtonState { - BLOCKING("gui.pipes.emerald.blocking"), NONBLOCKING("gui.pipes.emerald.nonblocking"); + BLOCKING("gui.pipes.emerald.blocking"), NONBLOCKING("gui.pipes.emerald.nonblocking"); private final String label; - private final ToolTip tip; private ButtonState(String label) { this.label = label; - tip = new ToolTip(); - tip.add(new ToolTipLine(label + ".tip")); } @Override @@ -65,8 +62,14 @@ public class PipeItemsEmerald extends PipeItemsWood implements IClientState, IGu public ToolTip getToolTip() { return this.tip; } + private final ToolTip tip = new ToolTip(500) { + @Override + public void refresh() { + clear(); + tip.add(new ToolTipLine(StringUtils.localize(label + ".tip"))); + } + }; } - private final MultiButtonController stateController = MultiButtonController.getController(ButtonState.BLOCKING.ordinal(), ButtonState.values()); private final SimpleInventory filters = new SimpleInventory(9, "Filters", 1); private int currentFilter = 0; @@ -108,7 +111,7 @@ public class PipeItemsEmerald extends PipeItemsWood implements IClientState, IGu /* ISELECTIVEINVENTORY */ // non blocking mode is not implemented for ISelectiveInventory yet if (inventory instanceof ISelectiveInventory) { - ItemStack[] stacks = ((ISelectiveInventory) inventory).extractItem(new ItemStack[] { getCurrentFilter() }, false, doRemove, from, (int) powerHandler.getEnergyStored()); + ItemStack[] stacks = ((ISelectiveInventory) inventory).extractItem(new ItemStack[]{getCurrentFilter()}, false, doRemove, from, (int) powerHandler.getEnergyStored()); if (doRemove) { for (ItemStack stack : stacks) { if (stack != null) { @@ -168,7 +171,7 @@ public class PipeItemsEmerald extends PipeItemsWood implements IClientState, IGu } if (result != null) { - return new ItemStack[] { result }; + return new ItemStack[]{result}; } } From fbffebeef553aaa02c13ed3527991bb90c9f5b76 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Tue, 19 Nov 2013 17:18:19 -0800 Subject: [PATCH 4/8] Housecleaning --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 28a79d58..2ae94aed 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,6 @@ a problem that might have fixed been already. Such things makes for very grumpy less time coding and more time doing stuff that makes them less grumpy. * If the issues occurs on a server, be sure it's a vanilla forge server and not a mcpc+ server. * Issues with any logs mentioning Optifine will be closed on sight! Remove Optifine before reporting any issue. -* Issues with any logs mentioning MineFactoryReloaded or PowerCrystalsCore will be closed on sight! They are modifying our code using core mods! #### Frequently reported * java.lang.AbstractMethodError - Incompatibility between BC/Forge/Mod using BC API. Usually not a BC issue From 9631ef5de68194f0306c1dbe528d2a399fa7df53 Mon Sep 17 00:00:00 2001 From: DemoXin Date: Tue, 19 Nov 2013 21:02:30 -0500 Subject: [PATCH 5/8] * BlockUtil.getItemStackFromBlock() now properly posts HarvestDropsEvent and loads its results for compatibility. * BlockUtil.breakBlock() now utilizes BlockUtil.getItemStackFromBlock() to get its drop list. --- common/buildcraft/core/utils/BlockUtil.java | 23 ++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/common/buildcraft/core/utils/BlockUtil.java b/common/buildcraft/core/utils/BlockUtil.java index 3b173e7b..0dde53c8 100644 --- a/common/buildcraft/core/utils/BlockUtil.java +++ b/common/buildcraft/core/utils/BlockUtil.java @@ -10,8 +10,12 @@ package buildcraft.core.utils; import buildcraft.BuildCraftCore; import buildcraft.BuildCraftEnergy; import buildcraft.api.core.BuildCraftAPI; +import buildcraft.core.proxy.CoreProxy; import cpw.mods.fml.common.FMLCommonHandler; + +import java.util.ArrayList; import java.util.List; + import net.minecraft.block.Block; import net.minecraft.block.BlockFluid; import net.minecraft.entity.item.EntityItem; @@ -22,12 +26,14 @@ import net.minecraft.network.packet.Packet60Explosion; import net.minecraft.world.ChunkPosition; import net.minecraft.world.Explosion; import net.minecraft.world.World; +import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidBlock; + public class BlockUtil { public static List getItemStackFromBlock(World world, int i, int j, int k) { @@ -41,7 +47,19 @@ public class BlockUtil { int meta = world.getBlockMetadata(i, j, k); - return block.getBlockDropped(world, i, j, k, meta, 0); + ArrayList dropsList = block.getBlockDropped(world, i, j, k, meta, 0); + float dropChance = ForgeEventFactory.fireBlockHarvesting(dropsList, world, block, i, j, k, meta, 0, 1.0F, false, CoreProxy.proxy.getBuildCraftPlayer(world)); + + ArrayList returnList = new ArrayList(); + for (ItemStack s : dropsList) + { + if (world.rand.nextFloat() <= dropChance) + { + returnList.add(s); + } + } + + return returnList; } public static void breakBlock(World world, int x, int y, int z) { @@ -50,8 +68,7 @@ public class BlockUtil { public static void breakBlock(World world, int x, int y, int z, int forcedLifespan) { if (!world.isAirBlock(x, y, z) && BuildCraftCore.dropBrokenBlocks && !world.isRemote && world.getGameRules().getGameRuleBooleanValue("doTileDrops")) { - int blockId = world.getBlockId(x, y, z); - List items = Block.blocksList[blockId].getBlockDropped(world, x, y, z, world.getBlockMetadata(x, y, z), 0); + List items = getItemStackFromBlock(world, x, y, z); for (ItemStack item : items) { float var = 0.7F; From 9d4b1b9782fb66e989e8eb9f4a19489ea6689a6e Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Wed, 20 Nov 2013 17:27:01 -0800 Subject: [PATCH 6/8] Move ILaserTarget to the power API --- common/buildcraft/api/power/ILaserTarget.java | 46 +++++++++++++++++++ common/buildcraft/silicon/ILaserTarget.java | 15 ------ .../silicon/TileAdvancedCraftingTable.java | 7 +-- .../buildcraft/silicon/TileAssemblyTable.java | 17 +++---- common/buildcraft/silicon/TileLaser.java | 12 ++--- 5 files changed, 65 insertions(+), 32 deletions(-) create mode 100644 common/buildcraft/api/power/ILaserTarget.java delete mode 100644 common/buildcraft/silicon/ILaserTarget.java diff --git a/common/buildcraft/api/power/ILaserTarget.java b/common/buildcraft/api/power/ILaserTarget.java new file mode 100644 index 00000000..3d1eca59 --- /dev/null +++ b/common/buildcraft/api/power/ILaserTarget.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) SpaceToad, 2011-2012 + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.api.power; + +/** + * Specifies a Tile Entity that can receive power via laser beam. + * + * @author cpw + */ +public interface ILaserTarget { + + /** + * Returns true if the target currently needs power. For example, if the Advanced + * Crafting Table has work to do. + * + * @return true if needs power + */ + boolean requiresLaserEnergy(); + + /** + * Transfers energy from the laser to the target. + * + * @param energy + */ + void receiveLaserEnergy(float energy); + + /** + * Return true if the Tile Entity object is no longer a valid target. For + * example, if its been invalidated. + * + * @return true if no longer a valid target object + */ + boolean isInvalidTarget(); + + int getXCoord(); + + int getYCoord(); + + int getZCoord(); +} diff --git a/common/buildcraft/silicon/ILaserTarget.java b/common/buildcraft/silicon/ILaserTarget.java deleted file mode 100644 index 46a39b60..00000000 --- a/common/buildcraft/silicon/ILaserTarget.java +++ /dev/null @@ -1,15 +0,0 @@ -package buildcraft.silicon; - -public interface ILaserTarget { - boolean hasCurrentWork(); - - void receiveLaserEnergy(float energy); - - boolean isInvalidTarget(); - - int getXCoord(); - - int getYCoord(); - - int getZCoord(); -} diff --git a/common/buildcraft/silicon/TileAdvancedCraftingTable.java b/common/buildcraft/silicon/TileAdvancedCraftingTable.java index 8fd35a15..89a1e9d5 100644 --- a/common/buildcraft/silicon/TileAdvancedCraftingTable.java +++ b/common/buildcraft/silicon/TileAdvancedCraftingTable.java @@ -1,5 +1,6 @@ package buildcraft.silicon; +import buildcraft.api.power.ILaserTarget; import buildcraft.BuildCraftCore; import buildcraft.api.gates.IAction; import buildcraft.api.gates.IActionReceptor; @@ -413,8 +414,8 @@ public class TileAdvancedCraftingTable extends TileEntity implements IInventory, } @Override - public boolean hasCurrentWork() { - return craftable && !justCrafted && lastMode != ActionMachineControl.Mode.Off; + public boolean requiresLaserEnergy() { + return craftable && !justCrafted && lastMode != ActionMachineControl.Mode.Off && storedEnergy < REQUIRED_POWER * 10; } @Override @@ -440,7 +441,7 @@ public class TileAdvancedCraftingTable extends TileEntity implements IInventory, @Override public boolean isActive() { - return hasCurrentWork(); + return requiresLaserEnergy(); } @Override diff --git a/common/buildcraft/silicon/TileAssemblyTable.java b/common/buildcraft/silicon/TileAssemblyTable.java index ffc6ae5e..f855de21 100644 --- a/common/buildcraft/silicon/TileAssemblyTable.java +++ b/common/buildcraft/silicon/TileAssemblyTable.java @@ -1,5 +1,6 @@ package buildcraft.silicon; +import buildcraft.api.power.ILaserTarget; import buildcraft.api.gates.IAction; import buildcraft.api.recipes.AssemblyRecipe; import buildcraft.core.DefaultProps; @@ -71,12 +72,6 @@ public class TileAssemblyTable extends TileEntity implements IMachine, IInventor return result; } - @Override - public void receiveLaserEnergy(float energy) { - energyStored += energy; - recentEnergy[tick] += energy; - } - @Override public boolean canUpdate() { return !FMLCommonHandler.instance().getEffectiveSide().isClient(); @@ -456,8 +451,14 @@ public class TileAssemblyTable extends TileEntity implements IMachine, IInventor } @Override - public boolean hasCurrentWork() { - return currentRecipe != null; + public boolean requiresLaserEnergy() { + return currentRecipe != null && energyStored < currentRequiredEnergy * 5F; + } + + @Override + public void receiveLaserEnergy(float energy) { + energyStored += energy; + recentEnergy[tick] += energy; } @Override diff --git a/common/buildcraft/silicon/TileLaser.java b/common/buildcraft/silicon/TileLaser.java index c85b983c..7dcace38 100644 --- a/common/buildcraft/silicon/TileLaser.java +++ b/common/buildcraft/silicon/TileLaser.java @@ -7,6 +7,7 @@ */ package buildcraft.silicon; +import buildcraft.api.power.ILaserTarget; import buildcraft.BuildCraftCore; import buildcraft.api.core.Position; import buildcraft.api.core.SafeTimeTracker; @@ -125,7 +126,7 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction protected boolean isValidTable() { - if (laserTarget == null || laserTarget.isInvalidTarget() || !laserTarget.hasCurrentWork()) + if (laserTarget == null || laserTarget.isInvalidTarget() || !laserTarget.requiresLaserEnergy()) return false; return true; @@ -163,7 +164,7 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction break; } - List targets = new LinkedList(); + List targets = new LinkedList(); for (int x = minX; x <= maxX; ++x) { for (int y = minY; y <= maxY; ++y) { @@ -173,8 +174,8 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction if (tile instanceof ILaserTarget) { ILaserTarget table = (ILaserTarget) tile; - if (table.hasCurrentWork()) { - targets.add(new BlockIndex(x, y, z)); + if (table.requiresLaserEnergy()) { + targets.add(table); } } @@ -185,8 +186,7 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction if (targets.isEmpty()) return; - BlockIndex b = targets.get(worldObj.rand.nextInt(targets.size())); - laserTarget = (ILaserTarget) worldObj.getBlockTileEntity(b.x, b.y, b.z); + laserTarget = targets.get(worldObj.rand.nextInt(targets.size())); } protected void createLaser() { From e7c5090e1ef805ff58031957c04300a6a1a2cd80 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Wed, 20 Nov 2013 20:13:38 -0800 Subject: [PATCH 7/8] Pumps can now be disabled with redstone --- common/buildcraft/factory/BlockPump.java | 9 +++ common/buildcraft/factory/TilePump.java | 91 ++++++++++++++++-------- 2 files changed, 69 insertions(+), 31 deletions(-) diff --git a/common/buildcraft/factory/BlockPump.java b/common/buildcraft/factory/BlockPump.java index 6dc5585f..51d12c58 100644 --- a/common/buildcraft/factory/BlockPump.java +++ b/common/buildcraft/factory/BlockPump.java @@ -83,6 +83,15 @@ public class BlockPump extends BlockContainer { return false; } + @Override + public void onNeighborBlockChange(World world, int x, int y, int z, int id) { + super.onNeighborBlockChange(world, x, y, z, id); + TileEntity tile = world.getBlockTileEntity(x, y, z); + if (tile instanceof TilePump) { + ((TilePump) tile).onNeighborBlockChange(id); + } + } + @SuppressWarnings({"unchecked", "rawtypes"}) @Override public void addCreativeItems(ArrayList itemList) { diff --git a/common/buildcraft/factory/TilePump.java b/common/buildcraft/factory/TilePump.java index e6e419d3..2baa9b3b 100644 --- a/common/buildcraft/factory/TilePump.java +++ b/common/buildcraft/factory/TilePump.java @@ -62,6 +62,7 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor private SafeTimeTracker timer = new SafeTimeTracker(); private int tick = Utils.RANDOM.nextInt(); private int numFluidBlocksFound = 0; + private boolean powered = false; public TilePump() { powerHandler = new PowerHandler(this, Type.MACHINE); @@ -73,19 +74,26 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor powerHandler.configurePowerPerdition(1, 100); } - // TODO, manage this by different levels (pump what's above first...) @Override public void updateEntity() { super.updateEntity(); - if (tube == null) - return; + if (powered) { + pumpLayerQueues.clear(); + destroyTube(); + } else + createTube(); - - if (CoreProxy.proxy.isRenderWorld(worldObj)) + if (worldObj.isRemote) return; pushToConsumers(); + + if(powered) + return; + + if(tube == null) + return; if (tube.posY - aimY > 0.01) { tubeY = tube.posY - 0.01; @@ -134,6 +142,15 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor } } + public void onNeighborBlockChange(int id) { + boolean p = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord); + if (powered != p) { + powered = p; + if(!worldObj.isRemote) + sendNetworkUpdate(); + } + } + private boolean isBlocked(int x, int y, int z) { Material mat = worldObj.getBlockMaterial(x, y, z); return mat.blocksMovement(); @@ -151,28 +168,37 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor return tileBuffer[side.ordinal()].getTile(); } - @Override - public void initialize() { - tube = FactoryProxy.proxy.newPumpTube(worldObj); + private void createTube() { + if (tube == null) { + tube = FactoryProxy.proxy.newPumpTube(worldObj); - if (!Double.isNaN(tubeY)) { - tube.posY = tubeY; - } else { - tube.posY = yCoord; + if (!Double.isNaN(tubeY)) { + tube.posY = tubeY; + } else { + tube.posY = yCoord; + } + + tubeY = tube.posY; + + if (aimY == 0) { + aimY = yCoord; + } + + setTubePosition(); + + worldObj.spawnEntityInWorld(tube); + + if (!worldObj.isRemote) + sendNetworkUpdate(); } + } - tubeY = tube.posY; - - if (aimY == 0) { - aimY = yCoord; - } - - setTubePosition(); - - worldObj.spawnEntityInWorld(tube); - - if (CoreProxy.proxy.isSimulating(worldObj)) { - sendNetworkUpdate(); + private void destroyTube() { + if (tube != null) { + CoreProxy.proxy.removeEntity(tube); + tube = null; + tubeY = Double.NaN; + aimY = 0; } } @@ -298,6 +324,8 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor powerHandler.readFromNBT(data); tank.readFromNBT(data); + powered = data.getBoolean("powered"); + aimY = data.getInteger("aimY"); tubeY = data.getFloat("tubeY"); @@ -311,6 +339,8 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor powerHandler.writeToNBT(data); tank.writeToNBT(data); + data.setBoolean("powered", powered); + data.setInteger("aimY", aimY); if (tube != null) { @@ -347,6 +377,7 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor public void writeData(DataOutputStream data) throws IOException { data.writeInt(aimY); data.writeFloat((float) tubeY); + data.writeBoolean(powered); } }); @@ -359,6 +390,7 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor DataInputStream data = payload.stream; aimY = data.readInt(); tubeY = data.readFloat(); + powered = data.readBoolean(); setTubePosition(); } @@ -394,12 +426,7 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor public void destroy() { tileBuffer = null; pumpLayerQueues.clear(); - if (tube != null) { - CoreProxy.proxy.removeEntity(tube); - tube = null; - tubeY = Double.NaN; - aimY = 0; - } + destroyTube(); } @Override @@ -431,7 +458,9 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor @Override public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { - if (resource != null && !resource.isFluidEqual(tank.getFluid())) + if (resource == null) + return null; + if (!resource.isFluidEqual(tank.getFluid())) return null; return drain(from, resource.amount, doDrain); } From 28a06b0973f6bc7a72794e6b4e6fe7dd361cbba3 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Wed, 20 Nov 2013 20:20:05 -0800 Subject: [PATCH 8/8] Reduce the amount of spam when building --- build.xml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/build.xml b/build.xml index 65fbdaca..39a6a78e 100644 --- a/build.xml +++ b/build.xml @@ -130,7 +130,7 @@ - + @@ -169,10 +169,30 @@ + + + + + + + + + + + + + + + + + + + +