diff --git a/src/dark/core/helpers/InvInteractionHelper.java b/src/dark/core/helpers/InvInteractionHelper.java index 45dd32432..8f554d2d1 100644 --- a/src/dark/core/helpers/InvInteractionHelper.java +++ b/src/dark/core/helpers/InvInteractionHelper.java @@ -14,7 +14,11 @@ import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.vector.Vector3; import dark.api.IExtendedStorage; import dark.core.prefab.machine.TileEntityMulti; - +/** + * Helper that handles most of the interaction of the tile with the inventories around it + * @author Rseifert + * + */ public class InvInteractionHelper { public World world; @@ -41,7 +45,7 @@ public class InvInteractionHelper } /** Throws the items from the manipulator into the world. - * + * * @param outputPosition * @param items */ public void throwItem(Vector3 outputPosition, ItemStack items) @@ -72,7 +76,7 @@ public class InvInteractionHelper } /** Tries to place an itemStack in a specific position if it is an inventory. - * + * * @return The ItemStack remained after place attempt */ public ItemStack tryPlaceInPosition(ItemStack itemStack, Vector3 position, ForgeDirection dir) { @@ -209,7 +213,7 @@ public class InvInteractionHelper } /** Tries to get an item from a position - * + * * @param position - location of item * @param direction - direction this item is from the original * @param ammount - amount up to one stack to grab diff --git a/src/dark/core/helpers/ItemWorldHelper.java b/src/dark/core/helpers/ItemWorldHelper.java index 1b0067055..b1553b436 100644 --- a/src/dark/core/helpers/ItemWorldHelper.java +++ b/src/dark/core/helpers/ItemWorldHelper.java @@ -4,24 +4,32 @@ import java.util.ArrayList; import java.util.List; import net.minecraft.block.Block; +import net.minecraft.command.IEntitySelector; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; +import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.vector.Vector3; public class ItemWorldHelper { /** gets all EntityItems in a location using a start and end point */ - public static List findAllItemIn(World world, Vector3 start, Vector3 end) + public static List findAllItemsIn(World world, Vector3 start, Vector3 end) { return world.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(start.x, start.y, start.z, end.x, end.y, end.z)); } + public static List getEntitiesInDirection(World world, Vector3 center, ForgeDirection dir) + { + List list = world.selectEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getAABBPool().getAABB(center.x + dir.offsetX, center.y + dir.offsetY, center.z + dir.offsetZ, center.x + dir.offsetX + 1, center.y + dir.offsetY + 1, center.z + dir.offsetZ + 1), IEntitySelector.selectAnything); + return list.size() > 0 ? list : null; + } + /** Gets all EntityItems in an area and sorts them by a list of itemStacks - * + * * @param world - world being worked in * @param start - start point * @param end - end point @@ -29,7 +37,7 @@ public class ItemWorldHelper * @return a list of EntityItem that match the itemStacks desired */ public static List findSelectItems(World world, Vector3 start, Vector3 end, List disiredItems) { - List entityItems = ItemWorldHelper.findAllItemIn(world, start, end); + List entityItems = ItemWorldHelper.findAllItemsIn(world, start, end); return filterEntityItemsList(entityItems, disiredItems); } @@ -68,7 +76,7 @@ public class ItemWorldHelper } /** filter a list of itemStack to another list of itemStacks - * + * * @param totalItems - full list of items being filtered * @param desiredItems - list the of item that are being filtered too * @return a list of item from the original that are wanted */ @@ -91,7 +99,7 @@ public class ItemWorldHelper } /** grabs all the items that the block can drop then pass them onto dropBlockAsItem_do - * + * * @param world * @param x * @param y diff --git a/src/dark/core/prefab/machine/BlockMachine.java b/src/dark/core/prefab/machine/BlockMachine.java index c6def2b83..135d949ff 100644 --- a/src/dark/core/prefab/machine/BlockMachine.java +++ b/src/dark/core/prefab/machine/BlockMachine.java @@ -7,6 +7,8 @@ import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.world.World; @@ -110,6 +112,17 @@ public abstract class BlockMachine extends BlockTile implements IExtraBlockInfo super.breakBlock(world, x, y, z, par5, par6); world.notifyBlockChange(x, y, z, world.getBlockId(x, y, z)); } + + @Override + public int getComparatorInputOverride(World world, int x, int y, int z, int side) + { + TileEntity entity = world.getBlockTileEntity(x, y, z); + if (entity instanceof IInventory) + { + return Container.calcRedstoneFromInventory((IInventory) entity); + } + return 0; + } @Override public TileEntity createTileEntity(World world, int metadata) diff --git a/src/dark/core/prefab/machine/TileEntityInv.java b/src/dark/core/prefab/machine/TileEntityInv.java index f08648c09..1976f2bfb 100644 --- a/src/dark/core/prefab/machine/TileEntityInv.java +++ b/src/dark/core/prefab/machine/TileEntityInv.java @@ -2,7 +2,6 @@ package dark.core.prefab.machine; import java.util.ArrayList; import java.util.List; - import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ISidedInventory; @@ -10,6 +9,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraftforge.common.ForgeDirection; +import universalelectricity.core.vector.Vector3; import universalelectricity.prefab.tile.TileEntityAdvanced; import dark.api.access.AccessGroup; import dark.api.access.AccessUser; @@ -21,13 +21,14 @@ import dark.core.prefab.terminal.TerminalCommandRegistry; import dark.core.prefab.tilenetwork.NetworkTileEntities; /** Prefab for simple object who only need basic inv support and nothing more - * + * * @author Darkguardsman */ public class TileEntityInv extends TileEntityAdvanced implements IExternalInv, ISidedInventory, ISpecialAccess { protected IInvBox inventory; protected boolean lockInv; protected int invSlots = 1; + private Vector3 thisPos; /** A list of user access data. */ protected List groups = new ArrayList(); @@ -36,6 +37,20 @@ public class TileEntityInv extends TileEntityAdvanced implements IExternalInv, I TerminalCommandRegistry.loadNewGroupSet(this); } + public void initiate() + { + thisPos = new Vector3(this); + } + + public Vector3 getThisPos() + { + if (this.thisPos == null || this.thisPos.intX() != xCoord || this.thisPos.intY() != yCoord || this.thisPos.intZ() != zCoord) + { + this.thisPos = new Vector3(this); + } + return this.thisPos; + } + @Override public void invalidate() {