From 18079fb1ce1ac0bf7c8194698d322a0b2699b0da Mon Sep 17 00:00:00 2001 From: Rseifert Date: Tue, 28 Aug 2012 14:13:35 -0400 Subject: [PATCH] Clean UP --- .gitignore | 11 +- .../basicpipes/pipes/api/ILiquidConsumer.java | 35 ++++ .../basicpipes/pipes/api/ILiquidProducer.java | 30 +++ src/common/{steampower => }/mcmod.info | 0 src/common/steampower/TradeHelper.java | 174 ++++++++++++++++++ .../steampower/{ap => api}/IHeatConsumer.java | 2 +- .../steampower/{ap => api}/IHeatProducer.java | 2 +- .../steampower/boiler/TileEntityBoiler.java | 2 +- .../steampower/burner/TileEntityFireBox.java | 4 +- src/minecraft/steampower/RenderBoiler.java | 1 - 10 files changed, 254 insertions(+), 7 deletions(-) create mode 100644 src/common/basicpipes/pipes/api/ILiquidConsumer.java create mode 100644 src/common/basicpipes/pipes/api/ILiquidProducer.java rename src/common/{steampower => }/mcmod.info (100%) create mode 100644 src/common/steampower/TradeHelper.java rename src/common/steampower/{ap => api}/IHeatConsumer.java (96%) rename src/common/steampower/{ap => api}/IHeatProducer.java (94%) diff --git a/.gitignore b/.gitignore index 13325804..456c8b29 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/src/common/basicpipes/pipes/api/ILiquidConsumer.java b/src/common/basicpipes/pipes/api/ILiquidConsumer.java new file mode 100644 index 00000000..57565dbe --- /dev/null +++ b/src/common/basicpipes/pipes/api/ILiquidConsumer.java @@ -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); + +} diff --git a/src/common/basicpipes/pipes/api/ILiquidProducer.java b/src/common/basicpipes/pipes/api/ILiquidProducer.java new file mode 100644 index 00000000..ec9edc55 --- /dev/null +++ b/src/common/basicpipes/pipes/api/ILiquidProducer.java @@ -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); +} \ No newline at end of file diff --git a/src/common/steampower/mcmod.info b/src/common/mcmod.info similarity index 100% rename from src/common/steampower/mcmod.info rename to src/common/mcmod.info diff --git a/src/common/steampower/TradeHelper.java b/src/common/steampower/TradeHelper.java new file mode 100644 index 00000000..2bb325dc --- /dev/null +++ b/src/common/steampower/TradeHelper.java @@ -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; + + } +} diff --git a/src/common/steampower/ap/IHeatConsumer.java b/src/common/steampower/api/IHeatConsumer.java similarity index 96% rename from src/common/steampower/ap/IHeatConsumer.java rename to src/common/steampower/api/IHeatConsumer.java index 9f9c25a2..31accc56 100644 --- a/src/common/steampower/ap/IHeatConsumer.java +++ b/src/common/steampower/api/IHeatConsumer.java @@ -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. diff --git a/src/common/steampower/ap/IHeatProducer.java b/src/common/steampower/api/IHeatProducer.java similarity index 94% rename from src/common/steampower/ap/IHeatProducer.java rename to src/common/steampower/api/IHeatProducer.java index 1c13a5c9..879b36b1 100644 --- a/src/common/steampower/ap/IHeatProducer.java +++ b/src/common/steampower/api/IHeatProducer.java @@ -1,4 +1,4 @@ -package steampower.ap; +package steampower.api; public interface IHeatProducer diff --git a/src/common/steampower/boiler/TileEntityBoiler.java b/src/common/steampower/boiler/TileEntityBoiler.java index 84eb4133..2ef0b106 100644 --- a/src/common/steampower/boiler/TileEntityBoiler.java +++ b/src/common/steampower/boiler/TileEntityBoiler.java @@ -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; diff --git a/src/common/steampower/burner/TileEntityFireBox.java b/src/common/steampower/burner/TileEntityFireBox.java index cf2b74c6..9c659146 100644 --- a/src/common/steampower/burner/TileEntityFireBox.java +++ b/src/common/steampower/burner/TileEntityFireBox.java @@ -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; diff --git a/src/minecraft/steampower/RenderBoiler.java b/src/minecraft/steampower/RenderBoiler.java index 15cacbbf..1af554d7 100644 --- a/src/minecraft/steampower/RenderBoiler.java +++ b/src/minecraft/steampower/RenderBoiler.java @@ -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 {