This commit is contained in:
Rseifert 2012-08-28 14:13:35 -04:00
parent 1cf72c7f8d
commit 18079fb1ce
10 changed files with 254 additions and 7 deletions

11
.gitignore vendored
View file

@ -31,7 +31,16 @@ LICENSE
/src/common/universalelectricity/*
/src/common/basiccomponents/*
/src/common/buildcraft/*
/src/common/BasicPipes/*
/src/common/BasicPipes/BasicPipesMain.java
/src/common/BasicPipes/PipeProxy.java
/src/common/BasicPipes/pipes/BlockPipe.java
/src/common/BasicPipes/pipes/BlockPump.java
/src/common/BasicPipes/pipes/ItemGuage.java
/src/common/BasicPipes/pipes/ItemParts.java
/src/common/BasicPipes/pipes/ItemPipe.java
/src/common/BasicPipes/pipes/TileEntityCondenser.java
/src/common/BasicPipes/pipes/TileEntityPipe.java
/src/common/BasicPipes/pipes/TileEntityPump.java
/bin/
/conf/
/docs/

View file

@ -0,0 +1,35 @@
package basicpipes.pipes.api;
import net.minecraftforge.common.ForgeDirection;
public interface ILiquidConsumer
{
/**
* onRecieveLiquid
* @param vol - The amount this block received.
* @param side - The side of the block in which the liquid came from.
* @parm type - The type of liquid being received
* @return vol - The amount liquid that can't be recieved
*/
public int onReceiveLiquid(int type, int vol, ForgeDirection side);
/**
* You can use this to check if a pipe can connect to this liquid consumer to properly render the graphics
* @param forgeDirection - The side in which the electricity is coming from.
* @parm type - The type of liquid
* @return Returns true or false if this consumer can receive electricity at this given tick or moment.
*/
public boolean canRecieveLiquid(int type, ForgeDirection forgeDirection);
/**
* @return Return the stored liquid of type in this consumer.
*/
public int getStoredLiquid(int type);
/**
* @return Return the maximum amount of stored liquid this consumer can get.
*/
public int getLiquidCapacity(int type);
}

View file

@ -0,0 +1,30 @@
package basicpipes.pipes.api;
import net.minecraftforge.common.ForgeDirection;
/**
* The UEIProducer interface is an interface that must be applied to all tile entities that can produce electricity.
* @author Calclavia
*
*/
public interface ILiquidProducer
{
/**
* onProduceLiquid
* block.
* @param type - the type of liquid
* @param maxvol - The maximum vol or requested volume
* @param side - The side
* @return vol - Return a vol of liquid type that is produced
*/
public int onProduceLiquid(int type, int maxVol, ForgeDirection side);
/**
* canProduceLiquid
* block.
* @param type - the type of liquid
* @param side - The side
* @return boolean - True if can, false if can't produce liquid of type or on that side
* Also used for connection rules of pipes'
*/
public boolean canProduceLiquid(int type, ForgeDirection side);
}

View file

@ -0,0 +1,174 @@
package steampower;
import basicpipes.pipes.api.ILiquidConsumer;
import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection;
public class TradeHelper {
/**
*
* @param entity - entity at center of search
* @return an Array containing found entities and nulls of nonEntities
*/
public static TileEntity[] getSourounding(TileEntity entity)
{
TileEntity[] list = new TileEntity[]{null,null,null,null,null,null};
for(int i =0; i< 6;i++)
{
int x = entity.xCoord;
int y = entity.yCoord;
int z = entity.zCoord;
switch(i)
{
case 0: y = y - 1;break;//down
case 1: y = y + 1;break;//up
case 2: z = z + 1;break;//north
case 3: z = z - 1;break;//south
case 4: x = x + 1;break;//east
case 5: x = x - 1;break;//west
}
TileEntity aEntity = entity.worldObj.getBlockTileEntity(x, y, z);
if(aEntity instanceof TileEntity)
{
list[i] = aEntity;
}
}
return list;
}
/**
* Only works for steam Power's boiler. Still needs recode to work for all things
* @param blockEntity - tile entity trading the liquid
* @param type - liquid type see chart for info
* @param rise - does the liquid rise up like a gas
* @return the remaining untraded liquid
*/
public static int shareLiquid(TileEntity blockEntity,int type,boolean rise)
{
TileEntity[] connectedBlocks = getSourounding(blockEntity);
ILiquidConsumer blockMachine = (ILiquidConsumer) blockEntity;
int wSum = ((ILiquidConsumer)blockEntity).getStoredLiquid(type);
int ammountStored = blockMachine.getStoredLiquid(type);
int tankCount = 1;
boolean bottom = false;
TileEntity firstEntity = null;
TileEntity secondEntity = null;
if(rise)
{
firstEntity = connectedBlocks[1];
secondEntity = connectedBlocks[0];
}
else
{
firstEntity = connectedBlocks[0];
secondEntity = connectedBlocks[1];
}
//checks wether or not the block bellow it is a tank to move liquid too
if(firstEntity instanceof ILiquidConsumer)
{
int bWater = ((ILiquidConsumer) firstEntity).getStoredLiquid(type);
int bMax = ((ILiquidConsumer) firstEntity).getLiquidCapacity(type);
//checks if that tank has room to get liquid.
if(bWater < bMax)
{
int tradeVol = 0;
int emptyVol = Math.max( bMax - bWater,0);
tradeVol = Math.min(emptyVol, ammountStored);
int rejected = ((ILiquidConsumer) firstEntity).onReceiveLiquid(type, tradeVol, ForgeDirection.getOrientation(1));
ammountStored = ammountStored + rejected - tradeVol;
wSum -= tradeVol;
}
else
{
bottom = true;
}
}
else
{
//there was no tank bellow this tank
bottom = true;
}
//if this is the bottom tank or bottom tank is full. Update average water ammount.
if(bottom)
{
//get average water around center tank
for(int i = 2; i<6;i++)
{
TileEntity entityA = connectedBlocks[i];
if(entityA instanceof ILiquidConsumer)
{
//if is a tank add to the sum
wSum += ((ILiquidConsumer) entityA).getStoredLiquid(type);
tankCount += 1;
}
}
//if this is the bottom tank or bottom tank is full then trade liquid with tanks around it.
for(int i = 2; i<6;i++)
{
int average = Math.round((float)wSum / (float)tankCount);// takes the sum and makes it an average
int tradeSum = 0;
TileEntity entity = connectedBlocks[i];
if(entity instanceof ILiquidConsumer)
{
int targetW = ((ILiquidConsumer) entity).getStoredLiquid(type);
if(targetW < average)
{
tradeSum = Math.min(average, ammountStored); //gets the ammount to give to the target tank
int rejectedAm = ((ILiquidConsumer) entity).onReceiveLiquid(type, tradeSum, ForgeDirection.getOrientation(i)); //send that ammount with safty incase some comes back
ammountStored =rejectedAm + ammountStored - tradeSum; //counts up current water sum after trade
}
}
}
if(secondEntity instanceof ILiquidConsumer)
{
int bWater = ((ILiquidConsumer) secondEntity).getStoredLiquid(type);
int bMax = ((ILiquidConsumer) secondEntity).getLiquidCapacity(type);
if(bottom && ammountStored > 0)
{
if(bWater < bMax)
{
int emptyVolS = Math.max( bMax - bWater,0);
int tradeVolS = Math.min(emptyVolS, ammountStored);
int rejectedS = ((ILiquidConsumer) secondEntity).onReceiveLiquid(type, tradeVolS, ForgeDirection.getOrientation(0));;
ammountStored =rejectedS + ammountStored - tradeVolS;
wSum -= tradeVolS;
}
}
}
}
return ammountStored;
}
/**
*
* @param entity - entity in question
* @return 1-4 if corner 0 if not a corner
* you have to figure out which is which depending on what your using this for
* 1 should be north east 2 south east
*/
public static int corner(TileEntity entity)
{
TileEntity[] en = getSourounding(entity);
if(en[4] != null && en[2] != null && en[5] == null && en[3] == null)
{
return 1;
}
if(en[2] != null && en[5] != null && en[3] == null && en[4] == null)
{
return 2;
}
if(en[5] != null && en[3] != null && en[4] == null && en[2] == null)
{
return 3;
}
if(en[3] != null && en[4] != null && en[2] == null && en[5] == null)
{
return 4;
}
return 0;
}
}

View file

@ -1,4 +1,4 @@
package steampower.ap;
package steampower.api;
/**
* The IHeatConsumer interface is an interface that must be applied to all tile entities that can receive heat joules.

View file

@ -1,4 +1,4 @@
package steampower.ap;
package steampower.api;
public interface IHeatProducer

View file

@ -9,9 +9,9 @@ import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import steampower.SteamPowerMain;
import steampower.TileEntityMachine;
import steampower.TradeHelper;
import steampower.burner.TileEntityFireBox;
import universalelectricity.network.IPacketReceiver;
import basicpipes.TradeHelper;
import basicpipes.pipes.api.ILiquidConsumer;
import basicpipes.pipes.api.ILiquidProducer;

View file

@ -12,10 +12,10 @@ import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.ISidedInventory;
import steampower.SteamPowerMain;
import steampower.TileEntityMachine;
import steampower.ap.IHeatProducer;
import steampower.TradeHelper;
import steampower.api.IHeatProducer;
import steampower.boiler.TileEntityBoiler;
import universalelectricity.network.IPacketReceiver;
import basicpipes.TradeHelper;
import com.google.common.io.ByteArrayDataInput;

View file

@ -6,7 +6,6 @@ import net.minecraft.src.TileEntitySpecialRenderer;
import org.lwjgl.opengl.GL11;
import steampower.boiler.TileEntityBoiler;
import basicpipes.TradeHelper;
public class RenderBoiler extends TileEntitySpecialRenderer
{