From 6d98e90acbc6f9149d95a296201b8d0c0ffbfcd8 Mon Sep 17 00:00:00 2001 From: Rseifert Date: Wed, 10 Apr 2013 17:32:46 -0400 Subject: [PATCH] Cleanup and bug fixes Worked on fixing a possible bug with release valve draining and ITankContainer that might not have had tanks on that side. --- .../fluidmech/client/ClientProxy.java | 6 +- .../client/model/ModelLiquidTank.java | 2 +- .../client/render/RenderReleaseValve.java | 2 +- .../fluidmech/client/render/RenderSink.java | 2 +- .../fluidmech/client/render/RenderTank.java | 2 +- src/minecraft/fluidmech/common/FluidMech.java | 6 +- .../common/block/BlockReleaseValve.java | 2 +- .../fluidmech/common/block/BlockSink.java | 2 +- .../fluidmech/common/block/BlockTank.java | 2 +- .../TileEntityReleaseValve.java | 70 ++++++++----------- .../{machines => tiles}/TileEntitySink.java | 2 +- .../{machines => tiles}/TileEntityTank.java | 2 +- 12 files changed, 45 insertions(+), 55 deletions(-) rename src/minecraft/fluidmech/common/{machines => tiles}/TileEntityReleaseValve.java (73%) rename src/minecraft/fluidmech/common/{machines => tiles}/TileEntitySink.java (98%) rename src/minecraft/fluidmech/common/{machines => tiles}/TileEntityTank.java (99%) diff --git a/src/minecraft/fluidmech/client/ClientProxy.java b/src/minecraft/fluidmech/client/ClientProxy.java index 8cf95b27..f9aed9a0 100644 --- a/src/minecraft/fluidmech/client/ClientProxy.java +++ b/src/minecraft/fluidmech/client/ClientProxy.java @@ -14,13 +14,13 @@ import fluidmech.client.render.RenderTank; import fluidmech.client.render.pipeextentions.RenderPipe; import fluidmech.common.CommonProxy; import fluidmech.common.FluidMech; -import fluidmech.common.machines.TileEntityReleaseValve; -import fluidmech.common.machines.TileEntitySink; -import fluidmech.common.machines.TileEntityTank; import fluidmech.common.machines.mech.TileEntityGenerator; import fluidmech.common.machines.mech.TileEntityRod; import fluidmech.common.machines.pipes.TileEntityPipe; import fluidmech.common.pump.TileEntityStarterPump; +import fluidmech.common.tiles.TileEntityReleaseValve; +import fluidmech.common.tiles.TileEntitySink; +import fluidmech.common.tiles.TileEntityTank; public class ClientProxy extends CommonProxy { diff --git a/src/minecraft/fluidmech/client/model/ModelLiquidTank.java b/src/minecraft/fluidmech/client/model/ModelLiquidTank.java index 2f7c96fd..e853573e 100644 --- a/src/minecraft/fluidmech/client/model/ModelLiquidTank.java +++ b/src/minecraft/fluidmech/client/model/ModelLiquidTank.java @@ -9,8 +9,8 @@ package fluidmech.client.model; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; import net.minecraft.tileentity.TileEntity; -import fluidmech.common.machines.TileEntityTank; import fluidmech.common.machines.pipes.TileEntityPipe; +import fluidmech.common.tiles.TileEntityTank; public class ModelLiquidTank extends ModelBase { diff --git a/src/minecraft/fluidmech/client/render/RenderReleaseValve.java b/src/minecraft/fluidmech/client/render/RenderReleaseValve.java index ab6e4870..47d65259 100644 --- a/src/minecraft/fluidmech/client/render/RenderReleaseValve.java +++ b/src/minecraft/fluidmech/client/render/RenderReleaseValve.java @@ -10,7 +10,7 @@ import org.lwjgl.opengl.GL11; import fluidmech.client.model.ModelLargePipe; import fluidmech.client.model.ModelReleaseValve; import fluidmech.common.FluidMech; -import fluidmech.common.machines.TileEntityReleaseValve; +import fluidmech.common.tiles.TileEntityReleaseValve; public class RenderReleaseValve extends TileEntitySpecialRenderer { diff --git a/src/minecraft/fluidmech/client/render/RenderSink.java b/src/minecraft/fluidmech/client/render/RenderSink.java index 252d41e5..313422fc 100644 --- a/src/minecraft/fluidmech/client/render/RenderSink.java +++ b/src/minecraft/fluidmech/client/render/RenderSink.java @@ -8,7 +8,7 @@ import org.lwjgl.opengl.GL11; import fluidmech.client.model.ModelSink; import fluidmech.common.FluidMech; -import fluidmech.common.machines.TileEntitySink; +import fluidmech.common.tiles.TileEntitySink; public class RenderSink extends TileEntitySpecialRenderer { diff --git a/src/minecraft/fluidmech/client/render/RenderTank.java b/src/minecraft/fluidmech/client/render/RenderTank.java index bdfeaaaf..4fe80143 100644 --- a/src/minecraft/fluidmech/client/render/RenderTank.java +++ b/src/minecraft/fluidmech/client/render/RenderTank.java @@ -12,7 +12,7 @@ import org.lwjgl.opengl.GL11; import fluidmech.client.model.ModelLiquidTank; import fluidmech.client.model.ModelLiquidTankCorner; import fluidmech.common.FluidMech; -import fluidmech.common.machines.TileEntityTank; +import fluidmech.common.tiles.TileEntityTank; public class RenderTank extends TileEntitySpecialRenderer { diff --git a/src/minecraft/fluidmech/common/FluidMech.java b/src/minecraft/fluidmech/common/FluidMech.java index 3ecf867e..820f146d 100644 --- a/src/minecraft/fluidmech/common/FluidMech.java +++ b/src/minecraft/fluidmech/common/FluidMech.java @@ -11,9 +11,6 @@ import fluidmech.common.item.ItemBlockTank; import fluidmech.common.item.ItemParts; import fluidmech.common.item.ItemParts.Parts; import fluidmech.common.item.ItemTools; -import fluidmech.common.machines.TileEntityReleaseValve; -import fluidmech.common.machines.TileEntitySink; -import fluidmech.common.machines.TileEntityTank; import fluidmech.common.machines.mech.BlockGenerator; import fluidmech.common.machines.mech.BlockRod; import fluidmech.common.machines.mech.TileEntityGenerator; @@ -27,6 +24,9 @@ import fluidmech.common.pump.BlockPumpMachine; import fluidmech.common.pump.TileEntityConstructionPump; import fluidmech.common.pump.TileEntityDrain; import fluidmech.common.pump.TileEntityStarterPump; +import fluidmech.common.tiles.TileEntityReleaseValve; +import fluidmech.common.tiles.TileEntitySink; +import fluidmech.common.tiles.TileEntityTank; import hydraulic.api.ColorCode; import hydraulic.helpers.FluidHelper; diff --git a/src/minecraft/fluidmech/common/block/BlockReleaseValve.java b/src/minecraft/fluidmech/common/block/BlockReleaseValve.java index 3b15a6bb..723e92d0 100644 --- a/src/minecraft/fluidmech/common/block/BlockReleaseValve.java +++ b/src/minecraft/fluidmech/common/block/BlockReleaseValve.java @@ -11,7 +11,7 @@ import net.minecraft.world.World; import universalelectricity.prefab.block.BlockAdvanced; import fluidmech.common.FluidMech; import fluidmech.common.TabFluidMech; -import fluidmech.common.machines.TileEntityReleaseValve; +import fluidmech.common.tiles.TileEntityReleaseValve; public class BlockReleaseValve extends BlockAdvanced { diff --git a/src/minecraft/fluidmech/common/block/BlockSink.java b/src/minecraft/fluidmech/common/block/BlockSink.java index 2d13e5b8..cbbd5056 100644 --- a/src/minecraft/fluidmech/common/block/BlockSink.java +++ b/src/minecraft/fluidmech/common/block/BlockSink.java @@ -20,7 +20,7 @@ import universalelectricity.prefab.block.BlockAdvanced; import universalelectricity.prefab.tile.TileEntityAdvanced; import fluidmech.client.render.BlockRenderHelper; import fluidmech.common.TabFluidMech; -import fluidmech.common.machines.TileEntitySink; +import fluidmech.common.tiles.TileEntitySink; public class BlockSink extends BlockAdvanced { diff --git a/src/minecraft/fluidmech/common/block/BlockTank.java b/src/minecraft/fluidmech/common/block/BlockTank.java index 61398a0c..897659e5 100644 --- a/src/minecraft/fluidmech/common/block/BlockTank.java +++ b/src/minecraft/fluidmech/common/block/BlockTank.java @@ -18,7 +18,7 @@ import net.minecraftforge.liquids.LiquidStack; import universalelectricity.prefab.block.BlockAdvanced; import fluidmech.client.render.BlockRenderHelper; import fluidmech.common.TabFluidMech; -import fluidmech.common.machines.TileEntityTank; +import fluidmech.common.tiles.TileEntityTank; public class BlockTank extends BlockAdvanced { diff --git a/src/minecraft/fluidmech/common/machines/TileEntityReleaseValve.java b/src/minecraft/fluidmech/common/tiles/TileEntityReleaseValve.java similarity index 73% rename from src/minecraft/fluidmech/common/machines/TileEntityReleaseValve.java rename to src/minecraft/fluidmech/common/tiles/TileEntityReleaseValve.java index 323d7750..04e5b1c4 100644 --- a/src/minecraft/fluidmech/common/machines/TileEntityReleaseValve.java +++ b/src/minecraft/fluidmech/common/tiles/TileEntityReleaseValve.java @@ -1,10 +1,11 @@ -package fluidmech.common.machines; +package fluidmech.common.tiles; import fluidmech.common.machines.pipes.TileEntityPipe; import hydraulic.api.ColorCode; import hydraulic.api.IColorCoded; import hydraulic.api.IPipeConnection; import hydraulic.api.IReadOut; +import hydraulic.fluidnetwork.IFluidNetworkPart; import hydraulic.helpers.connectionHelper; import hydraulic.prefab.tile.TileEntityFluidDevice; @@ -25,8 +26,8 @@ public class TileEntityReleaseValve extends TileEntityFluidDevice implements IPi public boolean[] allowed = new boolean[ColorCode.values().length - 1]; public TileEntity[] connected = new TileEntity[6]; - private List output = new ArrayList(); - private List input = new ArrayList(); + private List output = new ArrayList(); + private ITankContainer[] input = new ITankContainer[6]; public boolean isPowered = false; @@ -56,20 +57,20 @@ public class TileEntityReleaseValve extends TileEntityFluidDevice implements IPi if (!this.worldObj.isRemote && !isPowered && this.ticks % 20 == 0) { - validateNBuildList(); + this.validateNBuildList(); // start the draining process - if (this.input.size() > 0 && this.output.size() > 0) + for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { - for (ITankContainer drainedTank : input) + ITankContainer drainedTank = input[dir.ordinal()]; + if (drainedTank != null) { - LiquidStack stack = drainedTank.drain(ForgeDirection.UNKNOWN, LiquidContainerRegistry.BUCKET_VOLUME, false); + LiquidStack stack = drainedTank.drain(dir.getOpposite(), LiquidContainerRegistry.BUCKET_VOLUME, false); if (stack != null && stack.amount > 0) { - TileEntityPipe inputPipe = this.findValidPipe(stack); + IFluidNetworkPart inputPipe = this.findValidPipe(stack); if (inputPipe != null) { - ILiquidTank pipeVolume = inputPipe.getTanks(ForgeDirection.UNKNOWN)[0]; - int ammountFilled = inputPipe.getNetwork().addFluidToNetwork(this, stack, true); + int ammountFilled = inputPipe.getNetwork().addFluidToNetwork((TileEntity) drainedTank, stack, true); drainedTank.drain(ForgeDirection.UNKNOWN, ammountFilled, true); } } @@ -80,10 +81,10 @@ public class TileEntityReleaseValve extends TileEntityFluidDevice implements IPi } /** used to find a valid pipe for filling of the liquid type */ - public TileEntityPipe findValidPipe(LiquidStack stack) + public IFluidNetworkPart findValidPipe(LiquidStack stack) { // find normal color selective pipe first - for (TileEntityPipe pipe : output) + for (IFluidNetworkPart pipe : output) { if (pipe.fill(ForgeDirection.UNKNOWN, stack, false) > 0) { @@ -135,46 +136,35 @@ public class TileEntityReleaseValve extends TileEntityFluidDevice implements IPi { // cleanup this.connected = connectionHelper.getSurroundingTileEntities(worldObj, xCoord, yCoord, zCoord); - this.input.clear(); + this.input = new ITankContainer[6]; this.output.clear(); // read surroundings - for (int i = 0; i < 6; i++) + for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { - ForgeDirection dir = ForgeDirection.getOrientation(i); - TileEntity ent = connected[i]; - if (ent instanceof TileEntityPipe) + TileEntity tileEntity = connected[dir.ordinal()]; + if (tileEntity instanceof IFluidNetworkPart) { - TileEntityPipe pipe = (TileEntityPipe) ent; - ILiquidTank tank = pipe.getTanks(ForgeDirection.UNKNOWN)[0]; - if (this.isRestricted() && this.canConnect(pipe.getColor())) - { - connected[i] = null; - } - else if (tank.getLiquid() != null && tank.getLiquid().amount >= tank.getCapacity()) - { - connected[i] = null; - } - else + IFluidNetworkPart pipe = (IFluidNetworkPart) tileEntity; + if (this.canConnect(pipe.getColor())) { this.output.add(pipe); } - } - else if (ent instanceof ITankContainer) - { - ILiquidTank[] tanks = ((ITankContainer) connected[i]).getTanks(dir); - for (int t = 0; t < tanks.length; t++) + else { - LiquidStack ll = tanks[t].getLiquid(); - if (ll != null && ll.amount > 0 && ll.amount > 0) - { - this.input.add((ITankContainer) ent); - break; - } + this.connected[dir.ordinal()] = null; + } + } + else if (tileEntity instanceof ITankContainer) + { + ITankContainer tank = (ITankContainer) tileEntity; + if (tank != null && tank.drain(dir.getOpposite(), LiquidContainerRegistry.BUCKET_VOLUME, false) != null) + { + this.input[dir.ordinal()] = (ITankContainer) tileEntity; } } else { - connected[i] = null; + connected[dir.ordinal()] = null; } } } diff --git a/src/minecraft/fluidmech/common/machines/TileEntitySink.java b/src/minecraft/fluidmech/common/tiles/TileEntitySink.java similarity index 98% rename from src/minecraft/fluidmech/common/machines/TileEntitySink.java rename to src/minecraft/fluidmech/common/tiles/TileEntitySink.java index ce065699..156df77d 100644 --- a/src/minecraft/fluidmech/common/machines/TileEntitySink.java +++ b/src/minecraft/fluidmech/common/tiles/TileEntitySink.java @@ -1,4 +1,4 @@ -package fluidmech.common.machines; +package fluidmech.common.tiles; import fluidmech.common.FluidMech; import hydraulic.api.ColorCode; diff --git a/src/minecraft/fluidmech/common/machines/TileEntityTank.java b/src/minecraft/fluidmech/common/tiles/TileEntityTank.java similarity index 99% rename from src/minecraft/fluidmech/common/machines/TileEntityTank.java rename to src/minecraft/fluidmech/common/tiles/TileEntityTank.java index 48abe179..f20e3c20 100644 --- a/src/minecraft/fluidmech/common/machines/TileEntityTank.java +++ b/src/minecraft/fluidmech/common/tiles/TileEntityTank.java @@ -1,4 +1,4 @@ -package fluidmech.common.machines; +package fluidmech.common.tiles; import fluidmech.common.FluidMech; import hydraulic.api.ColorCode;