resonant-induction/minecraft/liquidmechanics/api/helpers/connectionHelper.java
Rseifert 1e5c47ad3f nothing much
Moved some stuff around, and made LiquidHandler able to be used in the
api folder to help other people work with this mod. The api is not
actual needed to work with this mod but it contains helpers to make life
easier.

Also added a method to LiquidHandler to get the name of a LiquidStack
which for some reason can't be directly gotten from the liquidStack
itself. Too get it i had to iterate over the hashMap used to store
liquids. If the LiquidStack is linked to a LiquidData it will use the
LiquidData name first.

Also removed PipeInstance since its not actual needed anymore now that
PipeColor is directly linked the pipe as well as the PipeBlock metadata.
2013-01-06 23:15:21 -05:00

54 lines
1.7 KiB
Java

package liquidmechanics.api.helpers;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.ITankContainer;
import net.minecraftforge.liquids.LiquidStack;
import universalelectricity.core.vector.Vector3;
public class connectionHelper
{
/**
* Used to find all tileEntities sounding the location you will have to filter for selective
* tileEntities
*
* @param world - the world being searched threw
* @param x
* @param y
* @param z
* @return an array of up to 6 tileEntities
*/
public static TileEntity[] getSurroundings(World world, int x, int y, int z)
{
TileEntity[] list = new TileEntity[] { null, null, null, null, null, null };
for (int i = 0; i < 6; i++)
{
ForgeDirection d = ForgeDirection.getOrientation(i);
TileEntity aEntity = world.getBlockTileEntity(x + d.offsetX, y + d.offsetY, z + d.offsetZ);
if (aEntity instanceof TileEntity)
{
list[i] = aEntity;
}
}
return list;
}
/**
* Used to find which of 4 Corners this block is in a group of blocks
* 0 = not a corner
* 1-4 = a corner of some direction
*/
public static int corner(TileEntity entity)
{
TileEntity[] en = getSurroundings(entity.worldObj, entity.xCoord, entity.yCoord, entity.zCoord);
if (en[4] != null && en[2] != null && en[5] == null && en[3] == null) { return 3; }
if (en[2] != null && en[5] != null && en[3] == null && en[4] == null) { return 4; }
if (en[5] != null && en[3] != null && en[4] == null && en[2] == null) { return 1; }
if (en[3] != null && en[4] != null && en[2] == null && en[5] == null) { return 2; }
return 0;
}
}