diff options
Diffstat (limited to 'src')
4 files changed, 53 insertions, 113 deletions
diff --git a/src/main/java/common/tileentities/GTMTE_FluidMultiStorage.java b/src/main/java/common/tileentities/GTMTE_FluidMultiStorage.java index e06d1cc4a6..bd992972a8 100644 --- a/src/main/java/common/tileentities/GTMTE_FluidMultiStorage.java +++ b/src/main/java/common/tileentities/GTMTE_FluidMultiStorage.java @@ -138,7 +138,7 @@ public class GTMTE_FluidMultiStorage extends GT_MetaTileEntity_MultiBlockBase { // Push out fluids if (guiSlotItem != null && guiSlotItem.getUnlocalizedName().equals("gt.integrated_circuit")) { - final FluidStack storedFluid = mfh.getFluid(fluidSelector); + final FluidStack storedFluid = mfh.getFluidCopy(fluidSelector); // Sum available output capacity int possibleOutput = 0; for (GT_MetaTileEntity_Hatch_Output outputHatch : super.mOutputHatches) { diff --git a/src/main/java/common/tileentities/GTMTE_TFFTMultiHatch.java b/src/main/java/common/tileentities/GTMTE_TFFTMultiHatch.java index f34905ba14..f93bafbead 100644 --- a/src/main/java/common/tileentities/GTMTE_TFFTMultiHatch.java +++ b/src/main/java/common/tileentities/GTMTE_TFFTMultiHatch.java @@ -153,7 +153,7 @@ public class GTMTE_TFFTMultiHatch extends GT_MetaTileEntity_Hatch { */ private void fillContainers(IGregTechTileEntity aBaseMetaTileEntity) { final ItemStack cellFromFluid = GT_Utility.fillFluidContainer( - mfh.getFluid(mfh.getSelectedFluid()), super.mInventory[super.getInputSlot()], false, true); + mfh.getFluidCopy(mfh.getSelectedFluid()), super.mInventory[super.getInputSlot()], false, true); // Check if cell is not null and if there is space for the filled container if (cellFromFluid != null && aBaseMetaTileEntity.addStackToSlot(super.getOutputSlot(), cellFromFluid, 1)) { // Convert back to FluidStack to learn the container capacity... @@ -171,14 +171,28 @@ public class GTMTE_TFFTMultiHatch extends GT_MetaTileEntity_Hatch { * this MetaTileEntity */ private void doAutoOutputPerSecond(IGregTechTileEntity aBaseMetaTileEntity) { - final ForgeDirection side = ForgeDirection.getOrientation(aBaseMetaTileEntity.getFrontFacing()); - final TileEntity adjacentTE = aBaseMetaTileEntity.getTileEntityOffset(side.offsetX, side.offsetY, side.offsetZ); + final ForgeDirection outSide = ForgeDirection.getOrientation(aBaseMetaTileEntity.getFrontFacing()); + final TileEntity adjacentTE = aBaseMetaTileEntity.getTileEntityOffset(outSide.offsetX, outSide.offsetY, outSide.offsetZ); if(adjacentTE instanceof IFluidHandler) { - final IFluidHandler adj = (IFluidHandler) adjacentTE; - final int outputPerSec = vals.get(super.mTier); + final IFluidHandler adjFH = (IFluidHandler) adjacentTE; // Cycle through fluids - for(int i = 0; i < mfh.getInfoData().size(); i++) { - final FluidStack storedFluid = mfh.getFluid(i); + for(int i = 0; i < mfh.getDistinctFluids(); i++) { + final FluidStack fluidCopy = mfh.getFluidCopy(i); + // Make sure the adjacent IFluidHandler can accept this fluid + if(adjFH.canFill(outSide.getOpposite(), fluidCopy.getFluid())) { + + // Limit to output rate + fluidCopy.amount = Math.min(fluidCopy.amount, vals.get(super.mTier)); + + // Test how much can be drawn + fluidCopy.amount = mfh.pullFluid(fluidCopy, false); + + // Test how much can be filled (and fill if possible) + fluidCopy.amount = adjFH.fill(outSide.getOpposite(), fluidCopy, true); + + // Actually deplete storage + mfh.pullFluid(fluidCopy, true); + } } } @@ -211,7 +225,7 @@ public class GTMTE_TFFTMultiHatch extends GT_MetaTileEntity_Hatch { @Override public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { if(mfh != null) { - final FluidStack drain = mfh.getFluid(0); + final FluidStack drain = mfh.getFluidCopy(0); if(drain != null) { // If there's no integrated circuit in the T.F.F.T. controller, output slot 0 final byte selectedSlot = (mfh.getSelectedFluid() == -1) ? 0 : mfh.getSelectedFluid(); diff --git a/src/main/java/common/tileentities/TE_TFFTMultiHatch.java b/src/main/java/common/tileentities/TE_TFFTMultiHatch.java index 29370dc4f2..de274bb15e 100644 --- a/src/main/java/common/tileentities/TE_TFFTMultiHatch.java +++ b/src/main/java/common/tileentities/TE_TFFTMultiHatch.java @@ -1,11 +1,6 @@ package common.tileentities; -import java.util.Iterator; -import java.util.List; - -import common.Blocks; import kekztech.MultiFluidHandler; -import net.minecraft.block.Block; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; @@ -48,88 +43,19 @@ public class TE_TFFTMultiHatch extends TileEntity implements IFluidHandler { @Override public void updateEntity() { - if(!autoOutput || mfh == null) { - return; - } - - tickCounter++; - if(tickCounter >= 20) { - - final ForgeDirection d = getOutwardsFacingDirection(); - if(d == ForgeDirection.UNKNOWN) { - return; - } - final TileEntity t = this.getWorldObj().getTileEntity( - this.xCoord + d.offsetX, - this.yCoord + d.offsetY, - this.zCoord + d.offsetZ - ); - - if(t instanceof IFluidHandler) { - - final IFluidHandler fh = (IFluidHandler) t; - final int meta = t.getWorldObj().getBlockMetadata(t.xCoord, t.yCoord, t.zCoord); - // Cycle through fluids - for (FluidStack volume : mfh.getFluids()) { - // Remember for later - final int oVolume = volume.amount; - - // Use API methods - if (fh.canFill(d.getOpposite(), volume.getFluid())) { - - // Test how much can be output - final FluidStack copy = volume.copy(); - copy.amount = (int) Math.min(copy.amount, BASE_OUTPUT_PER_SECOND * Math.pow(10, meta)); - - // How much is drawn - copy.amount = mfh.pullFluid(copy, false); - - // Test how much can be filled (and fill if possible) - copy.amount = fh.fill(d.getOpposite(), copy, true); - - // Actually deplete storage - mfh.pullFluid(copy, true); - - // Prevent ConcurrentModificationException - if (copy.amount >= oVolume) { - break; - } - } - } - } - - tickCounter = 0; - } - } - - private ForgeDirection getOutwardsFacingDirection() { - // TODO Revisit this once the hatch has a facing side - // Look up which side has the storage field block and choose the other side. - // This is important so the tank doesn't output into itself in case - // there is another hatch next to this one. - for(ForgeDirection direction : ForgeDirection.values()) { - - final Block b = this.getWorldObj().getBlock(this.xCoord + direction.offsetX, this.yCoord + direction.offsetY, this.zCoord + direction.offsetZ); - if(b != null && ( - b.equals(Blocks.tfftStorageField1) - || b.equals(Blocks.tfftStorageField2) - || b.equals(Blocks.tfftStorageField3) - || b.equals(Blocks.tfftStorageField4) - || b.equals(Blocks.tfftStorageField5))) { - return direction.getOpposite(); - } - } - return ForgeDirection.UNKNOWN; + // Removed deprecated code } @Override public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { - return (mfh != null) ? mfh.pushFluid(resource, doFill) : 0; + // Removed deprecated code + return 0; } @Override public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { - return (mfh != null) ? new FluidStack(resource.getFluid(), mfh.pullFluid(resource, doDrain)) : null; + // Removed deprecated code + return null; } /** @@ -148,42 +74,26 @@ public class TE_TFFTMultiHatch extends TileEntity implements IFluidHandler { */ @Override public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { - if(mfh != null) { - final FluidStack drain = mfh.getFluid(0); - if(drain != null) { - // If there's no integrated circuit in the T.F.F.T. controller, output slot 0 - final byte selectedSlot = (mfh.getSelectedFluid() == -1) ? 0 : mfh.getSelectedFluid(); - - return new FluidStack( - drain.getFluid(), - mfh.pullFluid(new FluidStack(drain.getFluid(), maxDrain), selectedSlot, doDrain) - ); - } - } + // Removed deprecated code return null; } @Override public boolean canFill(ForgeDirection from, Fluid fluid) { - return (mfh != null) && mfh.couldPush(new FluidStack(fluid, 1)); + // Removed deprecated code + return false; } @Override public boolean canDrain(ForgeDirection from, Fluid fluid) { - return (mfh != null) && mfh.contains(new FluidStack(fluid, 1)); + // Removed deprecated code + return false; } @Override public FluidTankInfo[] getTankInfo(ForgeDirection from) { - if(mfh == null) { - return null; - } - final List<FluidStack> fluids = mfh.getFluids(); - final FluidTankInfo[] tankInfo = new FluidTankInfo[fluids.size()]; - for(int i = 0; i < tankInfo.length; i++) { - tankInfo[i] = new FluidTankInfo(fluids.get(i), mfh.getCapacity()); - } - return tankInfo; + // Removed deprecated code + return null; } @Override diff --git a/src/main/java/kekztech/MultiFluidHandler.java b/src/main/java/kekztech/MultiFluidHandler.java index b90d8a35bf..3e9bcfa0e5 100644 --- a/src/main/java/kekztech/MultiFluidHandler.java +++ b/src/main/java/kekztech/MultiFluidHandler.java @@ -70,11 +70,27 @@ public class MultiFluidHandler { public int getCapacity() { return capacityPerFluid; } - - public FluidStack getFluid(int slot) { + + /** + * Returns a deep copy of the the FluidStack in the requested slot + * @param slot + * requested slot + * @return + * deep copy of the requested FluidStack + */ + public FluidStack getFluidCopy(int slot) { return (!locked && fluids.size() > 0 && slot >= 0 && slot < MAX_DISTINCT_FLUIDS) ? fluids.get(slot).copy() : null; } + + /** + * Returns the amount of different fluids currently stored. + * @return + * amount of different fluids currently stored (0-25) + */ + public int getDistinctFluids() { + return fluids.size(); + } public NBTTagCompound saveNBTData(NBTTagCompound nbt) { nbt = (nbt == null) ? new NBTTagCompound() : nbt; |