diff --git a/src/main/java/buildcraft/LICENSE-API b/src/main/java/buildcraft/LICENSE-API
new file mode 100644
index 000000000..95f750db0
--- /dev/null
+++ b/src/main/java/buildcraft/LICENSE-API
@@ -0,0 +1,21 @@
+BuildCraft API License
+
+Copyright (c) 2011-2014 SpaceToad and the BuildCraft team
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/src/main/java/buildcraft/api/tools/IToolWrench.java b/src/main/java/buildcraft/api/tools/IToolWrench.java
new file mode 100644
index 000000000..517f3e79b
--- /dev/null
+++ b/src/main/java/buildcraft/api/tools/IToolWrench.java
@@ -0,0 +1,40 @@
+/**
+ * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
+ * http://www.mod-buildcraft.com
+ *
+ * The BuildCraft API is distributed under the terms of the MIT License.
+ * Please check the contents of the license, which should be located
+ * as "LICENSE.API" in the BuildCraft source code distribution.
+ */
+package buildcraft.api.tools;
+
+import net.minecraft.entity.player.EntityPlayer;
+
+/***
+ * Implement this interface on subclasses of Item to have that item work as a wrench for buildcraft
+ */
+public interface IToolWrench {
+
+ /***
+ * Called to ensure that the wrench can be used. To get the ItemStack that is used, check player.inventory.getCurrentItem()
+ *
+ * @param player
+ * - The player doing the wrenching
+ * @param x
+ * ,y,z - The coordinates for the block being wrenched
+ *
+ * @return true if wrenching is allowed, false if not
+ */
+ boolean canWrench(EntityPlayer player, int x, int y, int z);
+
+ /***
+ * Callback after the wrench has been used. This can be used to decrease durability or for other purposes. To get the ItemStack that was used, check
+ * player.inventory.getCurrentItem()
+ *
+ * @param player
+ * - The player doing the wrenching
+ * @param x
+ * ,y,z - The coordinates of the block being wrenched
+ */
+ void wrenchUsed(EntityPlayer player, int x, int y, int z);
+}
diff --git a/src/main/java/buildcraft/api/tools/package-info.java b/src/main/java/buildcraft/api/tools/package-info.java
new file mode 100644
index 000000000..9c131641e
--- /dev/null
+++ b/src/main/java/buildcraft/api/tools/package-info.java
@@ -0,0 +1,11 @@
+/**
+ * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
+ * http://www.mod-buildcraft.com
+ *
+ * The BuildCraft API is distributed under the terms of the MIT License.
+ * Please check the contents of the license, which should be located
+ * as "LICENSE.API" in the BuildCraft source code distribution.
+ */
+@API(apiVersion = "1.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|tools")
+package buildcraft.api.tools;
+import cpw.mods.fml.common.API;
diff --git a/src/main/java/forestry/core/inventory/AdjacentInventoryCache.java b/src/main/java/forestry/core/inventory/AdjacentInventoryCache.java
index d77b7695f..da1a14afb 100644
--- a/src/main/java/forestry/core/inventory/AdjacentInventoryCache.java
+++ b/src/main/java/forestry/core/inventory/AdjacentInventoryCache.java
@@ -10,12 +10,20 @@
******************************************************************************/
package forestry.core.inventory;
-import forestry.core.utils.AdjacentTileCache;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.LinkedList;
+import java.util.List;
+
import net.minecraft.inventory.IInventory;
import net.minecraft.tileentity.TileEntity;
+
import net.minecraftforge.common.util.ForgeDirection;
+import forestry.core.utils.AdjacentTileCache;
+
/**
*
* @author CovertJaguar
@@ -40,12 +48,12 @@ public final class AdjacentInventoryCache implements AdjacentTileCache.ICacheLis
cache.addListener(this);
}
- public IInventory getAdjecentInventory(ForgeDirection side) {
+ public IInventory getAdjacentInventory(ForgeDirection side) {
checkChanged();
return sides[side.ordinal()];
}
- public Collection getAdjecentInventories() {
+ public Collection getAdjacentInventories() {
checkChanged();
return invs;
}
diff --git a/src/main/java/forestry/core/inventory/InvTools.java b/src/main/java/forestry/core/inventory/InvTools.java
index b1e35ae12..5cdad4e87 100755
--- a/src/main/java/forestry/core/inventory/InvTools.java
+++ b/src/main/java/forestry/core/inventory/InvTools.java
@@ -10,8 +10,31 @@
******************************************************************************/
package forestry.core.inventory;
-import buildcraft.api.transport.IPipeTile;
-import buildcraft.api.transport.PipeManager;
+import java.util.AbstractMap;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import net.minecraft.block.Block;
+import net.minecraft.entity.item.EntityItem;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.inventory.ISidedInventory;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.nbt.NBTTagList;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.tileentity.TileEntityChest;
+import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.World;
+
+import net.minecraftforge.common.util.ForgeDirection;
+import net.minecraftforge.oredict.OreDictionary;
+
+import cpw.mods.fml.common.Optional;
+
import forestry.core.inventory.filters.ArrayStackFilter;
import forestry.core.inventory.filters.IStackFilter;
import forestry.core.inventory.filters.InvertedStackFilter;
@@ -25,26 +48,10 @@ import forestry.core.inventory.wrappers.InventoryMapper;
import forestry.core.inventory.wrappers.SidedInventoryMapper;
import forestry.core.utils.AdjacentTileCache;
import forestry.core.utils.PlainInventory;
-import java.util.AbstractMap;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-import net.minecraft.block.Block;
-import net.minecraft.entity.item.EntityItem;
-import net.minecraft.inventory.IInventory;
-import net.minecraft.inventory.ISidedInventory;
-import net.minecraft.item.ItemStack;
-import net.minecraft.nbt.NBTTagCompound;
-import net.minecraft.nbt.NBTTagList;
-import net.minecraft.tileentity.TileEntity;
-import net.minecraft.tileentity.TileEntityChest;
-import net.minecraft.world.IBlockAccess;
-import net.minecraft.world.World;
-import net.minecraftforge.common.util.ForgeDirection;
-import net.minecraftforge.oredict.OreDictionary;
+import forestry.plugins.PluginManager;
+
+import buildcraft.api.transport.IPipeTile;
+import buildcraft.api.transport.PipeManager;
public abstract class InvTools {
@@ -144,8 +151,10 @@ public abstract class InvTools {
if (tile == null || !(tile instanceof IInventory))
return null;
- if (!PipeManager.canExtractItems(null, tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord))
- return null;
+ if (PluginManager.Module.BUILDCRAFT_TRANSPORT.isEnabled()) {
+ if(!internal_canExtractFromBuildCraftPipe(tile))
+ return null;
+ }
if (tile instanceof TileEntityChest) {
TileEntityChest chest = (TileEntityChest) tile;
@@ -154,6 +163,11 @@ public abstract class InvTools {
return getInventory((IInventory) tile, side);
}
+ @Optional.Method(modid = "BuildCraftAPI|transport")
+ private static boolean internal_canExtractFromBuildCraftPipe(TileEntity tile) {
+ return PipeManager.canExtractItems(null, tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord);
+ }
+
public static IInventory getInventory(IInventory inv, ForgeDirection side) {
if (inv == null)
return null;
@@ -741,6 +755,15 @@ public abstract class InvTools {
* @return true if an item was inserted, otherwise false.
*/
public static boolean moveOneItemToPipe(IInventory source, AdjacentTileCache tileCache) {
+ if (PluginManager.Module.BUILDCRAFT_TRANSPORT.isEnabled()) {
+ return internal_moveOneItemToPipe(source, tileCache);
+ }
+
+ return false;
+ }
+
+ @Optional.Method(modid = "BuildCraftAPI|transport")
+ private static boolean internal_moveOneItemToPipe(IInventory source, AdjacentTileCache tileCache) {
IInventory invClone = new InventoryCopy(source);
ItemStack stackToMove = removeOneItem(invClone);
if (stackToMove == null)
diff --git a/src/main/java/forestry/core/utils/BlockUtil.java b/src/main/java/forestry/core/utils/BlockUtil.java
index d45c7accc..a4971a0e5 100644
--- a/src/main/java/forestry/core/utils/BlockUtil.java
+++ b/src/main/java/forestry/core/utils/BlockUtil.java
@@ -11,8 +11,6 @@
package forestry.core.utils;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.LinkedList;
import net.minecraft.block.Block;
import net.minecraft.block.BlockCocoa;
@@ -28,11 +26,6 @@ import net.minecraftforge.common.util.ForgeDirection;
import forestry.core.config.Defaults;
import forestry.core.vect.Vect;
-import buildcraft.api.core.Position;
-import buildcraft.api.transport.IPipeConnection;
-import buildcraft.api.transport.IPipeConnection.ConnectOverride;
-import buildcraft.api.transport.IPipeTile;
-import buildcraft.api.transport.IPipeTile.PipeType;
import cofh.api.energy.IEnergyHandler;
public class BlockUtil {
@@ -45,80 +38,6 @@ public class BlockUtil {
}
- /**
- * Returns a list of adjacent pipes.
- */
- public static ForgeDirection[] getPipeDirections(World world, Vect blockPos, ForgeDirection from) {
- LinkedList possiblePipes = new LinkedList();
-
- for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
- if (from != ForgeDirection.UNKNOWN && from != dir.getOpposite())
- continue;
-
- Position posPipe = new Position(blockPos.x, blockPos.y, blockPos.z, dir);
- posPipe.moveForwards(1.0);
-
- TileEntity pipeEntry = world.getTileEntity((int) posPipe.x, (int) posPipe.y, (int) posPipe.z);
-
- if (pipeEntry instanceof IPipeTile) {
- IPipeTile pipe = (IPipeTile) pipeEntry;
-
- if (from != ForgeDirection.UNKNOWN && pipeEntry instanceof IPipeConnection) {
- if (((IPipeConnection) pipeEntry).overridePipeConnection(PipeType.ITEM, from) != ConnectOverride.DISCONNECT)
- possiblePipes.add(dir);
- } else if (pipe.getPipeType() == PipeType.ITEM && pipe.isPipeConnected(dir.getOpposite()))
- possiblePipes.add(dir);
- }
- }
-
- return possiblePipes.toArray(new ForgeDirection[possiblePipes.size()]);
-
- }
-
- public static ArrayList filterPipeDirections(ForgeDirection[] allDirections, ForgeDirection[] exclude) {
- ArrayList filtered = new ArrayList();
- ArrayList excludeList = new ArrayList(Arrays.asList(exclude));
-
- for (ForgeDirection direction : allDirections) {
- if (!excludeList.contains(direction))
- filtered.add(direction);
- }
-
- return filtered;
-
- }
-
- public static boolean putFromStackIntoPipe(TileEntity tile, ArrayList pipes, ItemStack stack) {
-
- if (stack == null)
- return false;
- if (stack.stackSize <= 0)
- return false;
- if (pipes.size() <= 0)
- return false;
-
- int choice = tile.getWorldObj().rand.nextInt(pipes.size());
- Position itemPos = new Position(tile.xCoord, tile.yCoord, tile.zCoord, pipes.get(choice));
-
- itemPos.x += 0.5;
- itemPos.y += 0.25;
- itemPos.z += 0.5;
- itemPos.moveForwards(0.5);
-
- Position pipePos = new Position(tile.xCoord, tile.yCoord, tile.zCoord, pipes.get(choice));
- pipePos.moveForwards(1.0);
-
- IPipeTile pipe = (IPipeTile) tile.getWorldObj().getTileEntity((int) pipePos.x, (int) pipePos.y, (int) pipePos.z);
-
- ItemStack payload = stack.splitStack(1);
- if (pipe.injectItem(payload, true, itemPos.orientation.getOpposite()) > 0)
- return true;
- else
- pipes.remove(choice);
-
- return false;
- }
-
public static boolean isRFTile(ForgeDirection side, TileEntity tile) {
if (tile == null)
return false;
diff --git a/src/main/java/forestry/energy/gadgets/EngineCopper.java b/src/main/java/forestry/energy/gadgets/EngineCopper.java
index 2d805666f..2afdfc453 100755
--- a/src/main/java/forestry/energy/gadgets/EngineCopper.java
+++ b/src/main/java/forestry/energy/gadgets/EngineCopper.java
@@ -10,9 +10,24 @@
******************************************************************************/
package forestry.energy.gadgets;
-import buildcraft.api.statements.ITriggerExternal;
+import java.util.Collection;
+import java.util.LinkedList;
+
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.inventory.Container;
+import net.minecraft.inventory.ICrafting;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.inventory.ISidedInventory;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.tileentity.TileEntity;
+
+import net.minecraftforge.common.util.ForgeDirection;
+
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.common.registry.GameData;
+
import forestry.api.core.ForestryAPI;
import forestry.api.fuels.FuelManager;
import forestry.core.EnumErrorCode;
@@ -22,22 +37,14 @@ import forestry.core.config.Defaults;
import forestry.core.config.ForestryItem;
import forestry.core.gadgets.Engine;
import forestry.core.gadgets.TileBase;
+import forestry.core.inventory.AdjacentInventoryCache;
+import forestry.core.inventory.InvTools;
import forestry.core.inventory.TileInventoryAdapter;
+import forestry.core.inventory.wrappers.InventoryMapper;
import forestry.core.network.GuiId;
-import forestry.core.utils.BlockUtil;
import forestry.factory.triggers.FactoryTriggers;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedList;
-import net.minecraft.entity.player.EntityPlayer;
-import net.minecraft.inventory.Container;
-import net.minecraft.inventory.ICrafting;
-import net.minecraft.inventory.ISidedInventory;
-import net.minecraft.item.Item;
-import net.minecraft.item.ItemStack;
-import net.minecraft.nbt.NBTTagCompound;
-import net.minecraft.tileentity.TileEntity;
-import net.minecraftforge.common.util.ForgeDirection;
+
+import buildcraft.api.statements.ITriggerExternal;
public class EngineCopper extends Engine implements ISidedInventory {
@@ -53,6 +60,7 @@ public class EngineCopper extends Engine implements ISidedInventory {
private int totalBurnTime;
private int ashProduction;
private final int ashForItem;
+ private final AdjacentInventoryCache inventoryCache = new AdjacentInventoryCache(this, getTileCache());
public EngineCopper() {
super(Defaults.ENGINE_COPPER_HEAT_MAX, 200000, 4000);
@@ -97,9 +105,11 @@ public class EngineCopper extends Engine implements ISidedInventory {
public void updateServerSide() {
super.updateServerSide();
- if (worldObj.getTotalWorldTime() % 20 * 10 != 0)
+ if (worldObj.getTotalWorldTime() % 40 != 0)
return;
+ dumpStash();
+
if (mayBurn() && burnTime > 0) {
setErrorState(EnumErrorCode.OK);
return;
@@ -217,31 +227,22 @@ public class EngineCopper extends Engine implements ISidedInventory {
return 0;
}
- private void dumpStash() {
- ForgeDirection[] pipes = BlockUtil.getPipeDirections(worldObj, Coords(), ForgeDirection.UNKNOWN);
+ /* AUTO-EJECTING */
+ private IInventory getWasteInventory() {
+ TileInventoryAdapter inventory = getInternalInventory();
+ if (inventory == null)
+ return null;
- if (pipes.length > 0)
- dumpToPipe(pipes);
+ return new InventoryMapper(inventory, SLOT_WASTE_1, SLOT_WASTE_COUNT);
}
- private void dumpToPipe(ForgeDirection[] pipes) {
- TileInventoryAdapter inventory = getInternalInventory();
- for (int i = SLOT_WASTE_1; i < SLOT_WASTE_1 + SLOT_WASTE_COUNT; i++) {
- if (inventory.getStackInSlot(i) == null)
- continue;
- if (inventory.getStackInSlot(i).stackSize <= 0)
- continue;
+ private void dumpStash() {
+ IInventory wasteInventory = getWasteInventory();
+ if (wasteInventory == null)
+ return;
- ArrayList filtered;
- filtered = BlockUtil.filterPipeDirections(pipes, new ForgeDirection[]{getOrientation()});
-
- while (inventory.getStackInSlot(i).stackSize > 0 && filtered.size() > 0) {
- BlockUtil.putFromStackIntoPipe(this, filtered, inventory.getStackInSlot(i));
- }
-
- if (inventory.getStackInSlot(i).stackSize <= 0)
- inventory.setInventorySlotContents(i, null);
- }
+ if (!InvTools.moveOneItemToPipe(wasteInventory, tileCache))
+ InvTools.moveItemStack(wasteInventory, inventoryCache.getAdjacentInventories());
}
// / STATE INFORMATION
diff --git a/src/main/java/forestry/energy/gadgets/EngineDefinition.java b/src/main/java/forestry/energy/gadgets/EngineDefinition.java
index f91f18890..db9f4f0fa 100755
--- a/src/main/java/forestry/energy/gadgets/EngineDefinition.java
+++ b/src/main/java/forestry/energy/gadgets/EngineDefinition.java
@@ -42,7 +42,7 @@ public class EngineDefinition extends MachineDefinition {
return false;
Engine tile = (Engine) world.getTileEntity(x, y, z);
- if (player.getCurrentEquippedItem() != null && Utils.canWrench(player, x, y, z)) {
+ if (Utils.canWrench(player, x, y, z)) {
tile.rotateEngine();
Utils.useWrench(player, x, y, z);
return true;
diff --git a/src/main/java/forestry/farming/gadgets/TileHatch.java b/src/main/java/forestry/farming/gadgets/TileHatch.java
index 5d6820471..52a456e57 100755
--- a/src/main/java/forestry/farming/gadgets/TileHatch.java
+++ b/src/main/java/forestry/farming/gadgets/TileHatch.java
@@ -66,14 +66,12 @@ public class TileHatch extends TileFarm implements ISidedInventory {
}
protected void dumpStash() {
-
- if (!hasMaster())
+ IInventory productInventory = getProductInventory();
+ if (productInventory == null)
return;
- if (!InvTools.moveOneItemToPipe(getProductInventory(), tileCache)) {
- IInventory struct = getStructureInventory();
- if (struct != null)
- InvTools.moveItemStack(getProductInventory(), inventoryCache.getAdjecentInventories());
+ if (!InvTools.moveOneItemToPipe(productInventory, tileCache)) {
+ InvTools.moveItemStack(productInventory, inventoryCache.getAdjacentInventories());
}
}