From bee1facd1b8e78d4ef734a7b1986276133e9e980 Mon Sep 17 00:00:00 2001 From: kekzdealer Date: Thu, 10 Oct 2019 04:28:42 +0200 Subject: Implemented MultiHatch. Fixed all known bugs in the T.F.F.T's fluid handling. Fluid storage not yet persistent. --- .../java/tileentities/GTMTE_FluidMultiStorage.java | 74 +++++++++-- src/main/java/tileentities/TE_TFFTMultiHatch.java | 120 ++++++++++++++++++ src/main/java/tileentities/TFFTMultiHatch.java | 138 --------------------- 3 files changed, 185 insertions(+), 147 deletions(-) create mode 100644 src/main/java/tileentities/TE_TFFTMultiHatch.java delete mode 100644 src/main/java/tileentities/TFFTMultiHatch.java (limited to 'src/main/java/tileentities') diff --git a/src/main/java/tileentities/GTMTE_FluidMultiStorage.java b/src/main/java/tileentities/GTMTE_FluidMultiStorage.java index 32d17d1cf5..051f27047d 100644 --- a/src/main/java/tileentities/GTMTE_FluidMultiStorage.java +++ b/src/main/java/tileentities/GTMTE_FluidMultiStorage.java @@ -1,9 +1,10 @@ package tileentities; import java.util.ArrayList; +import java.util.HashSet; import java.util.Iterator; - import blocks.Block_TFFTCasing; +import blocks.Block_TFFTMultiHatch; import blocks.Block_TFFTStorageFieldBlockT1; import blocks.Block_TFFTStorageFieldBlockT2; import blocks.Block_TFFTStorageFieldBlockT3; @@ -39,9 +40,11 @@ public class GTMTE_FluidMultiStorage extends GT_MetaTileEntity_MultiBlockBase { private final Block STORAGE_FIELD2 = Block_TFFTStorageFieldBlockT2.getInstance(); private final Block STORAGE_FIELD3 = Block_TFFTStorageFieldBlockT3.getInstance(); private final Block STORAGE_FIELD4 = Block_TFFTStorageFieldBlockT4.getInstance(); + private final Block MULTI_HATCH = Block_TFFTMultiHatch.getInstance(); private final int CASING_TEXTURE_ID = 176; private MultiFluidHandler mfh; + private HashSet multiHatches = new HashSet<>(); private int runningCost = 0; private boolean doVoidExcess = false; @@ -115,7 +118,10 @@ public class GTMTE_FluidMultiStorage extends GT_MetaTileEntity_MultiBlockBase { this.mEUt = runningCost; super.mMaxProgresstime = 10; - // TODO skip all of the currently existing code in here when there are only multi hatches + // If there are no basic I/O hatches, let multi hatches handle it and skip a lot of code! + if(multiHatches.size() > 0 && super.mInputHatches.size() == 0 && super.mOutputHatches.size() == 0) { + return true; + } // Suck in fluids final ArrayList inputHatchFluids = super.getStoredFluids(); @@ -123,7 +129,7 @@ public class GTMTE_FluidMultiStorage extends GT_MetaTileEntity_MultiBlockBase { for(FluidStack fluidStack : inputHatchFluids) { - final int pushed = mfh.pushFluid(fluidStack); + final int pushed = mfh.pushFluid(fluidStack, true); final FluidStack toDeplete = fluidStack.copy(); toDeplete.amount = pushed; super.depleteInput(toDeplete); @@ -153,11 +159,11 @@ public class GTMTE_FluidMultiStorage extends GT_MetaTileEntity_MultiBlockBase { possibleOutput += outputHatch.getCapacity() - outputHatch.getFluidAmount(); } } - + System.out.println("Output Capacity: " + possibleOutput); // Output as much as possible final FluidStack tempStack = storedFluid.copy(); tempStack.amount = possibleOutput; - possibleOutput = mfh.pullFluid(tempStack, config); + tempStack.amount = mfh.pullFluid(tempStack, config, true); super.addOutput(tempStack); } else { @@ -179,7 +185,7 @@ public class GTMTE_FluidMultiStorage extends GT_MetaTileEntity_MultiBlockBase { final FluidStack tempStack = storedFluid.copy(); tempStack.amount = possibleOutput; // TODO possible concurrent modification exception as pullFluid calls remove() without an iterator - possibleOutput = mfh.pullFluid(tempStack); + tempStack.amount = mfh.pullFluid(tempStack, true); super.addOutput(tempStack); } } @@ -187,6 +193,16 @@ public class GTMTE_FluidMultiStorage extends GT_MetaTileEntity_MultiBlockBase { return true; } + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + + if(mfh != null) { + mfh.setLock(!super.getBaseMetaTileEntity().isActive()); + } + + } + public Vector3ic rotateOffsetVector(Vector3ic forgeDirection, int x, int y, int z) { final Vector3i offset = new Vector3i(); @@ -221,7 +237,18 @@ public class GTMTE_FluidMultiStorage extends GT_MetaTileEntity_MultiBlockBase { return offset; } - + + /** + * Checks structural integrity and registers machine parts. + * Appears to often not run but can be jump started by forcing a block update on the controller. + * (Place a piece of dirt on the front face and remove it again. Dirty fix lol.) + * + * @param thisController + * Object reference to this controller block's Tile Entity. + * @param guiSlotItem + * References the item stack that can be placed in that GUI slot + * in the top right. + */ @Override public boolean checkMachine(IGregTechTileEntity thisController, ItemStack guiSlotItem) { try { @@ -257,10 +284,19 @@ public class GTMTE_FluidMultiStorage extends GT_MetaTileEntity_MultiBlockBase { && !super.addEnergyInputToMachineList(currentTE, CASING_TEXTURE_ID)) { // If it's not a hatch, is it the right casing for this machine? Check block and block meta. + // Also check for multi hatch if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == CASING) { // Seems to be valid casing. Decrement counter. minCasingAmount--; - } else { + } else if(thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == MULTI_HATCH) { + final TE_TFFTMultiHatch mh = + (TE_TFFTMultiHatch) thisController.getWorld().getTileEntity( + thisController.getXCoord() + offset.x(), + thisController.getYCoord() + offset.y(), + thisController.getZCoord() + offset.z()); + multiHatches.add(mh); + } + else { formationChecklist = false; } } @@ -326,9 +362,17 @@ public class GTMTE_FluidMultiStorage extends GT_MetaTileEntity_MultiBlockBase { && !super.addOutputToMachineList(currentTE, CASING_TEXTURE_ID)) { // If it's not a hatch, is it the right casing for this machine? Check block and block meta. + // Also check for multi hatch if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == CASING) { // Seems to be valid casing. Decrement counter. minCasingAmount--; + } else if(thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == MULTI_HATCH) { + final TE_TFFTMultiHatch mh = + (TE_TFFTMultiHatch) thisController.getWorld().getTileEntity( + thisController.getXCoord() + offset.x(), + thisController.getYCoord() + offset.y(), + thisController.getZCoord() + offset.z()); + multiHatches.add(mh); } else if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()).getUnlocalizedName().equals(glassNameAE2) || thisController.getBlockOffset(offset.x(), offset.y(), offset.z()).getUnlocalizedName().equals(glassNameStained)) { // do nothing lol @@ -341,7 +385,7 @@ public class GTMTE_FluidMultiStorage extends GT_MetaTileEntity_MultiBlockBase { } } - // Front slice + // Back slice for(int X = -2; X <= 2; X++) { for(int Y = -2; Y <= 2; Y++) { // Get next TE @@ -361,6 +405,13 @@ public class GTMTE_FluidMultiStorage extends GT_MetaTileEntity_MultiBlockBase { if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == CASING) { // Seems to be valid casing. Decrement counter. minCasingAmount--; + } else if(thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == MULTI_HATCH) { + final TE_TFFTMultiHatch mh = + (TE_TFFTMultiHatch) thisController.getWorld().getTileEntity( + thisController.getXCoord() + offset.x(), + thisController.getYCoord() + offset.y(), + thisController.getZCoord() + offset.z()); + multiHatches.add(mh); } else { formationChecklist = false; } @@ -407,11 +458,15 @@ public class GTMTE_FluidMultiStorage extends GT_MetaTileEntity_MultiBlockBase { mfh = new MultiFluidHandler(capacityPerFluid, mfh.getFluids()); } } + for(TE_TFFTMultiHatch mh : multiHatches) { + mh.setMultiFluidHandler(mfh); + } } return formationChecklist; } catch (Exception ex) { System.err.println("CAUGHT CHECKMACHINE EXCEPTION"); + ex.printStackTrace(); } return false; } @@ -431,6 +486,7 @@ public class GTMTE_FluidMultiStorage extends GT_MetaTileEntity_MultiBlockBase { public String[] getInfoData() { final ArrayList ll = mfh.getInfoData(); + ll.add(EnumChatFormatting.YELLOW + "Operational Data:" + EnumChatFormatting.RESET); ll.add("Auto-voiding: " + doVoidExcess); ll.add("Per-Fluid Capacity: " + mfh.getCapacity() + "L"); ll.add("Running Cost: " + (-super.mEUt) + "EU/t"); diff --git a/src/main/java/tileentities/TE_TFFTMultiHatch.java b/src/main/java/tileentities/TE_TFFTMultiHatch.java new file mode 100644 index 0000000000..94d7d9283a --- /dev/null +++ b/src/main/java/tileentities/TE_TFFTMultiHatch.java @@ -0,0 +1,120 @@ +package tileentities; + +import java.util.List; + +import kekztech.MultiFluidHandler; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; + +public class TE_TFFTMultiHatch extends TileEntity implements IFluidHandler { + + private MultiFluidHandler mfh; + + public void setMultiFluidHandler(MultiFluidHandler mfh) { + this.mfh = mfh; + } + + @Override + public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { + return (mfh != null) ? mfh.pushFluid(resource, doFill) : 0; + } + + @Override + public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { + return (mfh != null) ? new FluidStack(resource.getFluid(), mfh.pullFluid(resource, doDrain)) : null; + } + + /** + * Drains fluid out of 0th internal tank. + * + * @param from + * Orientation the fluid is drained to. + * @param maxDrain + * Maximum amount of fluid to drain. + * @param doDrain + * If false, drain will only be simulated. + * @return FluidStack representing the Fluid and amount that was (or would have been, if + * simulated) drained. + */ + @Override + public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { + if(mfh != null) { + final FluidStack drain = mfh.getFluid(0); + if(drain != null) { + return new FluidStack( + drain.getFluid(), + mfh.pullFluid(new FluidStack(drain.getFluid(), maxDrain), 0, doDrain) + ); + } + } + return null; + } + + @Override + public boolean canFill(ForgeDirection from, Fluid fluid) { + return (mfh != null) ? mfh.couldPush(new FluidStack(fluid, 1)) : false; + } + + @Override + public boolean canDrain(ForgeDirection from, Fluid fluid) { + return (mfh != null) ? mfh.contains(new FluidStack(fluid, 1)) : false; + } + + @Override + public FluidTankInfo[] getTankInfo(ForgeDirection from) { + if(mfh == null) { + return null; + } + final List 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; + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + nbt = (nbt == null) ? new NBTTagCompound() : nbt; + + super.writeToNBT(nbt); + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + nbt = (nbt == null) ? new NBTTagCompound() : nbt; + + super.readFromNBT(nbt); + } + + + + + + + + + + + + + + + + + + + + + + + + + + +} diff --git a/src/main/java/tileentities/TFFTMultiHatch.java b/src/main/java/tileentities/TFFTMultiHatch.java deleted file mode 100644 index 2ce6f6985f..0000000000 --- a/src/main/java/tileentities/TFFTMultiHatch.java +++ /dev/null @@ -1,138 +0,0 @@ -package tileentities; - -import gregtech.api.enums.Textures.BlockIcons; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; -import gregtech.api.objects.GT_RenderedTexture; -import kekztech.MultiFluidHandler; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; - -public class TFFTMultiHatch extends GT_MetaTileEntity_Hatch { - - private MultiFluidHandler multiFluidHandler; - - public TFFTMultiHatch(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 3, - new String[]{"Exclusive fluid I/O for the T.F.F.T", "Capacity: " + 8000 * (aTier + 1) + "L"}, new ITexture[0]); - } - - public TFFTMultiHatch(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 3, aDescription, aTextures); - } - - public TFFTMultiHatch(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 3, aDescription, aTextures); - } - - public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(BlockIcons.OVERLAY_PIPE_IN)}; - } - - public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(BlockIcons.OVERLAY_PIPE_IN)}; - } - - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new TFFTMultiHatch(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); - } - - public boolean isSimpleMachine() { - return true; - } - - public boolean isFacingValid(byte aFacing) { - return true; - } - - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } - - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } else { - return true; - } - } - - public boolean doesFillContainers() { - return false; - } - - public boolean doesEmptyContainers() { - return false; - } - - public boolean canTankBeFilled() { - return true; - } - - public boolean canTankBeEmptied() { - return true; - } - - public boolean displaysItemStack() { - return false; - } - - public boolean displaysStackSize() { - return false; - } - - public boolean isFluidInputAllowed(FluidStack aFluid) { - return (multiFluidHandler != null) ? multiFluidHandler.couldPush(aFluid) : false; - } - - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return false; - } - - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return false; - } - - public int getCapacity() { - return (multiFluidHandler != null) ? multiFluidHandler.getCapacity() : 0; - } - - public int getTankPressure() { - return -100; - } - - public void setMultiFluidHandler(MultiFluidHandler multiFluidHandler) { - this.multiFluidHandler = multiFluidHandler; - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - -} -- cgit