diff options
author | miozune <miozune@gmail.com> | 2022-10-09 18:10:02 +0900 |
---|---|---|
committer | miozune <miozune@gmail.com> | 2022-10-09 18:10:02 +0900 |
commit | a265085bd7742ebf1e2e95e4bf7397ba5bea01dc (patch) | |
tree | 92d6b48c083729e8952f0d02372682393145792e /src/main/java/common/tileentities | |
parent | 46bafc67d318bbe7c5ffbb34d857958ebe72a6e5 (diff) | |
download | GT5-Unofficial-a265085bd7742ebf1e2e95e4bf7397ba5bea01dc.tar.gz GT5-Unofficial-a265085bd7742ebf1e2e95e4bf7397ba5bea01dc.tar.bz2 GT5-Unofficial-a265085bd7742ebf1e2e95e4bf7397ba5bea01dc.zip |
updateBuildScript & spotlessApply
Diffstat (limited to 'src/main/java/common/tileentities')
15 files changed, 2079 insertions, 1842 deletions
diff --git a/src/main/java/common/tileentities/GTMTE_FluidMultiStorage.java b/src/main/java/common/tileentities/GTMTE_FluidMultiStorage.java index a73943b618..df60be8362 100644 --- a/src/main/java/common/tileentities/GTMTE_FluidMultiStorage.java +++ b/src/main/java/common/tileentities/GTMTE_FluidMultiStorage.java @@ -11,519 +11,552 @@ import gregtech.api.metatileentity.implementations.*; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Utility; +import java.util.ArrayList; +import java.util.HashSet; import kekztech.MultiFluidHandler; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import util.Vector3i; import util.Vector3ic; -import java.util.ArrayList; -import java.util.HashSet; - public class GTMTE_FluidMultiStorage extends GT_MetaTileEntity_TooltipMultiBlockBase { - private final static String glassNameIC2Reinforced = "blockAlloyGlass"; - private final static Block CASING = Blocks.tfftCasing; - private final static Block_TFFTStorageFieldBlockT1 STORAGE_FIELD1 = (Block_TFFTStorageFieldBlockT1) Blocks.tfftStorageField1; - private final static Block_TFFTStorageFieldBlockT2 STORAGE_FIELD2 = (Block_TFFTStorageFieldBlockT2) Blocks.tfftStorageField2; - private final static Block_TFFTStorageFieldBlockT3 STORAGE_FIELD3 = (Block_TFFTStorageFieldBlockT3) Blocks.tfftStorageField3; - private final static Block_TFFTStorageFieldBlockT4 STORAGE_FIELD4 = (Block_TFFTStorageFieldBlockT4) Blocks.tfftStorageField4; - private final static Block_TFFTStorageFieldBlockT5 STORAGE_FIELD5 = (Block_TFFTStorageFieldBlockT5) Blocks.tfftStorageField5; - private final static int CASING_TEXTURE_ID = 176; - - private MultiFluidHandler mfh; - private final HashSet<GTMTE_TFFTMultiHatch> sMultiHatches = new HashSet<>(); - - private int runningCost = 0; - private boolean doVoidExcess = false; - private byte fluidSelector = 0; - - public GTMTE_FluidMultiStorage(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - } + private static final String glassNameIC2Reinforced = "blockAlloyGlass"; + private static final Block CASING = Blocks.tfftCasing; + private static final Block_TFFTStorageFieldBlockT1 STORAGE_FIELD1 = + (Block_TFFTStorageFieldBlockT1) Blocks.tfftStorageField1; + private static final Block_TFFTStorageFieldBlockT2 STORAGE_FIELD2 = + (Block_TFFTStorageFieldBlockT2) Blocks.tfftStorageField2; + private static final Block_TFFTStorageFieldBlockT3 STORAGE_FIELD3 = + (Block_TFFTStorageFieldBlockT3) Blocks.tfftStorageField3; + private static final Block_TFFTStorageFieldBlockT4 STORAGE_FIELD4 = + (Block_TFFTStorageFieldBlockT4) Blocks.tfftStorageField4; + private static final Block_TFFTStorageFieldBlockT5 STORAGE_FIELD5 = + (Block_TFFTStorageFieldBlockT5) Blocks.tfftStorageField5; + private static final int CASING_TEXTURE_ID = 176; + + private MultiFluidHandler mfh; + private final HashSet<GTMTE_TFFTMultiHatch> sMultiHatches = new HashSet<>(); + + private int runningCost = 0; + private boolean doVoidExcess = false; + private byte fluidSelector = 0; + + public GTMTE_FluidMultiStorage(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } - public GTMTE_FluidMultiStorage(String aName) { - super(aName); - } + public GTMTE_FluidMultiStorage(String aName) { + super(aName); + } - @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity var1) { - return new GTMTE_FluidMultiStorage(super.mName); - } + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity var1) { + return new GTMTE_FluidMultiStorage(super.mName); + } @Override protected GT_Multiblock_Tooltip_Builder createTooltip() { final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType("Fluid Tank") - .addInfo("High-Tech fluid tank that can hold up to 25 different fluids!") - .addInfo("Has 1/25th of the total capacity as capacity for each fluid.") - .addInfo("Right clicking the controller with a screwdriver will turn on excess voiding.") - .addInfo("Fluid storage amount and running cost depends on the storage field blocks used.") - .addSeparator() - .addInfo("Note on hatch locking:") - .addInfo("Use an Integrated Circuit in the GUI slot to limit which fluid is output.") - .addInfo("The index of a stored fluid can be obtained through the Tricorder.") - .addSeparator() - .beginStructureBlock(5, 9, 5, false) - .addController("Top Center") - .addCasingInfo("T.F.F.T. Casing", 20) - .addOtherStructurePart("Storage Field Blocks (Tier I-V)", "Inner 3x7x3 solid pillar") - .addOtherStructurePart("IC2 Reinforced Glass", "Outer 5x7x5 glass shell") - .addMaintenanceHatch("Any top or bottom casing") - .addEnergyHatch("Any top or bottom casing") - .addInputHatch("Instead of any casing or glass, has to touch storage field block") - .addOutputHatch("Instead of any casing or glass, has to touch storage field block") - .addStructureInfo("You can have a bunch of hatches") - .addOtherStructurePart("Multi I/O Hatches", "Instead of any casing or glass, has to touch storage field block") - .addStructureInfo("Use MIOH with conduits or fluid storage busses to see all fluids at once. If it's fixed.") - .addStructureInfo("Ask someone else why there's 4 versions, with 2 uncraftable ones") - .toolTipFinisher("KekzTech"); + tt.addMachineType("Fluid Tank") + .addInfo("High-Tech fluid tank that can hold up to 25 different fluids!") + .addInfo("Has 1/25th of the total capacity as capacity for each fluid.") + .addInfo("Right clicking the controller with a screwdriver will turn on excess voiding.") + .addInfo("Fluid storage amount and running cost depends on the storage field blocks used.") + .addSeparator() + .addInfo("Note on hatch locking:") + .addInfo("Use an Integrated Circuit in the GUI slot to limit which fluid is output.") + .addInfo("The index of a stored fluid can be obtained through the Tricorder.") + .addSeparator() + .beginStructureBlock(5, 9, 5, false) + .addController("Top Center") + .addCasingInfo("T.F.F.T. Casing", 20) + .addOtherStructurePart("Storage Field Blocks (Tier I-V)", "Inner 3x7x3 solid pillar") + .addOtherStructurePart("IC2 Reinforced Glass", "Outer 5x7x5 glass shell") + .addMaintenanceHatch("Any top or bottom casing") + .addEnergyHatch("Any top or bottom casing") + .addInputHatch("Instead of any casing or glass, has to touch storage field block") + .addOutputHatch("Instead of any casing or glass, has to touch storage field block") + .addStructureInfo("You can have a bunch of hatches") + .addOtherStructurePart( + "Multi I/O Hatches", "Instead of any casing or glass, has to touch storage field block") + .addStructureInfo( + "Use MIOH with conduits or fluid storage busses to see all fluids at once. If it's fixed.") + .addStructureInfo("Ask someone else why there's 4 versions, with 2 uncraftable ones") + .toolTipFinisher("KekzTech"); return tt; } - @Override - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, - boolean aActive, boolean aRedstone) { - return aSide == aFacing - ? new ITexture[]{BlockIcons.casingTexturePages[1][48], - new GT_RenderedTexture(aActive - ? BlockIcons.OVERLAY_FRONT_LARGE_CHEMICAL_REACTOR_ACTIVE - : BlockIcons.OVERLAY_FRONT_LARGE_CHEMICAL_REACTOR)} - : new ITexture[]{BlockIcons.casingTexturePages[1][48]}; - } - - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), - "MultiblockDisplay.png"); - } - - @Override - public boolean isCorrectMachinePart(ItemStack var1) { - return true; - } - - @Override - public boolean checkRecipe(ItemStack guiSlotItem) { - - super.mEfficiency = 10000 - (super.getIdealStatus() - super.getRepairStatus()) * 1000; - super.mEfficiencyIncrease = 10000; - super.mEUt = runningCost; - super.mMaxProgresstime = 10; - - if(guiSlotItem != null && guiSlotItem.getUnlocalizedName().equals("gt.integrated_circuit")) { - this.fluidSelector = (byte) guiSlotItem.getItemDamage(); - } - - // If there are no basic I/O hatches, let multi hatches handle it and skip a lot of code! - if (sMultiHatches.size() > 0 && super.mInputHatches.size() == 0 && super.mOutputHatches.size() == 0) { - return true; - } - - // Suck in fluids - final ArrayList<FluidStack> inputHatchFluids = super.getStoredFluids(); - if (inputHatchFluids.size() > 0) { - - for (FluidStack fluidStack : inputHatchFluids) { - - final int pushed = mfh.pushFluid(fluidStack, true); - final FluidStack toDeplete = fluidStack.copy(); - toDeplete.amount = pushed; - super.depleteInput(toDeplete); - } - } - - // Push out fluids - if (guiSlotItem != null && guiSlotItem.getUnlocalizedName().equals("gt.integrated_circuit")) { - final FluidStack storedFluid = mfh.getFluidCopy(fluidSelector); - // Sum available output capacity - int possibleOutput = 0; - for (GT_MetaTileEntity_Hatch_Output outputHatch : super.mOutputHatches) { - if (outputHatch.isFluidLocked() && outputHatch.getLockedFluidName().equals(storedFluid.getUnlocalizedName())) { - possibleOutput += outputHatch.getCapacity() - outputHatch.getFluidAmount(); - } else if (outputHatch.getFluid() != null && outputHatch.getFluid().getUnlocalizedName().equals(storedFluid.getUnlocalizedName())) { - possibleOutput += outputHatch.getCapacity() - outputHatch.getFluidAmount(); - } else if (outputHatch.getFluid() == null) { - possibleOutput += outputHatch.getCapacity() - outputHatch.getFluidAmount(); - } - } - // Output as much as possible - final FluidStack tempStack = storedFluid.copy(); - tempStack.amount = possibleOutput; - tempStack.amount = mfh.pullFluid(tempStack, fluidSelector, true); - super.addOutput(tempStack); - - } else { - int tDistinct = mfh.getDistinctFluids(); - int tDistinctCount = 0; - int tMaxDistinct = mfh.getMaxDistinctFluids(); - for(int i = 0; i < tMaxDistinct && tDistinctCount< tDistinct;i++) { - final FluidStack storedFluidCopy = mfh.getFluidCopy(i); - if (storedFluidCopy == null) - continue; - tDistinctCount++; - storedFluidCopy.amount = 0; - // Calculate how much capacity all available Output Hatches offer - for (GT_MetaTileEntity_Hatch_Output outputHatch : super.mOutputHatches) { - if (outputHatch.isFluidLocked() && outputHatch.getLockedFluidName().equals(storedFluidCopy.getUnlocalizedName())) { - storedFluidCopy.amount += outputHatch.getCapacity() - outputHatch.getFluidAmount(); - addFluidToHatch(storedFluidCopy,outputHatch); - } else if (outputHatch.getFluid() != null && outputHatch.getFluid().isFluidEqual(storedFluidCopy)) { - storedFluidCopy.amount += outputHatch.getCapacity() - outputHatch.getFluidAmount(); - addFluidToHatch(storedFluidCopy,outputHatch); - } else if (!outputHatch.isFluidLocked() && outputHatch.getFluid() == null) { - storedFluidCopy.amount += outputHatch.getCapacity() - outputHatch.getFluidAmount(); - addFluidToHatch(storedFluidCopy,outputHatch); - } - } - } - } - - return true; - } - - public void addFluidToHatch(FluidStack aFluid, GT_MetaTileEntity_Hatch_Output aHatch) { - aFluid.amount = mfh.pullFluid(aFluid, true); - aHatch.fill(aFluid,true); - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - - if (mfh != null) { - mfh.setLock(!super.getBaseMetaTileEntity().isActive()); - mfh.setFluidSelector(fluidSelector); - mfh.setDoVoidExcess(doVoidExcess); - } - } - - public Vector3ic rotateOffsetVector(Vector3ic forgeDirection, int x, int y, int z) { - final Vector3i offset = new Vector3i(); - - // either direction on z-axis - if (forgeDirection.x() == 0 && forgeDirection.z() == -1) { - offset.x = x; - offset.y = y; - offset.z = z; - } - if (forgeDirection.x() == 0 && forgeDirection.z() == 1) { - offset.x = -x; - offset.y = y; - offset.z = -z; - } - // either direction on x-axis - if (forgeDirection.x() == -1 && forgeDirection.z() == 0) { - offset.x = z; - offset.y = y; - offset.z = -x; - } - if (forgeDirection.x() == 1 && forgeDirection.z() == 0) { - offset.x = -z; - offset.y = y; - offset.z = x; - } - // either direction on y-axis - if (forgeDirection.y() == -1) { - offset.x = x; - offset.y = z; - offset.z = y; - } - - return offset; - } - - @Override - public boolean checkMachine(IGregTechTileEntity thisController, ItemStack guiSlotItem) { - // Figure out the vector for the direction the back face of the controller is facing - final Vector3ic forgeDirection = new Vector3i( - ForgeDirection.getOrientation(thisController.getBackFacing()).offsetX, - ForgeDirection.getOrientation(thisController.getBackFacing()).offsetY, - ForgeDirection.getOrientation(thisController.getBackFacing()).offsetZ - ); - int minCasingAmount = 20; - boolean formationChecklist = true; // If this is still true at the end, machine is good to go :) - float runningCostAcc = 0; - double fluidCapacityAcc = 0; - - sMultiHatches.clear(); - - // Front segment - for (int X = -2; X <= 2; X++) { - for (int Y = -2; Y <= 2; Y++) { - if (X == 0 && Y == 0) { - continue; // Skip controller - } - - // Get next TE - final Vector3ic offset = rotateOffsetVector(forgeDirection, X, Y, 0); - final IGregTechTileEntity currentTE = - thisController.getIGregTechTileEntityOffset(offset.x(), offset.y(), offset.z()); - - // Fluid hatches should touch the storage field. - // Maintenance/Energy hatch can go anywhere - if (X > -2 && X < 2 && Y > -2 && Y < 2) { - if (!super.addMaintenanceToMachineList(currentTE, CASING_TEXTURE_ID) - && !super.addInputToMachineList(currentTE, CASING_TEXTURE_ID) - && !super.addOutputToMachineList(currentTE, CASING_TEXTURE_ID) - && !super.addEnergyInputToMachineList(currentTE, CASING_TEXTURE_ID) - && !addMultiHatchToMachineList(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 { - formationChecklist = false; - } - } - } else { - if (!super.addMaintenanceToMachineList(currentTE, CASING_TEXTURE_ID) - && !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. - if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == CASING) { - // Seems to be valid casing. Decrement counter. - minCasingAmount--; - } else { - formationChecklist = false; - } - } - } - } - } - - // Middle seven long segment - for (int X = -2; X <= 2; X++) { - for (int Y = -2; Y <= 2; Y++) { - for (int Z = -1; Z >= -7; Z--) { - final Vector3ic offset = rotateOffsetVector(forgeDirection, X, Y, Z); - if (X > -2 && X < 2 && Y > -2 && Y < 2) { - if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()).getUnlocalizedName() - .equals(STORAGE_FIELD1.getUnlocalizedName())) { - runningCostAcc += 0.5f; - fluidCapacityAcc += (float) Block_TFFTStorageFieldBlockT1.getCapacity(); - } else if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()).getUnlocalizedName() - .equals(STORAGE_FIELD2.getUnlocalizedName())) { - runningCostAcc += 1.0f; - fluidCapacityAcc += (float) Block_TFFTStorageFieldBlockT2.getCapacity(); - } else if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()).getUnlocalizedName() - .equals(STORAGE_FIELD3.getUnlocalizedName())) { - runningCostAcc += 2.0f; - fluidCapacityAcc += (float) Block_TFFTStorageFieldBlockT3.getCapacity(); - } else if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()).getUnlocalizedName() - .equals(STORAGE_FIELD4.getUnlocalizedName())) { - runningCostAcc += 4.0f; - fluidCapacityAcc += (float) Block_TFFTStorageFieldBlockT4.getCapacity(); - } else if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()).getUnlocalizedName() - .equals(STORAGE_FIELD5.getUnlocalizedName())) { - runningCostAcc += 8.0f; - fluidCapacityAcc += (float) Block_TFFTStorageFieldBlockT5.getCapacity(); - } else { - formationChecklist = false; - } - continue; - } - - // Get next TE - final IGregTechTileEntity currentTE = - thisController.getIGregTechTileEntityOffset(offset.x(), offset.y(), offset.z()); - - // Corner allows only glass - if (X == -2 && Y == -2 || X == 2 && Y == 2 || X == -2 && Y == 2 || X == 2 && Y == -2) { - if (!(thisController.getBlockOffset(offset.x(), offset.y(), offset.z()).getUnlocalizedName().equals(glassNameIC2Reinforced))) { - formationChecklist = false; - } - } else { - // Tries to add TE as either of those kinds of hatches. - // The number is the texture index number for the texture that needs to be painted over the hatch texture (TAE for GT++) - if (!super.addInputToMachineList(currentTE, CASING_TEXTURE_ID) - && !super.addOutputToMachineList(currentTE, CASING_TEXTURE_ID) - && !addMultiHatchToMachineList(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()).getUnlocalizedName().equals(glassNameIC2Reinforced)) { - formationChecklist = false; - } - } - } - } - } - } - - // Back segment - for (int X = -2; X <= 2; X++) { - for (int Y = -2; Y <= 2; Y++) { - // Get next TE - final Vector3ic offset = rotateOffsetVector(forgeDirection, X, Y, -8); - final IGregTechTileEntity currentTE = - thisController.getIGregTechTileEntityOffset(offset.x(), offset.y(), offset.z()); - - // Fluid hatches should touch the storage field. - // Maintenance/Energy hatch can go anywhere - if (X > -2 && X < 2 && Y > -2 && Y < 2) { - if (!super.addMaintenanceToMachineList(currentTE, CASING_TEXTURE_ID) - && !super.addInputToMachineList(currentTE, CASING_TEXTURE_ID) - && !super.addOutputToMachineList(currentTE, CASING_TEXTURE_ID) - && !super.addEnergyInputToMachineList(currentTE, CASING_TEXTURE_ID) - && !addMultiHatchToMachineList(currentTE, CASING_TEXTURE_ID)) { - - // If it's not a hatch, is it the right casing for this machine? Check block and block meta. - if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == CASING) { - // Seems to be valid casing. Decrement counter. - minCasingAmount--; - } else { - formationChecklist = false; - } - } - } else { - if (!super.addMaintenanceToMachineList(currentTE, CASING_TEXTURE_ID) - && !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. - if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == CASING) { - // Seems to be valid casing. Decrement counter. - minCasingAmount--; - } else { - formationChecklist = false; - } - } - } - } - } - - if (this.mEnergyHatches.size() < 1) { - formationChecklist = false; - } - - if (this.mMaintenanceHatches.size() != 1) { - formationChecklist = false; - } - - if (minCasingAmount > 0) { - formationChecklist = false; - } - - if (formationChecklist) { - runningCost = Math.round(-runningCostAcc); - // Update MultiFluidHandler in case storage cells have been changed - final int capacityPerFluid = (int) Math.round(fluidCapacityAcc / 25.0f); - if (mfh == null) { - mfh = MultiFluidHandler.newInstance(25, capacityPerFluid); - } else { - if (mfh.getCapacity() != capacityPerFluid) { - mfh = MultiFluidHandler.newAdjustedInstance(mfh, capacityPerFluid); - } - } - for (GTMTE_TFFTMultiHatch mh : sMultiHatches) { - mh.setMultiFluidHandler(mfh); - } - } - - return formationChecklist; - } - - public boolean addMultiHatchToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null) { - return false; - } else { - final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity == null) { - return false; - } else if (aMetaTileEntity instanceof GTMTE_TFFTMultiHatch) { - ((GTMTE_TFFTMultiHatch)aMetaTileEntity).updateTexture(aBaseCasingIndex); - return this.sMultiHatches.add((GTMTE_TFFTMultiHatch)aMetaTileEntity); - } else { - return false; - } - } - } - - @Override - public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - doVoidExcess = !doVoidExcess; - GT_Utility.sendChatToPlayer(aPlayer, doVoidExcess ? "Auto-voiding enabled" : "Auto-voiding disabled"); - } - - @Override - public String[] getInfoData() { - final ArrayList<String> 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: " - // mEUt does not naturally reflect efficiency status. Do that here. - + ((-super.mEUt) * 10000 / Math.max(1000, super.mEfficiency)) + "EU/t"); - ll.add("Maintenance Status: " + ((super.getRepairStatus() == super.getIdealStatus()) - ? EnumChatFormatting.GREEN + "Working perfectly" + EnumChatFormatting.RESET - : EnumChatFormatting.RED + "Has Problems" + EnumChatFormatting.RESET)); - ll.add("---------------------------------------------"); - - final String[] a = new String[ll.size()]; - return ll.toArray(a); - } - - @Override - public void saveNBTData(NBTTagCompound nbt) { - nbt = (nbt == null) ? new NBTTagCompound() : nbt; - - nbt.setInteger("runningCost", runningCost); - nbt.setBoolean("doVoidExcess", doVoidExcess); - - nbt.setInteger("capacityPerFluid", mfh.getCapacity()); - nbt.setTag("fluids", mfh.saveNBTData(new NBTTagCompound())); - - super.saveNBTData(nbt); - } - - @Override - public void loadNBTData(NBTTagCompound nbt) { - nbt = (nbt == null) ? new NBTTagCompound() : nbt; - - runningCost = nbt.getInteger("runningCost"); - doVoidExcess = nbt.getBoolean("doVoidExcess"); - - mfh = MultiFluidHandler.loadNBTData(nbt); - for (GTMTE_TFFTMultiHatch mh : sMultiHatches) { - mh.setMultiFluidHandler(mfh); - } - super.loadNBTData(nbt); - } - - @Override - public boolean isGivingInformation() { - return true; - } - - @Override - public int getMaxEfficiency(ItemStack var1) { - return 10000; - } - - @Override - public int getPollutionPerTick(ItemStack var1) { - return 0; - } - - @Override - public int getDamageToComponent(ItemStack var1) { - return 0; - } - - @Override - public boolean explodesOnComponentBreak(ItemStack var1) { - return false; - } + @Override + public ITexture[] getTexture( + IGregTechTileEntity aBaseMetaTileEntity, + byte aSide, + byte aFacing, + byte aColorIndex, + boolean aActive, + boolean aRedstone) { + return aSide == aFacing + ? new ITexture[] { + BlockIcons.casingTexturePages[1][48], + new GT_RenderedTexture( + aActive + ? BlockIcons.OVERLAY_FRONT_LARGE_CHEMICAL_REACTOR_ACTIVE + : BlockIcons.OVERLAY_FRONT_LARGE_CHEMICAL_REACTOR) + } + : new ITexture[] {BlockIcons.casingTexturePages[1][48]}; + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine( + aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), "MultiblockDisplay.png"); + } + + @Override + public boolean isCorrectMachinePart(ItemStack var1) { + return true; + } + + @Override + public boolean checkRecipe(ItemStack guiSlotItem) { + + super.mEfficiency = 10000 - (super.getIdealStatus() - super.getRepairStatus()) * 1000; + super.mEfficiencyIncrease = 10000; + super.mEUt = runningCost; + super.mMaxProgresstime = 10; + + if (guiSlotItem != null && guiSlotItem.getUnlocalizedName().equals("gt.integrated_circuit")) { + this.fluidSelector = (byte) guiSlotItem.getItemDamage(); + } + + // If there are no basic I/O hatches, let multi hatches handle it and skip a lot of code! + if (sMultiHatches.size() > 0 && super.mInputHatches.size() == 0 && super.mOutputHatches.size() == 0) { + return true; + } + + // Suck in fluids + final ArrayList<FluidStack> inputHatchFluids = super.getStoredFluids(); + if (inputHatchFluids.size() > 0) { + + for (FluidStack fluidStack : inputHatchFluids) { + + final int pushed = mfh.pushFluid(fluidStack, true); + final FluidStack toDeplete = fluidStack.copy(); + toDeplete.amount = pushed; + super.depleteInput(toDeplete); + } + } + + // Push out fluids + if (guiSlotItem != null && guiSlotItem.getUnlocalizedName().equals("gt.integrated_circuit")) { + final FluidStack storedFluid = mfh.getFluidCopy(fluidSelector); + // Sum available output capacity + int possibleOutput = 0; + for (GT_MetaTileEntity_Hatch_Output outputHatch : super.mOutputHatches) { + if (outputHatch.isFluidLocked() + && outputHatch.getLockedFluidName().equals(storedFluid.getUnlocalizedName())) { + possibleOutput += outputHatch.getCapacity() - outputHatch.getFluidAmount(); + } else if (outputHatch.getFluid() != null + && outputHatch.getFluid().getUnlocalizedName().equals(storedFluid.getUnlocalizedName())) { + possibleOutput += outputHatch.getCapacity() - outputHatch.getFluidAmount(); + } else if (outputHatch.getFluid() == null) { + possibleOutput += outputHatch.getCapacity() - outputHatch.getFluidAmount(); + } + } + // Output as much as possible + final FluidStack tempStack = storedFluid.copy(); + tempStack.amount = possibleOutput; + tempStack.amount = mfh.pullFluid(tempStack, fluidSelector, true); + super.addOutput(tempStack); + + } else { + int tDistinct = mfh.getDistinctFluids(); + int tDistinctCount = 0; + int tMaxDistinct = mfh.getMaxDistinctFluids(); + for (int i = 0; i < tMaxDistinct && tDistinctCount < tDistinct; i++) { + final FluidStack storedFluidCopy = mfh.getFluidCopy(i); + if (storedFluidCopy == null) continue; + tDistinctCount++; + storedFluidCopy.amount = 0; + // Calculate how much capacity all available Output Hatches offer + for (GT_MetaTileEntity_Hatch_Output outputHatch : super.mOutputHatches) { + if (outputHatch.isFluidLocked() + && outputHatch.getLockedFluidName().equals(storedFluidCopy.getUnlocalizedName())) { + storedFluidCopy.amount += outputHatch.getCapacity() - outputHatch.getFluidAmount(); + addFluidToHatch(storedFluidCopy, outputHatch); + } else if (outputHatch.getFluid() != null + && outputHatch.getFluid().isFluidEqual(storedFluidCopy)) { + storedFluidCopy.amount += outputHatch.getCapacity() - outputHatch.getFluidAmount(); + addFluidToHatch(storedFluidCopy, outputHatch); + } else if (!outputHatch.isFluidLocked() && outputHatch.getFluid() == null) { + storedFluidCopy.amount += outputHatch.getCapacity() - outputHatch.getFluidAmount(); + addFluidToHatch(storedFluidCopy, outputHatch); + } + } + } + } + + return true; + } + + public void addFluidToHatch(FluidStack aFluid, GT_MetaTileEntity_Hatch_Output aHatch) { + aFluid.amount = mfh.pullFluid(aFluid, true); + aHatch.fill(aFluid, true); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + + if (mfh != null) { + mfh.setLock(!super.getBaseMetaTileEntity().isActive()); + mfh.setFluidSelector(fluidSelector); + mfh.setDoVoidExcess(doVoidExcess); + } + } + + public Vector3ic rotateOffsetVector(Vector3ic forgeDirection, int x, int y, int z) { + final Vector3i offset = new Vector3i(); + + // either direction on z-axis + if (forgeDirection.x() == 0 && forgeDirection.z() == -1) { + offset.x = x; + offset.y = y; + offset.z = z; + } + if (forgeDirection.x() == 0 && forgeDirection.z() == 1) { + offset.x = -x; + offset.y = y; + offset.z = -z; + } + // either direction on x-axis + if (forgeDirection.x() == -1 && forgeDirection.z() == 0) { + offset.x = z; + offset.y = y; + offset.z = -x; + } + if (forgeDirection.x() == 1 && forgeDirection.z() == 0) { + offset.x = -z; + offset.y = y; + offset.z = x; + } + // either direction on y-axis + if (forgeDirection.y() == -1) { + offset.x = x; + offset.y = z; + offset.z = y; + } + + return offset; + } + + @Override + public boolean checkMachine(IGregTechTileEntity thisController, ItemStack guiSlotItem) { + // Figure out the vector for the direction the back face of the controller is facing + final Vector3ic forgeDirection = new Vector3i( + ForgeDirection.getOrientation(thisController.getBackFacing()).offsetX, + ForgeDirection.getOrientation(thisController.getBackFacing()).offsetY, + ForgeDirection.getOrientation(thisController.getBackFacing()).offsetZ); + int minCasingAmount = 20; + boolean formationChecklist = true; // If this is still true at the end, machine is good to go :) + float runningCostAcc = 0; + double fluidCapacityAcc = 0; + + sMultiHatches.clear(); + + // Front segment + for (int X = -2; X <= 2; X++) { + for (int Y = -2; Y <= 2; Y++) { + if (X == 0 && Y == 0) { + continue; // Skip controller + } + + // Get next TE + final Vector3ic offset = rotateOffsetVector(forgeDirection, X, Y, 0); + final IGregTechTileEntity currentTE = + thisController.getIGregTechTileEntityOffset(offset.x(), offset.y(), offset.z()); + + // Fluid hatches should touch the storage field. + // Maintenance/Energy hatch can go anywhere + if (X > -2 && X < 2 && Y > -2 && Y < 2) { + if (!super.addMaintenanceToMachineList(currentTE, CASING_TEXTURE_ID) + && !super.addInputToMachineList(currentTE, CASING_TEXTURE_ID) + && !super.addOutputToMachineList(currentTE, CASING_TEXTURE_ID) + && !super.addEnergyInputToMachineList(currentTE, CASING_TEXTURE_ID) + && !addMultiHatchToMachineList(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 { + formationChecklist = false; + } + } + } else { + if (!super.addMaintenanceToMachineList(currentTE, CASING_TEXTURE_ID) + && !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. + if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == CASING) { + // Seems to be valid casing. Decrement counter. + minCasingAmount--; + } else { + formationChecklist = false; + } + } + } + } + } + + // Middle seven long segment + for (int X = -2; X <= 2; X++) { + for (int Y = -2; Y <= 2; Y++) { + for (int Z = -1; Z >= -7; Z--) { + final Vector3ic offset = rotateOffsetVector(forgeDirection, X, Y, Z); + if (X > -2 && X < 2 && Y > -2 && Y < 2) { + if (thisController + .getBlockOffset(offset.x(), offset.y(), offset.z()) + .getUnlocalizedName() + .equals(STORAGE_FIELD1.getUnlocalizedName())) { + runningCostAcc += 0.5f; + fluidCapacityAcc += (float) Block_TFFTStorageFieldBlockT1.getCapacity(); + } else if (thisController + .getBlockOffset(offset.x(), offset.y(), offset.z()) + .getUnlocalizedName() + .equals(STORAGE_FIELD2.getUnlocalizedName())) { + runningCostAcc += 1.0f; + fluidCapacityAcc += (float) Block_TFFTStorageFieldBlockT2.getCapacity(); + } else if (thisController + .getBlockOffset(offset.x(), offset.y(), offset.z()) + .getUnlocalizedName() + .equals(STORAGE_FIELD3.getUnlocalizedName())) { + runningCostAcc += 2.0f; + fluidCapacityAcc += (float) Block_TFFTStorageFieldBlockT3.getCapacity(); + } else if (thisController + .getBlockOffset(offset.x(), offset.y(), offset.z()) + .getUnlocalizedName() + .equals(STORAGE_FIELD4.getUnlocalizedName())) { + runningCostAcc += 4.0f; + fluidCapacityAcc += (float) Block_TFFTStorageFieldBlockT4.getCapacity(); + } else if (thisController + .getBlockOffset(offset.x(), offset.y(), offset.z()) + .getUnlocalizedName() + .equals(STORAGE_FIELD5.getUnlocalizedName())) { + runningCostAcc += 8.0f; + fluidCapacityAcc += (float) Block_TFFTStorageFieldBlockT5.getCapacity(); + } else { + formationChecklist = false; + } + continue; + } + + // Get next TE + final IGregTechTileEntity currentTE = + thisController.getIGregTechTileEntityOffset(offset.x(), offset.y(), offset.z()); + + // Corner allows only glass + if (X == -2 && Y == -2 || X == 2 && Y == 2 || X == -2 && Y == 2 || X == 2 && Y == -2) { + if (!(thisController + .getBlockOffset(offset.x(), offset.y(), offset.z()) + .getUnlocalizedName() + .equals(glassNameIC2Reinforced))) { + formationChecklist = false; + } + } else { + // Tries to add TE as either of those kinds of hatches. + // The number is the texture index number for the texture that needs to be painted over the + // hatch texture (TAE for GT++) + if (!super.addInputToMachineList(currentTE, CASING_TEXTURE_ID) + && !super.addOutputToMachineList(currentTE, CASING_TEXTURE_ID) + && !addMultiHatchToMachineList(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()) + .getUnlocalizedName() + .equals(glassNameIC2Reinforced)) { + formationChecklist = false; + } + } + } + } + } + } + + // Back segment + for (int X = -2; X <= 2; X++) { + for (int Y = -2; Y <= 2; Y++) { + // Get next TE + final Vector3ic offset = rotateOffsetVector(forgeDirection, X, Y, -8); + final IGregTechTileEntity currentTE = + thisController.getIGregTechTileEntityOffset(offset.x(), offset.y(), offset.z()); + + // Fluid hatches should touch the storage field. + // Maintenance/Energy hatch can go anywhere + if (X > -2 && X < 2 && Y > -2 && Y < 2) { + if (!super.addMaintenanceToMachineList(currentTE, CASING_TEXTURE_ID) + && !super.addInputToMachineList(currentTE, CASING_TEXTURE_ID) + && !super.addOutputToMachineList(currentTE, CASING_TEXTURE_ID) + && !super.addEnergyInputToMachineList(currentTE, CASING_TEXTURE_ID) + && !addMultiHatchToMachineList(currentTE, CASING_TEXTURE_ID)) { + + // If it's not a hatch, is it the right casing for this machine? Check block and block meta. + if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == CASING) { + // Seems to be valid casing. Decrement counter. + minCasingAmount--; + } else { + formationChecklist = false; + } + } + } else { + if (!super.addMaintenanceToMachineList(currentTE, CASING_TEXTURE_ID) + && !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. + if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == CASING) { + // Seems to be valid casing. Decrement counter. + minCasingAmount--; + } else { + formationChecklist = false; + } + } + } + } + } + + if (this.mEnergyHatches.size() < 1) { + formationChecklist = false; + } + + if (this.mMaintenanceHatches.size() != 1) { + formationChecklist = false; + } + + if (minCasingAmount > 0) { + formationChecklist = false; + } + + if (formationChecklist) { + runningCost = Math.round(-runningCostAcc); + // Update MultiFluidHandler in case storage cells have been changed + final int capacityPerFluid = (int) Math.round(fluidCapacityAcc / 25.0f); + if (mfh == null) { + mfh = MultiFluidHandler.newInstance(25, capacityPerFluid); + } else { + if (mfh.getCapacity() != capacityPerFluid) { + mfh = MultiFluidHandler.newAdjustedInstance(mfh, capacityPerFluid); + } + } + for (GTMTE_TFFTMultiHatch mh : sMultiHatches) { + mh.setMultiFluidHandler(mfh); + } + } + + return formationChecklist; + } + + public boolean addMultiHatchToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } else if (aMetaTileEntity instanceof GTMTE_TFFTMultiHatch) { + ((GTMTE_TFFTMultiHatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); + return this.sMultiHatches.add((GTMTE_TFFTMultiHatch) aMetaTileEntity); + } else { + return false; + } + } + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + doVoidExcess = !doVoidExcess; + GT_Utility.sendChatToPlayer(aPlayer, doVoidExcess ? "Auto-voiding enabled" : "Auto-voiding disabled"); + } + + @Override + public String[] getInfoData() { + final ArrayList<String> 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: " + // mEUt does not naturally reflect efficiency status. Do that here. + + ((-super.mEUt) * 10000 / Math.max(1000, super.mEfficiency)) + "EU/t"); + ll.add("Maintenance Status: " + + ((super.getRepairStatus() == super.getIdealStatus()) + ? EnumChatFormatting.GREEN + "Working perfectly" + EnumChatFormatting.RESET + : EnumChatFormatting.RED + "Has Problems" + EnumChatFormatting.RESET)); + ll.add("---------------------------------------------"); + + final String[] a = new String[ll.size()]; + return ll.toArray(a); + } + + @Override + public void saveNBTData(NBTTagCompound nbt) { + nbt = (nbt == null) ? new NBTTagCompound() : nbt; + + nbt.setInteger("runningCost", runningCost); + nbt.setBoolean("doVoidExcess", doVoidExcess); + + nbt.setInteger("capacityPerFluid", mfh.getCapacity()); + nbt.setTag("fluids", mfh.saveNBTData(new NBTTagCompound())); + + super.saveNBTData(nbt); + } + + @Override + public void loadNBTData(NBTTagCompound nbt) { + nbt = (nbt == null) ? new NBTTagCompound() : nbt; + + runningCost = nbt.getInteger("runningCost"); + doVoidExcess = nbt.getBoolean("doVoidExcess"); + + mfh = MultiFluidHandler.loadNBTData(nbt); + for (GTMTE_TFFTMultiHatch mh : sMultiHatches) { + mh.setMultiFluidHandler(mfh); + } + super.loadNBTData(nbt); + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public int getMaxEfficiency(ItemStack var1) { + return 10000; + } + + @Override + public int getPollutionPerTick(ItemStack var1) { + return 0; + } + + @Override + public int getDamageToComponent(ItemStack var1) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack var1) { + return false; + } } diff --git a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java index 0e0dea54d0..703217ba05 100644 --- a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java +++ b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java @@ -1,5 +1,13 @@ package common.tileentities; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static common.itemBlocks.IB_LapotronicEnergyUnit.*; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_StructureUtility.filterByMTEClass; +import static java.lang.Math.max; +import static java.lang.Math.min; + import com.github.bartimaeusnek.bartworks.API.BorosilicateGlass; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoMulti; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoTunnel; @@ -7,14 +15,10 @@ import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_H import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyTunnel; import com.google.common.collect.ImmutableList; import com.gtnewhorizon.structurelib.StructureLibAPI; -import com.google.common.collect.ImmutableList; -import com.gtnewhorizon.structurelib.StructureLibAPI; import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; import com.gtnewhorizon.structurelib.alignment.constructable.ChannelDataAccessor; -import com.gtnewhorizon.structurelib.alignment.constructable.ConstructableUtility; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IItemSource; -import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.IStructureElement; import com.gtnewhorizon.structurelib.structure.IStructureElement.PlaceResult; @@ -35,6 +39,10 @@ import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Utility; import gregtech.api.util.IGT_HatchAdder; +import java.math.BigInteger; +import java.text.NumberFormat; +import java.util.*; +import java.util.function.Consumer; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -47,21 +55,9 @@ import net.minecraft.util.IChatComponent; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import java.math.BigInteger; -import java.text.NumberFormat; -import java.util.*; -import java.util.function.Consumer; - -import static com.google.common.math.LongMath.pow; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; -import static common.itemBlocks.IB_LapotronicEnergyUnit.*; -import static gregtech.api.enums.GT_HatchElement.Maintenance; -import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; -import static gregtech.api.util.GT_StructureUtility.filterByMTEClass; -import static java.lang.Math.max; -import static java.lang.Math.min; - -public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMultiBlockBase<GTMTE_LapotronicSuperCapacitor> implements IGlobalWirelessEnergy, ISurvivalConstructable { +public class GTMTE_LapotronicSuperCapacitor + extends GT_MetaTileEntity_EnhancedMultiBlockBase<GTMTE_LapotronicSuperCapacitor> + implements IGlobalWirelessEnergy, ISurvivalConstructable { private enum TopState { MayBeTop, Top, @@ -89,7 +85,9 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu private final int minimalGlassTier; private final BigInteger providedCapacity; static final Capacitor[] VALUES = values(); - static final Capacitor[] VALUES_BY_TIER = Arrays.stream(values()).sorted(Comparator.comparingInt(Capacitor::getMinimalGlassTier)).toArray(Capacitor[]::new); + static final Capacitor[] VALUES_BY_TIER = Arrays.stream(values()) + .sorted(Comparator.comparingInt(Capacitor::getMinimalGlassTier)) + .toArray(Capacitor[]::new); Capacitor(int minimalGlassTier, BigInteger providedCapacity) { this.minimalGlassTier = minimalGlassTier; @@ -119,83 +117,179 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu private static final String STRUCTURE_PIECE_TOP = "top"; private static final String STRUCTURE_PIECE_MID = "mid"; - private static final Block LSC_PART = Blocks.lscLapotronicEnergyUnit; - private static final Item LSC_PART_ITEM = Item.getItemFromBlock(LSC_PART); - private static final int CASING_META = 0; - private static final int CASING_TEXTURE_ID = (42 << 7) | 127; + private static final Block LSC_PART = Blocks.lscLapotronicEnergyUnit; + private static final Item LSC_PART_ITEM = Item.getItemFromBlock(LSC_PART); + private static final int CASING_META = 0; + private static final int CASING_TEXTURE_ID = (42 << 7) | 127; private static final int DURATION_AVERAGE_TICKS = 100; // height channel for height. // glass channel for glass // capacitor channel for capacitor, but it really just pick whatever capacitor it can find in survival - private static final IStructureDefinition<GTMTE_LapotronicSuperCapacitor> STRUCTURE_DEFINITION = IStructureDefinition.<GTMTE_LapotronicSuperCapacitor>builder() - .addShape(STRUCTURE_PIECE_BASE, transpose(new String[][]{ - {"bbbbb", "bbbbb", "bbbbb", "bbbbb", "bbbbb",}, - {"bb~bb", "bbbbb", "bbbbb", "bbbbb", "bbbbb",}, - })) - .addShape(STRUCTURE_PIECE_LAYER, transpose(new String[][]{ - {"ggggg", "gcccg", "gcccg", "gcccg", "ggggg",}, - })) - .addShape(STRUCTURE_PIECE_TOP, transpose(new String[][]{ - {"ggggg", "ggggg", "ggggg", "ggggg", "ggggg",}, - })) - .addShape(STRUCTURE_PIECE_MID, transpose(new String[][]{ - {"ggggg", "gCCCg", "gCCCg", "gCCCg", "ggggg",}, - })) - .addElement('b', buildHatchAdder(GTMTE_LapotronicSuperCapacitor.class) - .atLeast(LSCHatchElement.Energy, LSCHatchElement.Dynamo, Maintenance) - .hatchItemFilterAnd((t, h) -> ChannelDataAccessor.getChannelData(h, "glass") < 6 ? - filterByMTEClass(ImmutableList.of(GT_MetaTileEntity_Hatch_EnergyTunnel.class, GT_MetaTileEntity_Hatch_DynamoTunnel.class)).negate() : - s -> true) - .casingIndex(CASING_TEXTURE_ID) - .dot(1) - .buildAndChain(onElementPass(te -> te.casingAmount++, ofBlock(LSC_PART, CASING_META))) - ) - .addElement('g', withChannel("glass", BorosilicateGlass.ofBoroGlass((byte) -1, (te, t) -> te.glassTier = t, te -> te.glassTier))) - .addElement('c', ofChain( - onlyIf(te -> te.topState != TopState.NotTop, onElementPass(te -> te.topState = TopState.Top, withChannel("glass", BorosilicateGlass.ofBoroGlass((byte) -1, (te, t) -> te.glassTier = t, te -> te.glassTier)))), - onlyIf(te -> te.topState != TopState.Top, onElementPass(te -> te.topState = TopState.NotTop, - new IStructureElement<GTMTE_LapotronicSuperCapacitor>() { - @Override - public boolean check(GTMTE_LapotronicSuperCapacitor t, World world, int x, int y, int z) { - Block worldBlock = world.getBlock(x, y, z); - int meta = worldBlock.getDamageValue(world, x, y, z); - if (LSC_PART != worldBlock || meta == 0) - return false; - t.capacitors[meta - 1]++; - return true; - } - - private int getHint(ItemStack stack) { - return Capacitor.VALUES_BY_TIER[Math.min(Capacitor.VALUES_BY_TIER.length, ChannelDataAccessor.getChannelData(stack, "capacitor")) - 1].getMinimalGlassTier() + 1; - } - - @Override - public boolean spawnHint(GTMTE_LapotronicSuperCapacitor t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, LSC_PART, getHint(trigger)); - return true; - } - - @Override - public boolean placeBlock(GTMTE_LapotronicSuperCapacitor t, World world, int x, int y, int z, ItemStack trigger) { - world.setBlock(x, y, z, LSC_PART, getHint(trigger), 3); - return true; - } - - @Override - public PlaceResult survivalPlaceBlock(GTMTE_LapotronicSuperCapacitor t, World world, int x, int y, int z, ItemStack trigger, IItemSource source, EntityPlayerMP actor, Consumer<IChatComponent> chatter) { - if (check(t, world, x, y, z)) return PlaceResult.SKIP; - int glassTier = ChannelDataAccessor.getChannelData(trigger, "glass") + 2; - ItemStack targetStack = source.takeOne(s -> s != null && s.stackSize >= 0 && s.getItem() == LSC_PART_ITEM && Capacitor.VALUES[Math.min(s.getItemDamage(), Capacitor.VALUES.length) - 1].getMinimalGlassTier() > glassTier, true); - if (targetStack == null) return PlaceResult.REJECT; - return StructureUtility.survivalPlaceBlock(targetStack, NBTMode.EXACT, targetStack.stackTagCompound, true, world, x, y, z, source, actor, chatter); - } - } - )) - )) - .addElement('C', ofBlock(LSC_PART, 1)) - .build(); + private static final IStructureDefinition<GTMTE_LapotronicSuperCapacitor> STRUCTURE_DEFINITION = + IStructureDefinition.<GTMTE_LapotronicSuperCapacitor>builder() + .addShape(STRUCTURE_PIECE_BASE, transpose(new String[][] { + { + "bbbbb", "bbbbb", "bbbbb", "bbbbb", "bbbbb", + }, + { + "bb~bb", "bbbbb", "bbbbb", "bbbbb", "bbbbb", + }, + })) + .addShape(STRUCTURE_PIECE_LAYER, transpose(new String[][] { + { + "ggggg", "gcccg", "gcccg", "gcccg", "ggggg", + }, + })) + .addShape(STRUCTURE_PIECE_TOP, transpose(new String[][] { + { + "ggggg", "ggggg", "ggggg", "ggggg", "ggggg", + }, + })) + .addShape(STRUCTURE_PIECE_MID, transpose(new String[][] { + { + "ggggg", "gCCCg", "gCCCg", "gCCCg", "ggggg", + }, + })) + .addElement( + 'b', + buildHatchAdder(GTMTE_LapotronicSuperCapacitor.class) + .atLeast(LSCHatchElement.Energy, LSCHatchElement.Dynamo, Maintenance) + .hatchItemFilterAnd((t, h) -> ChannelDataAccessor.getChannelData(h, "glass") < 6 + ? filterByMTEClass(ImmutableList.of( + GT_MetaTileEntity_Hatch_EnergyTunnel.class, + GT_MetaTileEntity_Hatch_DynamoTunnel.class)) + .negate() + : s -> true) + .casingIndex(CASING_TEXTURE_ID) + .dot(1) + .buildAndChain( + onElementPass(te -> te.casingAmount++, ofBlock(LSC_PART, CASING_META)))) + .addElement( + 'g', + withChannel( + "glass", + BorosilicateGlass.ofBoroGlass( + (byte) -1, (te, t) -> te.glassTier = t, te -> te.glassTier))) + .addElement( + 'c', + ofChain( + onlyIf( + te -> te.topState != TopState.NotTop, + onElementPass( + te -> te.topState = TopState.Top, + withChannel( + "glass", + BorosilicateGlass.ofBoroGlass( + (byte) -1, + (te, t) -> te.glassTier = t, + te -> te.glassTier)))), + onlyIf( + te -> te.topState != TopState.Top, + onElementPass( + te -> te.topState = TopState.NotTop, + new IStructureElement<GTMTE_LapotronicSuperCapacitor>() { + @Override + public boolean check( + GTMTE_LapotronicSuperCapacitor t, + World world, + int x, + int y, + int z) { + Block worldBlock = world.getBlock(x, y, z); + int meta = worldBlock.getDamageValue(world, x, y, z); + if (LSC_PART != worldBlock || meta == 0) return false; + t.capacitors[meta - 1]++; + return true; + } + + private int getHint(ItemStack stack) { + return Capacitor.VALUES_BY_TIER[ + Math.min( + Capacitor.VALUES_BY_TIER + .length, + ChannelDataAccessor + .getChannelData( + stack, + "capacitor")) + - 1] + .getMinimalGlassTier() + + 1; + } + + @Override + public boolean spawnHint( + GTMTE_LapotronicSuperCapacitor t, + World world, + int x, + int y, + int z, + ItemStack trigger) { + StructureLibAPI.hintParticle( + world, x, y, z, LSC_PART, getHint(trigger)); + return true; + } + + @Override + public boolean placeBlock( + GTMTE_LapotronicSuperCapacitor t, + World world, + int x, + int y, + int z, + ItemStack trigger) { + world.setBlock(x, y, z, LSC_PART, getHint(trigger), 3); + return true; + } + + @Override + public PlaceResult survivalPlaceBlock( + GTMTE_LapotronicSuperCapacitor t, + World world, + int x, + int y, + int z, + ItemStack trigger, + IItemSource source, + EntityPlayerMP actor, + Consumer<IChatComponent> chatter) { + if (check(t, world, x, y, z)) return PlaceResult.SKIP; + int glassTier = + ChannelDataAccessor.getChannelData(trigger, "glass") + + 2; + ItemStack targetStack = source.takeOne( + s -> s != null + && s.stackSize >= 0 + && s.getItem() == LSC_PART_ITEM + && Capacitor.VALUES[ + Math.min( + s + .getItemDamage(), + Capacitor + .VALUES + .length) + - 1] + .getMinimalGlassTier() + > glassTier, + true); + if (targetStack == null) return PlaceResult.REJECT; + return StructureUtility.survivalPlaceBlock( + targetStack, + NBTMode.EXACT, + targetStack.stackTagCompound, + true, + world, + x, + y, + z, + source, + actor, + chatter); + } + })))) + .addElement('C', ofBlock(LSC_PART, 1)) + .build(); private static final BigInteger MAX_LONG = BigInteger.valueOf(Long.MAX_VALUE); @@ -208,6 +302,7 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu * Index = meta - 1 */ private final int[] capacitors = new int[7]; + private BigInteger capacity = BigInteger.ZERO; private BigInteger stored = BigInteger.ZERO; private long passiveDischargeAmount = 0; @@ -261,7 +356,8 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu if (!(aMetaTileEntity instanceof GT_MetaTileEntity_Hatch)) return false; if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance) { ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); - return GTMTE_LapotronicSuperCapacitor.this.mMaintenanceHatches.add((GT_MetaTileEntity_Hatch_Maintenance) aMetaTileEntity); + return GTMTE_LapotronicSuperCapacitor.this.mMaintenanceHatches.add( + (GT_MetaTileEntity_Hatch_Maintenance) aMetaTileEntity); } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy) { // Add GT hatches final GT_MetaTileEntity_Hatch_Energy tHatch = ((GT_MetaTileEntity_Hatch_Energy) aMetaTileEntity); @@ -269,7 +365,8 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu return mEnergyHatches.add(tHatch); } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_EnergyTunnel) { // Add TT Laser hatches - final GT_MetaTileEntity_Hatch_EnergyTunnel tHatch = ((GT_MetaTileEntity_Hatch_EnergyTunnel) aMetaTileEntity); + final GT_MetaTileEntity_Hatch_EnergyTunnel tHatch = + ((GT_MetaTileEntity_Hatch_EnergyTunnel) aMetaTileEntity); processInputHatch(tHatch, aBaseCasingIndex); return mEnergyTunnelsTT.add(tHatch); } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_EnergyMulti) { @@ -304,55 +401,81 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu protected GT_Multiblock_Tooltip_Builder createTooltip() { final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); tt.addMachineType("Energy Storage") - .addInfo("Loses energy equal to 1% of the total capacity every 24 hours. Capped") - .addInfo("at " + EnumChatFormatting.RED + GT_Utility.formatNumbers(max_passive_drain_eu_per_tick_per_uhv_cap) + EnumChatFormatting.GRAY + "EU/t passive loss per " + GT_Values.TIER_COLORS[9] + GT_Values.VN[9] + EnumChatFormatting.GRAY + " capacitor.") - .addInfo("Passive loss is multiplied by the number of maintenance issues present.") - .addSeparator() - .addInfo("Glass shell has to be Tier - 3 of the highest capacitor tier.") - .addInfo(GT_Values.TIER_COLORS[8] + GT_Values.VN[8] + EnumChatFormatting.GRAY + "-tier glass required for " + EnumChatFormatting.BLUE + "Tec" + EnumChatFormatting.DARK_BLUE + "Tech" + EnumChatFormatting.GRAY + " Laser Hatches.") - .addInfo("Add more or better capacitors to increase capacity.") - .addSeparator() - .addInfo("Wireless mode can be enabled by right clicking with a screwdriver.") - .addInfo("This mode can only be enabled if you have a "+ GT_Values.TIER_COLORS[9] + GT_Values.VN[9] + EnumChatFormatting.GRAY + " capacitor in the multiblock.") - .addInfo("When enabled every " + EnumChatFormatting.BLUE + GT_Utility.formatNumbers(LSC_time_between_wireless_rebalance_in_ticks) + EnumChatFormatting.GRAY + " ticks the LSC will attempt to re-balance against your") - .addInfo("wireless EU network. If there is less than " + EnumChatFormatting.RED + GT_Utility.formatNumbers(LSC_wireless_eu_cap) + EnumChatFormatting.GRAY + "EU in the LSC") - .addInfo("it will withdraw from the network and add to the LSC. If there is more it will add") - .addInfo("the EU to the network and remove it from the LSC.") - .addSeparator() - .beginVariableStructureBlock(5, 5, 4, 18, 5, 5, false) - .addStructureInfo("Modular height of 4-18 blocks.") - .addController("Front center bottom") - .addOtherStructurePart("Lapotronic Super Capacitor Casing", "5x2x5 base (at least 17x)") - .addOtherStructurePart("Lapotronic Capacitor (" + GT_Values.TIER_COLORS[4] + GT_Values.VN[4] + EnumChatFormatting.GRAY + "-" + GT_Values.TIER_COLORS[8] + GT_Values.VN[8] + EnumChatFormatting.GRAY + "), Ultimate Capacitor (" + GT_Values.TIER_COLORS[9] + GT_Values.VN[9] + EnumChatFormatting.GRAY + ")", "Center 3x(1-15)x3 above base (9-135 blocks)") - .addStructureInfo("You can also use the Empty Capacitor to save materials if you use it for less than half the blocks") - .addOtherStructurePart("Borosilicate Glass (any)", "41-265x, Encase capacitor pillar") - .addEnergyHatch("Any casing") - .addDynamoHatch("Any casing") - .addOtherStructurePart("Laser Target/Source Hatches", "Any casing, must be using " + GT_Values.TIER_COLORS[8] + GT_Values.VN[8] + EnumChatFormatting.GRAY + "-tier glass") - .addStructureInfo("You can have several I/O Hatches") - .addSubChannelUsage("glass", "Borosilicate Glass Tier") - .addSubChannelUsage("capacitor", "Maximum Capacitor Tier") - .addSubChannelUsage("height", "Height of structure") - .addMaintenanceHatch("Any casing") - .toolTipFinisher("KekzTech"); + .addInfo("Loses energy equal to 1% of the total capacity every 24 hours. Capped") + .addInfo("at " + EnumChatFormatting.RED + + GT_Utility.formatNumbers(max_passive_drain_eu_per_tick_per_uhv_cap) + EnumChatFormatting.GRAY + + "EU/t passive loss per " + GT_Values.TIER_COLORS[9] + GT_Values.VN[9] + + EnumChatFormatting.GRAY + " capacitor.") + .addInfo("Passive loss is multiplied by the number of maintenance issues present.") + .addSeparator() + .addInfo("Glass shell has to be Tier - 3 of the highest capacitor tier.") + .addInfo(GT_Values.TIER_COLORS[8] + GT_Values.VN[8] + EnumChatFormatting.GRAY + + "-tier glass required for " + EnumChatFormatting.BLUE + "Tec" + EnumChatFormatting.DARK_BLUE + + "Tech" + EnumChatFormatting.GRAY + " Laser Hatches.") + .addInfo("Add more or better capacitors to increase capacity.") + .addSeparator() + .addInfo("Wireless mode can be enabled by right clicking with a screwdriver.") + .addInfo("This mode can only be enabled if you have a " + GT_Values.TIER_COLORS[9] + GT_Values.VN[9] + + EnumChatFormatting.GRAY + " capacitor in the multiblock.") + .addInfo("When enabled every " + EnumChatFormatting.BLUE + + GT_Utility.formatNumbers(LSC_time_between_wireless_rebalance_in_ticks) + + EnumChatFormatting.GRAY + " ticks the LSC will attempt to re-balance against your") + .addInfo("wireless EU network. If there is less than " + EnumChatFormatting.RED + + GT_Utility.formatNumbers(LSC_wireless_eu_cap) + EnumChatFormatting.GRAY + "EU in the LSC") + .addInfo("it will withdraw from the network and add to the LSC. If there is more it will add") + .addInfo("the EU to the network and remove it from the LSC.") + .addSeparator() + .beginVariableStructureBlock(5, 5, 4, 18, 5, 5, false) + .addStructureInfo("Modular height of 4-18 blocks.") + .addController("Front center bottom") + .addOtherStructurePart("Lapotronic Super Capacitor Casing", "5x2x5 base (at least 17x)") + .addOtherStructurePart( + "Lapotronic Capacitor (" + GT_Values.TIER_COLORS[4] + GT_Values.VN[4] + EnumChatFormatting.GRAY + + "-" + GT_Values.TIER_COLORS[8] + GT_Values.VN[8] + EnumChatFormatting.GRAY + + "), Ultimate Capacitor (" + GT_Values.TIER_COLORS[9] + GT_Values.VN[9] + + EnumChatFormatting.GRAY + ")", + "Center 3x(1-15)x3 above base (9-135 blocks)") + .addStructureInfo( + "You can also use the Empty Capacitor to save materials if you use it for less than half the blocks") + .addOtherStructurePart("Borosilicate Glass (any)", "41-265x, Encase capacitor pillar") + .addEnergyHatch("Any casing") + .addDynamoHatch("Any casing") + .addOtherStructurePart( + "Laser Target/Source Hatches", + "Any casing, must be using " + GT_Values.TIER_COLORS[8] + GT_Values.VN[8] + + EnumChatFormatting.GRAY + "-tier glass") + .addStructureInfo("You can have several I/O Hatches") + .addSubChannelUsage("glass", "Borosilicate Glass Tier") + .addSubChannelUsage("capacitor", "Maximum Capacitor Tier") + .addSubChannelUsage("height", "Height of structure") + .addMaintenanceHatch("Any casing") + .toolTipFinisher("KekzTech"); return tt; } @Override - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, - boolean aActive, boolean aRedstone) { - ITexture[] sTexture = new ITexture[]{TextureFactory.of(BlockIcons.MACHINE_CASING_FUSION_GLASS, - Dyes.getModulation(-1, Dyes._NULL.mRGBa))}; + public ITexture[] getTexture( + IGregTechTileEntity aBaseMetaTileEntity, + byte aSide, + byte aFacing, + byte aColorIndex, + boolean aActive, + boolean aRedstone) { + ITexture[] sTexture = new ITexture[] { + TextureFactory.of(BlockIcons.MACHINE_CASING_FUSION_GLASS, Dyes.getModulation(-1, Dyes._NULL.mRGBa)) + }; if (aSide == aFacing && aActive) { - sTexture = new ITexture[]{TextureFactory.of(BlockIcons.MACHINE_CASING_FUSION_GLASS_YELLOW, - Dyes.getModulation(-1, Dyes._NULL.mRGBa))}; + sTexture = new ITexture[] { + TextureFactory.of( + BlockIcons.MACHINE_CASING_FUSION_GLASS_YELLOW, Dyes.getModulation(-1, Dyes._NULL.mRGBa)) + }; } return sTexture; } public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), - "MultiblockDisplay.png"); + return new GT_GUIContainer_MultiMachine( + aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), "MultiblockDisplay.png"); } private String global_energy_user_uuid; @@ -402,20 +525,16 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu mMaxEUIn = 0; mMaxEUOut = 0; - if (!checkPiece(STRUCTURE_PIECE_BASE, 2, 1, 0)) - return false; + if (!checkPiece(STRUCTURE_PIECE_BASE, 2, 1, 0)) return false; topState = TopState.NotTop; // need at least one layer of capacitor to form, obviously int layer = 2; while (true) { - if (!checkPiece(STRUCTURE_PIECE_LAYER, 2, layer, 0)) - return false; - layer ++; - if (topState == TopState.Top) - break; // top found, break out + if (!checkPiece(STRUCTURE_PIECE_LAYER, 2, layer, 0)) return false; + layer++; + if (topState == TopState.Top) break; // top found, break out topState = TopState.MayBeTop; - if (layer > 18) - return false; // too many layers + if (layer > 18) return false; // too many layers } // Make sure glass tier is T-2 of the highest tier capacitor in the structure @@ -424,25 +543,28 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu for (int highestGlassTier = capacitors.length - 1; highestGlassTier >= 0; highestGlassTier--) { int highestCapacitor = Capacitor.getIndexFromGlassTier(highestGlassTier); if (capacitors[highestCapacitor] > 0) { - if (Capacitor.VALUES[highestCapacitor].getMinimalGlassTier() > glassTier) - return false; + if (Capacitor.VALUES[highestCapacitor].getMinimalGlassTier() > glassTier) return false; break; } } // Glass has to be at least UV-tier to allow TT Laser hatches if (glassTier < 8) { - if(mEnergyTunnelsTT.size() > 0 || mDynamoTunnelsTT.size() > 0) - return false; + if (mEnergyTunnelsTT.size() > 0 || mDynamoTunnelsTT.size() > 0) return false; } - //Check if enough (more than 50%) non-empty caps - if (capacitors[5] > capacitors[0] + capacitors[1] + capacitors[2] + capacitors[3] + getUHVCapacitorCount() + capacitors[6]) - return false; + // Check if enough (more than 50%) non-empty caps + if (capacitors[5] + > capacitors[0] + + capacitors[1] + + capacitors[2] + + capacitors[3] + + getUHVCapacitorCount() + + capacitors[6]) return false; // Calculate total capacity capacity = BigInteger.ZERO; - for(int i = 0; i < capacitors.length; i++) { + for (int i = 0; i < capacitors.length; i++) { int count = capacitors[i]; capacity = capacity.add(Capacitor.VALUES[i].getProvidedCapacity().multiply(BigInteger.valueOf(count))); } @@ -455,8 +577,7 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu public void construct(ItemStack stackSize, boolean hintsOnly) { int layer = min(stackSize.stackSize + 3, 18); buildPiece(STRUCTURE_PIECE_BASE, stackSize, hintsOnly, 2, 1, 0); - for (int i = 2; i < layer - 1; i++) - buildPiece(STRUCTURE_PIECE_MID, stackSize, hintsOnly, 2, i, 0); + for (int i = 2; i < layer - 1; i++) buildPiece(STRUCTURE_PIECE_MID, stackSize, hintsOnly, 2, i, 0); buildPiece(STRUCTURE_PIECE_TOP, stackSize, hintsOnly, 2, layer - 1, 0); } @@ -465,16 +586,19 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu if (mMachine) return -1; int layer = Math.min(ChannelDataAccessor.getChannelData(stackSize, "height") + 3, 18); int built; - built = survivialBuildPiece(STRUCTURE_PIECE_BASE, stackSize, 2, 1, 0, elementBudget, source, actor, false, true); + built = survivialBuildPiece( + STRUCTURE_PIECE_BASE, stackSize, 2, 1, 0, elementBudget, source, actor, false, true); if (built >= 0) return built; for (int i = 2; i < layer - 1; i++) - built = survivialBuildPiece(STRUCTURE_PIECE_MID, stackSize, 2, i, 0, elementBudget, source, actor, false, true); + built = survivialBuildPiece( + STRUCTURE_PIECE_MID, stackSize, 2, i, 0, elementBudget, source, actor, false, true); if (built >= 0) return built; - return survivialBuildPiece(STRUCTURE_PIECE_TOP, stackSize, 2, layer - 1, 0, elementBudget, source, actor, false, true); + return survivialBuildPiece( + STRUCTURE_PIECE_TOP, stackSize, 2, layer - 1, 0, elementBudget, source, actor, false, true); } @Override - public boolean onRunningTick(ItemStack stack){ + public boolean onRunningTick(ItemStack stack) { // Reset I/O cache inputLastTick = 0; outputLastTick = 0; @@ -482,12 +606,12 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu long temp_stored = 0L; // Draw energy from GT hatches - for(GT_MetaTileEntity_Hatch_Energy eHatch : super.mEnergyHatches) { - if(eHatch == null || eHatch.getBaseMetaTileEntity().isInvalidTileEntity()) { + for (GT_MetaTileEntity_Hatch_Energy eHatch : super.mEnergyHatches) { + if (eHatch == null || eHatch.getBaseMetaTileEntity().isInvalidTileEntity()) { continue; } final long power = getPowerToDraw(eHatch.maxEUInput() * eHatch.maxAmperesIn()); - if(eHatch.getEUVar() >= power) { + if (eHatch.getEUVar() >= power) { eHatch.setEUVar(eHatch.getEUVar() - power); temp_stored += power; inputLastTick += power; @@ -495,12 +619,12 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu } // Output energy to GT hatches - for(GT_MetaTileEntity_Hatch_Dynamo eDynamo : super.mDynamoHatches){ - if(eDynamo == null || eDynamo.getBaseMetaTileEntity().isInvalidTileEntity()){ + for (GT_MetaTileEntity_Hatch_Dynamo eDynamo : super.mDynamoHatches) { + if (eDynamo == null || eDynamo.getBaseMetaTileEntity().isInvalidTileEntity()) { continue; } final long power = getPowerToPush(eDynamo.maxEUOutput() * eDynamo.maxAmperesOut()); - if(power <= eDynamo.maxEUStore() - eDynamo.getEUVar()) { + if (power <= eDynamo.maxEUStore() - eDynamo.getEUVar()) { eDynamo.setEUVar(eDynamo.getEUVar() + power); temp_stored -= power; outputLastTick += power; @@ -508,12 +632,12 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu } // Draw energy from TT hatches - for(GT_MetaTileEntity_Hatch_EnergyMulti eHatch : mEnergyHatchesTT) { - if(eHatch == null || eHatch.getBaseMetaTileEntity().isInvalidTileEntity()) { + for (GT_MetaTileEntity_Hatch_EnergyMulti eHatch : mEnergyHatchesTT) { + if (eHatch == null || eHatch.getBaseMetaTileEntity().isInvalidTileEntity()) { continue; } final long power = getPowerToDraw(eHatch.maxEUInput() * eHatch.maxAmperesIn()); - if(eHatch.getEUVar() >= power) { + if (eHatch.getEUVar() >= power) { eHatch.setEUVar(eHatch.getEUVar() - power); temp_stored += power; inputLastTick += power; @@ -521,12 +645,12 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu } // Output energy to TT hatches - for(GT_MetaTileEntity_Hatch_DynamoMulti eDynamo : mDynamoHatchesTT) { - if(eDynamo == null || eDynamo.getBaseMetaTileEntity().isInvalidTileEntity()){ + for (GT_MetaTileEntity_Hatch_DynamoMulti eDynamo : mDynamoHatchesTT) { + if (eDynamo == null || eDynamo.getBaseMetaTileEntity().isInvalidTileEntity()) { continue; } final long power = getPowerToPush(eDynamo.maxEUOutput() * eDynamo.maxAmperesOut()); - if(power <= eDynamo.maxEUStore() - eDynamo.getEUVar()) { + if (power <= eDynamo.maxEUStore() - eDynamo.getEUVar()) { eDynamo.setEUVar(eDynamo.getEUVar() + power); temp_stored -= power; outputLastTick += power; @@ -534,13 +658,13 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu } // Draw energy from TT Laser hatches - for(GT_MetaTileEntity_Hatch_EnergyTunnel eHatch : mEnergyTunnelsTT) { - if(eHatch == null || eHatch.getBaseMetaTileEntity().isInvalidTileEntity()) { + for (GT_MetaTileEntity_Hatch_EnergyTunnel eHatch : mEnergyTunnelsTT) { + if (eHatch == null || eHatch.getBaseMetaTileEntity().isInvalidTileEntity()) { continue; } final long ttLaserWattage = eHatch.maxEUInput() * eHatch.Amperes - (eHatch.Amperes / 20); final long power = getPowerToDraw(ttLaserWattage); - if(eHatch.getEUVar() >= power) { + if (eHatch.getEUVar() >= power) { eHatch.setEUVar(eHatch.getEUVar() - power); temp_stored += power; inputLastTick += power; @@ -548,13 +672,13 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu } // Output energy to TT Laser hatches - for(GT_MetaTileEntity_Hatch_DynamoTunnel eDynamo : mDynamoTunnelsTT) { - if(eDynamo == null || eDynamo.getBaseMetaTileEntity().isInvalidTileEntity()){ + for (GT_MetaTileEntity_Hatch_DynamoTunnel eDynamo : mDynamoTunnelsTT) { + if (eDynamo == null || eDynamo.getBaseMetaTileEntity().isInvalidTileEntity()) { continue; } final long ttLaserWattage = eDynamo.maxEUOutput() * eDynamo.Amperes - (eDynamo.Amperes / 20); final long power = getPowerToPush(ttLaserWattage); - if(power <= eDynamo.maxEUStore() - eDynamo.getEUVar()) { + if (power <= eDynamo.maxEUStore() - eDynamo.getEUVar()) { eDynamo.setEUVar(eDynamo.getEUVar() + power); temp_stored -= power; outputLastTick += power; @@ -573,7 +697,8 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu counter = 1; // Find difference. - BigInteger transferred_eu = stored.subtract(LSC_wireless_eu_cap.multiply(BigInteger.valueOf(getUHVCapacitorCount()))); + BigInteger transferred_eu = + stored.subtract(LSC_wireless_eu_cap.multiply(BigInteger.valueOf(getUHVCapacitorCount()))); if (transferred_eu.signum() == 1) { inputLastTick += transferred_eu.longValue(); @@ -590,7 +715,7 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu // Lose some energy. // Re-calculate if the repair status changed. - if(super.getRepairStatus() != repairStatusCache) { + if (super.getRepairStatus() != repairStatusCache) { passiveDischargeAmount = recalculateLossWithMaintenance(super.getRepairStatus()); } @@ -603,16 +728,16 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu IGregTechTileEntity tBMTE = this.getBaseMetaTileEntity(); - tBMTE.injectEnergyUnits((byte)ForgeDirection.UNKNOWN.ordinal(), inputLastTick, 1L); - tBMTE.drainEnergyUnits((byte)ForgeDirection.UNKNOWN.ordinal(), outputLastTick, 1L); + tBMTE.injectEnergyUnits((byte) ForgeDirection.UNKNOWN.ordinal(), inputLastTick, 1L); + tBMTE.drainEnergyUnits((byte) ForgeDirection.UNKNOWN.ordinal(), outputLastTick, 1L); - //Add I/O values to Queues - if(energyInputValues.size() > DURATION_AVERAGE_TICKS){ + // Add I/O values to Queues + if (energyInputValues.size() > DURATION_AVERAGE_TICKS) { energyInputValues.remove(); } energyInputValues.offer(inputLastTick); - if(energyOutputValues.size() > DURATION_AVERAGE_TICKS){ + if (energyOutputValues.size() > DURATION_AVERAGE_TICKS) { energyOutputValues.remove(); } @@ -631,15 +756,19 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu repairStatusCache = repairStatus; // This cannot overflow because there is a 135 capacitor maximum per LSC. - long temp_capacity_divided = capacity.divide(BigInteger.valueOf(100L * 86400L * 20L)).longValue(); + long temp_capacity_divided = + capacity.divide(BigInteger.valueOf(100L * 86400L * 20L)).longValue(); - // Passive loss is multiplied by number of UHV caps. Minimum of 1 otherwise loss is 0 for non-UHV caps calculations. - long uhv_cap_multiplier = min(temp_capacity_divided, max_passive_drain_eu_per_tick_per_uhv_cap * max(1, getUHVCapacitorCount())); + // Passive loss is multiplied by number of UHV caps. Minimum of 1 otherwise loss is 0 for non-UHV caps + // calculations. + long uhv_cap_multiplier = + min(temp_capacity_divided, max_passive_drain_eu_per_tick_per_uhv_cap * max(1, getUHVCapacitorCount())); // Passive loss is multiplied by number of maintenance issues. long total_passive_loss = uhv_cap_multiplier * (getIdealStatus() - repairStatus + 1); - // Maximum of 100,000 EU/t drained per UHV cell. The logic is 1% of EU capacity should be drained every 86400 seconds (1 day). + // Maximum of 100,000 EU/t drained per UHV cell. The logic is 1% of EU capacity should be drained every 86400 + // seconds (1 day). return total_passive_loss; } @@ -649,7 +778,7 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu * Hatch amperage * voltage * @return EU amount */ - private long getPowerToDraw(long hatchWatts){ + private long getPowerToDraw(long hatchWatts) { final BigInteger remcapActual = capacity.subtract(stored); final BigInteger recampLimited = (MAX_LONG.compareTo(remcapActual) > 0) ? remcapActual : MAX_LONG; return min(hatchWatts, recampLimited.longValue()); @@ -661,22 +790,22 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu * Hatch amperage * voltage * @return EU amount */ - private long getPowerToPush(long hatchWatts){ + private long getPowerToPush(long hatchWatts) { final BigInteger remStoredLimited = (MAX_LONG.compareTo(stored) > 0) ? stored : MAX_LONG; return min(hatchWatts, remStoredLimited.longValue()); } - private long getAvgIn(){ + private long getAvgIn() { long sum = 0L; - for(long l: energyInputValues){ + for (long l : energyInputValues) { sum += l; } return sum / Math.max(energyInputValues.size(), 1); } - private long getAvgOut(){ + private long getAvgOut() { long sum = 0L; - for(long l: energyOutputValues){ + for (long l : energyOutputValues) { sum += l; } return sum / Math.max(energyOutputValues.size(), 1); @@ -685,7 +814,7 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu @Override public String[] getInfoData() { NumberFormat nf = NumberFormat.getNumberInstance(); - int secInterval = DURATION_AVERAGE_TICKS/20; + int secInterval = DURATION_AVERAGE_TICKS / 20; final ArrayList<String> ll = new ArrayList<>(); ll.add(EnumChatFormatting.YELLOW + "Operational Data:" + EnumChatFormatting.RESET); @@ -696,14 +825,18 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu ll.add("EU OUT: " + GT_Utility.formatNumbers(outputLastTick) + "EU/t"); ll.add("Avg EU IN: " + nf.format(getAvgIn()) + " (last " + secInterval + " seconds)"); ll.add("Avg EU OUT: " + nf.format(getAvgOut()) + " (last " + secInterval + " seconds)"); - ll.add("Maintenance Status: " + ((super.getRepairStatus() == super.getIdealStatus()) - ? EnumChatFormatting.GREEN + "Working perfectly" + EnumChatFormatting.RESET - : EnumChatFormatting.RED + "Has Problems" + EnumChatFormatting.RESET)); - ll.add("Wireless mode: " + (wireless_mode - ? EnumChatFormatting.GREEN + "enabled" + EnumChatFormatting.RESET - : EnumChatFormatting.RED + "disabled" + EnumChatFormatting.RESET)); - ll.add(GT_Values.TIER_COLORS[9] + GT_Values.VN[9] + EnumChatFormatting.RESET + " Capacitors detected: " + getUHVCapacitorCount()); - ll.add("Total wireless EU: " + EnumChatFormatting.RED + GT_Utility.formatNumbers(getUserEU(global_energy_user_uuid))); + ll.add("Maintenance Status: " + + ((super.getRepairStatus() == super.getIdealStatus()) + ? EnumChatFormatting.GREEN + "Working perfectly" + EnumChatFormatting.RESET + : EnumChatFormatting.RED + "Has Problems" + EnumChatFormatting.RESET)); + ll.add("Wireless mode: " + + (wireless_mode + ? EnumChatFormatting.GREEN + "enabled" + EnumChatFormatting.RESET + : EnumChatFormatting.RED + "disabled" + EnumChatFormatting.RESET)); + ll.add(GT_Values.TIER_COLORS[9] + GT_Values.VN[9] + EnumChatFormatting.RESET + " Capacitors detected: " + + getUHVCapacitorCount()); + ll.add("Total wireless EU: " + EnumChatFormatting.RED + + GT_Utility.formatNumbers(getUserEU(global_energy_user_uuid))); ll.add("---------------------------------------------"); final String[] a = new String[ll.size()]; @@ -738,67 +871,67 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu } @Override - public int getMaxEfficiency(ItemStack stack) { return 10000; } + public int getMaxEfficiency(ItemStack stack) { + return 10000; + } @Override - public int getPollutionPerTick(ItemStack stack) { return 0; } + public int getPollutionPerTick(ItemStack stack) { + return 0; + } @Override - public int getDamageToComponent(ItemStack stack) { return 0; } + public int getDamageToComponent(ItemStack stack) { + return 0; + } @Override - public boolean explodesOnComponentBreak(ItemStack stack) { return false; } + public boolean explodesOnComponentBreak(ItemStack stack) { + return false; + } - //called by the getEUCapacity() function in BaseMetaTileEntity + // called by the getEUCapacity() function in BaseMetaTileEntity @Override - public long maxEUStore() - { + public long maxEUStore() { return capacity.longValue(); } - //called by the getEUStored() function in BaseMetaTileEntity + // called by the getEUStored() function in BaseMetaTileEntity @Override - public long getEUVar() - { + public long getEUVar() { return stored.longValue(); } /* all of these are needed for the injectEnergyUnits() and drainEnergyUnits() - in IGregTechTileEntity - */ + in IGregTechTileEntity + */ @Override - public long maxEUInput() - { + public long maxEUInput() { return mMaxEUIn; } @Override - public long maxAmperesIn() - { + public long maxAmperesIn() { return 1L; } @Override - public long maxEUOutput() - { + public long maxEUOutput() { return mMaxEUOut; } @Override - public long maxAmperesOut() - { + public long maxAmperesOut() { return 1L; } @Override - public boolean isEnetInput() - { + public boolean isEnetInput() { return true; } @Override - public boolean isEnetOutput() - { + public boolean isEnetOutput() { return true; } @@ -808,7 +941,10 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu wireless_mode = !wireless_mode; GT_Utility.sendChatToPlayer(aPlayer, "Wireless network mode " + (wireless_mode ? "enabled." : "disabled.")); } else { - GT_Utility.sendChatToPlayer(aPlayer, "Wireless mode cannot be enabled without at least 1 " + GT_Values.TIER_COLORS[9] + GT_Values.VN[9] + EnumChatFormatting.RESET + " capacitor."); + GT_Utility.sendChatToPlayer( + aPlayer, + "Wireless mode cannot be enabled without at least 1 " + GT_Values.TIER_COLORS[9] + GT_Values.VN[9] + + EnumChatFormatting.RESET + " capacitor."); wireless_mode = false; } } diff --git a/src/main/java/common/tileentities/GTMTE_ModularNuclearReactor.java b/src/main/java/common/tileentities/GTMTE_ModularNuclearReactor.java index ec720b9354..67aaf2a0f9 100644 --- a/src/main/java/common/tileentities/GTMTE_ModularNuclearReactor.java +++ b/src/main/java/common/tileentities/GTMTE_ModularNuclearReactor.java @@ -1,245 +1,249 @@ -package common.tileentities;
-
-import org.joml.Vector3i;
-import org.lwjgl.input.Keyboard;
-
-import client.gui.GUIContainer_ModularNuclearReactor;
-import common.Blocks;
-import gregtech.api.GregTech_API;
-import gregtech.api.enums.Textures;
-import gregtech.api.interfaces.ITexture;
-import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
-import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
-import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase;
-import gregtech.api.objects.GT_RenderedTexture;
-import net.minecraft.block.Block;
-import net.minecraft.entity.player.InventoryPlayer;
-import net.minecraft.item.ItemStack;
-import net.minecraftforge.common.util.ForgeDirection;
-
-public class GTMTE_ModularNuclearReactor extends GT_MetaTileEntity_MultiBlockBase {
-
- private final Block CASING = GregTech_API.sBlockCasings3;
- private final int CASING_META = 12;
- private final int CASING_TEXTURE_ID = 44;
-
- private final Block CHAMBER_OFF = Blocks.reactorChamberOFF;
- private final Block CHAMBER_ON = Blocks.reactorChamberON;
- private final Block CONTROL_ROD = Blocks.reactorControlRod;
-
- private boolean euMode = true;
-
- public GTMTE_ModularNuclearReactor(int aID, String aName, String aNameRegional) {
- super(aID, aName, aNameRegional);
-
- }
-
- public GTMTE_ModularNuclearReactor(String aName) {
- super(aName);
-
- }
-
- @Override
- public IMetaTileEntity newMetaEntity(IGregTechTileEntity var1) {
- return new GTMTE_ModularNuclearReactor(super.mName);
- }
-
- @Override
- public String[] getDescription() {
- return new String[]{"Disabled"};
- /*
- final MultiBlockTooltipBuilder b = new MultiBlockTooltipBuilder();
- b.addInfo("Can be built, BUT DOES NOT WORK")
- .addInfo("Converts fissile material and outputs power or heat")
- .addSeparator()
- .addInfo("EU-MODE:")
- .addInfo(" Directly outputs electricity depending on inserted fuel rods")
- .addSeparator()
- .addInfo("COOLANT-MODE:")
- .addInfo(" Requires coolant to be pumped into the reactor.")
- .addInfo(" Coolant is heated and should be drained and converted to electricity by other means.")
- .addSeparator()
- .addInfo("NOTES:")
- .addInfo(" Does NOT use Industrialcraft 2 reactor components!")
- .addInfo(" Consult controller GUI on how to arrange the outer casings.")
- .addSeparator()
- .beginStructureBlock(7, 6, 7)
- .addController("Front bottom Center")
- .addCasingInfo("Radiation Proof Machine Casing", 100)
- .addOtherStructurePart("Control Rods", "Four pillars, four blocks high each. Diagonal to the inner edges of the shell")
- .addOtherStructurePart("Nuclear Reactor Chamber", "17 of them to fill out the rest of the floor inside the shell")
- .addDynamoHatch("ONLY in EU-mode, at least one")
- .addOtherStructurePart("Input Bus, Output Bus", "Optional but required for automation")
- .addOtherStructurePart("Input Hatch, Output Hatch", "ONLY in Coolant-Mode, at least one each")
- .signAndFinalize("Kekzdealer");
- if(!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
- return b.getInformation();
- } else {
- return b.getStructureInformation();
- }*/
- }
-
- @Override
- public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing,
- final byte aColorIndex, final boolean aActive, final boolean aRedstone) {
- return aSide == aFacing
- ? new ITexture[]{Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID),
- new GT_RenderedTexture(aActive ?
- Textures.BlockIcons.OVERLAY_FRONT_HEAT_EXCHANGER_ACTIVE
- : Textures.BlockIcons.OVERLAY_FRONT_HEAT_EXCHANGER)}
- : new ITexture[]{Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID)};
- }
-
- // TODO: Opening UI crashes server. Controller isn't craftable right now.
- public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) {
- /*return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(),
- "MultiblockDisplay.png");*/
- return new GUIContainer_ModularNuclearReactor(aBaseMetaTileEntity, aPlayerInventory.player);
- }
-
- @Override
- public boolean isCorrectMachinePart(ItemStack stack) {
- return true;
- }
-
- @Override
- public boolean checkRecipe(ItemStack stack) {
- return false;
- }
-
- @Override
- public void onPostTick(IGregTechTileEntity thisController, long aTick) {
- super.onPostTick(thisController, aTick);
-
- if(super.getBaseMetaTileEntity().isActive()) {
- // Switch to ON blocks
- } else {
- // Switch to OFF blocks
- }
- }
-
- @Override
- public boolean checkMachine(IGregTechTileEntity thisController, ItemStack guiSlotItem) {
- // Figure out the vector for the direction the back face of the controller is facing
- final int dirX = ForgeDirection.getOrientation(thisController.getBackFacing()).offsetX;
- final int dirZ = ForgeDirection.getOrientation(thisController.getBackFacing()).offsetZ;
- int minCasingAmount = 100;
- boolean checklist = true; // if this is still true at the end, machine is good to go :)
-
- // Determine the ground level center of the structure
- final Vector3i center = new Vector3i(
- thisController.getXCoord(),
- thisController.getYCoord(),
- thisController.getZCoord())
- .add(dirX * 3, 0, dirZ * 3);
- // Scan for outer tube
- // - Scan sides
- for(int x = -3; x <= 3; x++) {
- for(int z = -3; z <= 3; z++) {
- // Only scan the three wide even sides, skip rest
- if((Math.abs(x) <= 1 && Math.abs(z) == 3) || (Math.abs(z) <= 1 && Math.abs(x) == 3)) {
- for(int h = 0; h < 6; h++) {
- final Vector3i pos = new Vector3i(center.x() + x, center.y() + h, center.z() + z);
- if(h == 0 && pos.x() == thisController.getXCoord() && pos.y() == thisController.getYCoord() && pos.z() == thisController.getZCoord()) {
- // Ignore controller
- continue;
- } else if (thisController.getBlock(pos.x(), pos.y(), pos.z()) == CASING
- && thisController.getMetaID(pos.x(), pos.y(), pos.z()) == CASING_META) {
- minCasingAmount--;
- } else {
- checklist = false;
- }
- }
- }
- }
- }
- // - Scan corners of tube
- for(int x = -2; x <= 2; x++) {
- for(int z = -2; z <= 2; z++) {
- // Only scan the four corners, skip rest
- if(Math.abs(x) + Math.abs(z) == 4) {
- for(int h = 0; h < 6; h++) {
- final Vector3i pos = new Vector3i(center.x() + x, center.y() + h, center.z() + z);
- if(h == 0 && pos.x() == thisController.getXCoord() && pos.y() == thisController.getYCoord() && pos.z() == thisController.getZCoord()) {
- // Ignore controller
- continue;
- } else if (thisController.getBlock(pos.x(), pos.y(), pos.z()) == CASING
- && thisController.getMetaID(pos.x(), pos.y(), pos.z()) == CASING_META) {
- minCasingAmount--;
- } else {
- checklist = false;
- }
- }
- }
- }
- }
- // Scan ground layer
- for(int x = -2; x <= 2; x++) {
- for(int z = -2; z <= 2; z++) {
- if(!(thisController.getBlock(center.x() + x, center.y(), center.z() + z) == CASING
- && thisController.getMetaID(center.x() + x, center.y(), center.z() + z) == CASING_META)) {
- checklist = false;
- } else {
- minCasingAmount--;
- }
- }
- }
- // Scan reactor chambers
- for(int x = -2; x <= 2; x++) {
- for(int z = -2; z <= 2; z++) {
- // Skip if diagonal, don't skip center
- if(Math.abs(x) == Math.abs(z) && !(x == 0 && z == 0)) {
- continue;
- }
- if(!(thisController.getBlock(center.x() + x, center.y() + 1, center.z() + z) == CHAMBER_OFF
- || thisController.getBlock(center.x() + x, center.y() + 1, center.z() + z) == CHAMBER_ON)) {
- checklist = false;
- }
- }
- }
- // Scan control rods
- for(int h = 1; h < 5; h++) {
- for(int x = -1; x <= 1; x++) {
- for(int z = -1; z <= 1; z++) {
- // Only check diagonal
- if(x == 0 || z == 0) {
- continue;
- }
- if(!(thisController.getBlock(center.x() + x, center.y() + h, center.z() + z) == CONTROL_ROD)) {
- checklist = false;
- }
- }
- }
- }
-
-
-
-
- if(minCasingAmount > 0) {
- checklist = false;
- }
-
- return checklist;
- }
-
- @Override
- public int getMaxEfficiency(ItemStack stack) {
- return 10000;
- }
-
- @Override
- public int getPollutionPerTick(ItemStack stack) {
- return 0;
- }
-
- @Override
- public int getDamageToComponent(ItemStack stack) {
- return 0;
- }
-
- @Override
- public boolean explodesOnComponentBreak(ItemStack stack) {
- return false;
- }
-
-}
+package common.tileentities; + +import client.gui.GUIContainer_ModularNuclearReactor; +import common.Blocks; +import gregtech.api.GregTech_API; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; +import gregtech.api.objects.GT_RenderedTexture; +import net.minecraft.block.Block; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; +import org.joml.Vector3i; + +public class GTMTE_ModularNuclearReactor extends GT_MetaTileEntity_MultiBlockBase { + + private final Block CASING = GregTech_API.sBlockCasings3; + private final int CASING_META = 12; + private final int CASING_TEXTURE_ID = 44; + + private final Block CHAMBER_OFF = Blocks.reactorChamberOFF; + private final Block CHAMBER_ON = Blocks.reactorChamberON; + private final Block CONTROL_ROD = Blocks.reactorControlRod; + + private boolean euMode = true; + + public GTMTE_ModularNuclearReactor(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GTMTE_ModularNuclearReactor(String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity var1) { + return new GTMTE_ModularNuclearReactor(super.mName); + } + + @Override + public String[] getDescription() { + return new String[] {"Disabled"}; + /* + final MultiBlockTooltipBuilder b = new MultiBlockTooltipBuilder(); + b.addInfo("Can be built, BUT DOES NOT WORK") + .addInfo("Converts fissile material and outputs power or heat") + .addSeparator() + .addInfo("EU-MODE:") + .addInfo(" Directly outputs electricity depending on inserted fuel rods") + .addSeparator() + .addInfo("COOLANT-MODE:") + .addInfo(" Requires coolant to be pumped into the reactor.") + .addInfo(" Coolant is heated and should be drained and converted to electricity by other means.") + .addSeparator() + .addInfo("NOTES:") + .addInfo(" Does NOT use Industrialcraft 2 reactor components!") + .addInfo(" Consult controller GUI on how to arrange the outer casings.") + .addSeparator() + .beginStructureBlock(7, 6, 7) + .addController("Front bottom Center") + .addCasingInfo("Radiation Proof Machine Casing", 100) + .addOtherStructurePart("Control Rods", "Four pillars, four blocks high each. Diagonal to the inner edges of the shell") + .addOtherStructurePart("Nuclear Reactor Chamber", "17 of them to fill out the rest of the floor inside the shell") + .addDynamoHatch("ONLY in EU-mode, at least one") + .addOtherStructurePart("Input Bus, Output Bus", "Optional but required for automation") + .addOtherStructurePart("Input Hatch, Output Hatch", "ONLY in Coolant-Mode, at least one each") + .signAndFinalize("Kekzdealer"); + if(!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { + return b.getInformation(); + } else { + return b.getStructureInformation(); + }*/ + } + + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { + return aSide == aFacing + ? new ITexture[] { + Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID), + new GT_RenderedTexture( + aActive + ? Textures.BlockIcons.OVERLAY_FRONT_HEAT_EXCHANGER_ACTIVE + : Textures.BlockIcons.OVERLAY_FRONT_HEAT_EXCHANGER) + } + : new ITexture[] {Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID)}; + } + + // TODO: Opening UI crashes server. Controller isn't craftable right now. + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + /*return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), + "MultiblockDisplay.png");*/ + return new GUIContainer_ModularNuclearReactor(aBaseMetaTileEntity, aPlayerInventory.player); + } + + @Override + public boolean isCorrectMachinePart(ItemStack stack) { + return true; + } + + @Override + public boolean checkRecipe(ItemStack stack) { + return false; + } + + @Override + public void onPostTick(IGregTechTileEntity thisController, long aTick) { + super.onPostTick(thisController, aTick); + + if (super.getBaseMetaTileEntity().isActive()) { + // Switch to ON blocks + } else { + // Switch to OFF blocks + } + } + + @Override + public boolean checkMachine(IGregTechTileEntity thisController, ItemStack guiSlotItem) { + // Figure out the vector for the direction the back face of the controller is facing + final int dirX = ForgeDirection.getOrientation(thisController.getBackFacing()).offsetX; + final int dirZ = ForgeDirection.getOrientation(thisController.getBackFacing()).offsetZ; + int minCasingAmount = 100; + boolean checklist = true; // if this is still true at the end, machine is good to go :) + + // Determine the ground level center of the structure + final Vector3i center = new Vector3i( + thisController.getXCoord(), thisController.getYCoord(), thisController.getZCoord()) + .add(dirX * 3, 0, dirZ * 3); + // Scan for outer tube + // - Scan sides + for (int x = -3; x <= 3; x++) { + for (int z = -3; z <= 3; z++) { + // Only scan the three wide even sides, skip rest + if ((Math.abs(x) <= 1 && Math.abs(z) == 3) || (Math.abs(z) <= 1 && Math.abs(x) == 3)) { + for (int h = 0; h < 6; h++) { + final Vector3i pos = new Vector3i(center.x() + x, center.y() + h, center.z() + z); + if (h == 0 + && pos.x() == thisController.getXCoord() + && pos.y() == thisController.getYCoord() + && pos.z() == thisController.getZCoord()) { + // Ignore controller + continue; + } else if (thisController.getBlock(pos.x(), pos.y(), pos.z()) == CASING + && thisController.getMetaID(pos.x(), pos.y(), pos.z()) == CASING_META) { + minCasingAmount--; + } else { + checklist = false; + } + } + } + } + } + // - Scan corners of tube + for (int x = -2; x <= 2; x++) { + for (int z = -2; z <= 2; z++) { + // Only scan the four corners, skip rest + if (Math.abs(x) + Math.abs(z) == 4) { + for (int h = 0; h < 6; h++) { + final Vector3i pos = new Vector3i(center.x() + x, center.y() + h, center.z() + z); + if (h == 0 + && pos.x() == thisController.getXCoord() + && pos.y() == thisController.getYCoord() + && pos.z() == thisController.getZCoord()) { + // Ignore controller + continue; + } else if (thisController.getBlock(pos.x(), pos.y(), pos.z()) == CASING + && thisController.getMetaID(pos.x(), pos.y(), pos.z()) == CASING_META) { + minCasingAmount--; + } else { + checklist = false; + } + } + } + } + } + // Scan ground layer + for (int x = -2; x <= 2; x++) { + for (int z = -2; z <= 2; z++) { + if (!(thisController.getBlock(center.x() + x, center.y(), center.z() + z) == CASING + && thisController.getMetaID(center.x() + x, center.y(), center.z() + z) == CASING_META)) { + checklist = false; + } else { + minCasingAmount--; + } + } + } + // Scan reactor chambers + for (int x = -2; x <= 2; x++) { + for (int z = -2; z <= 2; z++) { + // Skip if diagonal, don't skip center + if (Math.abs(x) == Math.abs(z) && !(x == 0 && z == 0)) { + continue; + } + if (!(thisController.getBlock(center.x() + x, center.y() + 1, center.z() + z) == CHAMBER_OFF + || thisController.getBlock(center.x() + x, center.y() + 1, center.z() + z) == CHAMBER_ON)) { + checklist = false; + } + } + } + // Scan control rods + for (int h = 1; h < 5; h++) { + for (int x = -1; x <= 1; x++) { + for (int z = -1; z <= 1; z++) { + // Only check diagonal + if (x == 0 || z == 0) { + continue; + } + if (!(thisController.getBlock(center.x() + x, center.y() + h, center.z() + z) == CONTROL_ROD)) { + checklist = false; + } + } + } + } + + if (minCasingAmount > 0) { + checklist = false; + } + + return checklist; + } + + @Override + public int getMaxEfficiency(ItemStack stack) { + return 10000; + } + + @Override + public int getPollutionPerTick(ItemStack stack) { + return 0; + } + + @Override + public int getDamageToComponent(ItemStack stack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack stack) { + return false; + } +} diff --git a/src/main/java/common/tileentities/GTMTE_SOFuelCellMK1.java b/src/main/java/common/tileentities/GTMTE_SOFuelCellMK1.java index 03668aaa28..1909b5ef27 100644 --- a/src/main/java/common/tileentities/GTMTE_SOFuelCellMK1.java +++ b/src/main/java/common/tileentities/GTMTE_SOFuelCellMK1.java @@ -1,14 +1,12 @@ package common.tileentities; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static gregtech.api.enums.Textures.BlockIcons.*; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; -import cpw.mods.fml.common.registry.GameRegistry; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_EnhancedMultiBlockBase; - import common.Blocks; +import cpw.mods.fml.common.registry.GameRegistry; import gregtech.api.GregTech_API; import gregtech.api.enums.Materials; import gregtech.api.enums.Textures; @@ -16,34 +14,33 @@ import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_EnhancedMultiBlockBase; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; -import gregtech.api.util.GT_Utility; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; +import gregtech.api.util.GT_Utility; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; -import static gregtech.api.enums.Textures.BlockIcons.*; -import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; - -public class GTMTE_SOFuelCellMK1 extends GT_MetaTileEntity_EnhancedMultiBlockBase<GTMTE_SOFuelCellMK1> { +public class GTMTE_SOFuelCellMK1 extends GT_MetaTileEntity_EnhancedMultiBlockBase<GTMTE_SOFuelCellMK1> { - private final int OXYGEN_PER_SEC = 100; - private final int EU_PER_TICK = 2048; - private final int STEAM_PER_SEC = 20000; + private final int OXYGEN_PER_SEC = 100; + private final int EU_PER_TICK = 2048; + private final int STEAM_PER_SEC = 20000; - public GTMTE_SOFuelCellMK1(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - - } + public GTMTE_SOFuelCellMK1(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } - public GTMTE_SOFuelCellMK1(String aName) { - super(aName); - } + public GTMTE_SOFuelCellMK1(String aName) { + super(aName); + } @Override public IMetaTileEntity newMetaEntity(IGregTechTileEntity var1) { @@ -54,22 +51,25 @@ public class GTMTE_SOFuelCellMK1 extends GT_MetaTileEntity_EnhancedMultiBlockBa private static final int CASING_TEXTURE_ID = 49; private static final String STRUCTURE_PIECE_MAIN = "main"; - private static final IStructureDefinition<GTMTE_SOFuelCellMK1> STRUCTURE_DEFINITION = IStructureDefinition.<GTMTE_SOFuelCellMK1>builder() - .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ - {"ccc", "ccc", "ccc", "ccc", "ccc"}, - {"c~c", "geg", "geg", "geg", "cdc"}, - {"ccc", "ccc", "ccc", "ccc", "ccc"} - })) - .addElement('c', ofChain( - onElementPass(te -> te.mCasing++, ofBlock(GregTech_API.sBlockCasings4, 1)), - ofHatchAdder(GTMTE_SOFuelCellMK1::addInputToMachineList, CASING_TEXTURE_ID, 1), - ofHatchAdder(GTMTE_SOFuelCellMK1::addMaintenanceToMachineList, CASING_TEXTURE_ID, 1), - ofHatchAdder(GTMTE_SOFuelCellMK1::addOutputToMachineList, CASING_TEXTURE_ID, 1) - )) - .addElement('d', ofHatchAdder(GTMTE_SOFuelCellMK1::addDynamoToMachineList, CASING_TEXTURE_ID, 1)) - .addElement('g', ofBlockAnyMeta(GameRegistry.findBlock("IC2", "blockAlloyGlass"))) - .addElement('e', ofBlockAnyMeta(Blocks.yszUnit)) - .build(); + private static final IStructureDefinition<GTMTE_SOFuelCellMK1> STRUCTURE_DEFINITION = + IStructureDefinition.<GTMTE_SOFuelCellMK1>builder() + .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][] { + {"ccc", "ccc", "ccc", "ccc", "ccc"}, + {"c~c", "geg", "geg", "geg", "cdc"}, + {"ccc", "ccc", "ccc", "ccc", "ccc"} + })) + .addElement( + 'c', + ofChain( + onElementPass(te -> te.mCasing++, ofBlock(GregTech_API.sBlockCasings4, 1)), + ofHatchAdder(GTMTE_SOFuelCellMK1::addInputToMachineList, CASING_TEXTURE_ID, 1), + ofHatchAdder( + GTMTE_SOFuelCellMK1::addMaintenanceToMachineList, CASING_TEXTURE_ID, 1), + ofHatchAdder(GTMTE_SOFuelCellMK1::addOutputToMachineList, CASING_TEXTURE_ID, 1))) + .addElement('d', ofHatchAdder(GTMTE_SOFuelCellMK1::addDynamoToMachineList, CASING_TEXTURE_ID, 1)) + .addElement('g', ofBlockAnyMeta(GameRegistry.findBlock("IC2", "blockAlloyGlass"))) + .addElement('e', ofBlockAnyMeta(Blocks.yszUnit)) + .build(); @Override public IStructureDefinition<GTMTE_SOFuelCellMK1> getStructureDefinition() { @@ -80,132 +80,150 @@ public class GTMTE_SOFuelCellMK1 extends GT_MetaTileEntity_EnhancedMultiBlockBa protected GT_Multiblock_Tooltip_Builder createTooltip() { final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); tt.addMachineType("Gas Turbine") - .addInfo("Oxidizes gas fuels to generate electricity without polluting the environment") - .addInfo("Consumes up to" + (EU_PER_TICK * 20) + "EU worth of fuel with up to 100% efficiency each second") - .addInfo("Steam production requires the SOFC to heat up completely first") - .addInfo("Outputs " + EU_PER_TICK + "EU/t and " + STEAM_PER_SEC + "L/s Steam") - .addInfo("Additionally, requires " + OXYGEN_PER_SEC + "L/s Oxygen gas") - .addSeparator() - .beginStructureBlock(3, 3, 5, false) - .addController("Front center") - .addCasingInfo("Clean Stainless Steel Casing", 12) - .addOtherStructurePart("YSZ Ceramic Electrolyte Unit", "3x, Center 1x1x3") - .addOtherStructurePart("Reinforced Glass", "6x, touching the electrolyte units on the horizontal sides") - .addDynamoHatch("Back center", 1) - .addMaintenanceHatch("Any casing") - .addInputHatch("Fuel, any casing") - .addInputHatch("Oxygen, any casing") - .addOutputHatch("Steam, any casing") - .toolTipFinisher("KekzTech"); + .addInfo("Oxidizes gas fuels to generate electricity without polluting the environment") + .addInfo("Consumes up to" + (EU_PER_TICK * 20) + + "EU worth of fuel with up to 100% efficiency each second") + .addInfo("Steam production requires the SOFC to heat up completely first") + .addInfo("Outputs " + EU_PER_TICK + "EU/t and " + STEAM_PER_SEC + "L/s Steam") + .addInfo("Additionally, requires " + OXYGEN_PER_SEC + "L/s Oxygen gas") + .addSeparator() + .beginStructureBlock(3, 3, 5, false) + .addController("Front center") + .addCasingInfo("Clean Stainless Steel Casing", 12) + .addOtherStructurePart("YSZ Ceramic Electrolyte Unit", "3x, Center 1x1x3") + .addOtherStructurePart("Reinforced Glass", "6x, touching the electrolyte units on the horizontal sides") + .addDynamoHatch("Back center", 1) + .addMaintenanceHatch("Any casing") + .addInputHatch("Fuel, any casing") + .addInputHatch("Oxygen, any casing") + .addOutputHatch("Steam, any casing") + .toolTipFinisher("KekzTech"); return tt; } - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, - final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { if (aSide == aFacing) { if (aActive) - return new ITexture[]{ + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID), - TextureFactory.builder().addIcon(OVERLAY_FRONT_HEAT_EXCHANGER_ACTIVE).extFacing().build(), - TextureFactory.builder().addIcon(OVERLAY_FRONT_HEAT_EXCHANGER_ACTIVE_GLOW).extFacing().glow().build()}; - return new ITexture[]{ + TextureFactory.builder() + .addIcon(OVERLAY_FRONT_HEAT_EXCHANGER_ACTIVE) + .extFacing() + .build(), + TextureFactory.builder() + .addIcon(OVERLAY_FRONT_HEAT_EXCHANGER_ACTIVE_GLOW) + .extFacing() + .glow() + .build() + }; + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID), - TextureFactory.builder().addIcon(OVERLAY_FRONT_HEAT_EXCHANGER).extFacing().build(), - TextureFactory.builder().addIcon(OVERLAY_FRONT_HEAT_EXCHANGER_GLOW).extFacing().glow().build()}; + TextureFactory.builder() + .addIcon(OVERLAY_FRONT_HEAT_EXCHANGER) + .extFacing() + .build(), + TextureFactory.builder() + .addIcon(OVERLAY_FRONT_HEAT_EXCHANGER_GLOW) + .extFacing() + .glow() + .build() + }; } - return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID)}; - } - - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), - "MultiblockDisplay.png"); - } - - @Override - public boolean isCorrectMachinePart(ItemStack stack) { - return true; - } - - @Override - public boolean checkRecipe(ItemStack stack) { - final ArrayList<FluidStack> storedFluids = super.getStoredFluids(); - Collection<GT_Recipe> recipeList = GT_Recipe_Map.sTurbineFuels.mRecipeList; - - if((storedFluids.size() > 0 && recipeList != null)) { - - final Iterator<FluidStack> fluidsIterator = storedFluids.iterator(); - while(fluidsIterator.hasNext()) { - - final FluidStack hatchFluid = fluidsIterator.next(); - final Iterator<GT_Recipe> recipeIterator = recipeList.iterator(); - while(recipeIterator.hasNext()) { - - final GT_Recipe aFuel = recipeIterator.next(); - FluidStack liquid; - if((liquid = GT_Utility.getFluidForFilledItem(aFuel.getRepresentativeInput(0), true)) != null - && hatchFluid.isFluidEqual(liquid)) { - - liquid.amount = (EU_PER_TICK * 20) / aFuel.mSpecialValue; - - if(super.depleteInput(liquid)) { - - if(!super.depleteInput(Materials.Oxygen.getGas(OXYGEN_PER_SEC))) { - super.mEUt = 0; - super.mEfficiency = 0; - return false; - } - - super.mEUt = EU_PER_TICK; - super.mMaxProgresstime = 20; - super.mEfficiencyIncrease = 40; - if(super.mEfficiency == getMaxEfficiency(null)) { - super.addOutput(GT_ModHandler.getSteam(STEAM_PER_SEC)); - } - return true; - } - } - } - } - } - - super.mEUt = 0; - super.mEfficiency = 0; - return false; - } - - @Override - public boolean checkMachine(IGregTechTileEntity thisController, ItemStack guiSlotItem) { + return new ITexture[] {Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID)}; + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine( + aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), "MultiblockDisplay.png"); + } + + @Override + public boolean isCorrectMachinePart(ItemStack stack) { + return true; + } + + @Override + public boolean checkRecipe(ItemStack stack) { + final ArrayList<FluidStack> storedFluids = super.getStoredFluids(); + Collection<GT_Recipe> recipeList = GT_Recipe_Map.sTurbineFuels.mRecipeList; + + if ((storedFluids.size() > 0 && recipeList != null)) { + + final Iterator<FluidStack> fluidsIterator = storedFluids.iterator(); + while (fluidsIterator.hasNext()) { + + final FluidStack hatchFluid = fluidsIterator.next(); + final Iterator<GT_Recipe> recipeIterator = recipeList.iterator(); + while (recipeIterator.hasNext()) { + + final GT_Recipe aFuel = recipeIterator.next(); + FluidStack liquid; + if ((liquid = GT_Utility.getFluidForFilledItem(aFuel.getRepresentativeInput(0), true)) != null + && hatchFluid.isFluidEqual(liquid)) { + + liquid.amount = (EU_PER_TICK * 20) / aFuel.mSpecialValue; + + if (super.depleteInput(liquid)) { + + if (!super.depleteInput(Materials.Oxygen.getGas(OXYGEN_PER_SEC))) { + super.mEUt = 0; + super.mEfficiency = 0; + return false; + } + + super.mEUt = EU_PER_TICK; + super.mMaxProgresstime = 20; + super.mEfficiencyIncrease = 40; + if (super.mEfficiency == getMaxEfficiency(null)) { + super.addOutput(GT_ModHandler.getSteam(STEAM_PER_SEC)); + } + return true; + } + } + } + } + } + + super.mEUt = 0; + super.mEfficiency = 0; + return false; + } + + @Override + public boolean checkMachine(IGregTechTileEntity thisController, ItemStack guiSlotItem) { this.mCasing = 0; - if(!checkPiece(STRUCTURE_PIECE_MAIN, 1, 1, 0)) - return false; - - return (this.mCasing >= 12 && - this.mMaintenanceHatches.size() == 1 && - this.mInputHatches.size() >= 2 - ); - } - - @Override - public int getMaxEfficiency(ItemStack stack) { - return 10000; - } - - @Override - public int getPollutionPerTick(ItemStack stack) { - return 0; - } - - @Override - public int getDamageToComponent(ItemStack stack) { - return 0; - } - - @Override - public boolean explodesOnComponentBreak(ItemStack stack) { - return false; - } + if (!checkPiece(STRUCTURE_PIECE_MAIN, 1, 1, 0)) return false; + + return (this.mCasing >= 12 && this.mMaintenanceHatches.size() == 1 && this.mInputHatches.size() >= 2); + } + + @Override + public int getMaxEfficiency(ItemStack stack) { + return 10000; + } + + @Override + public int getPollutionPerTick(ItemStack stack) { + return 0; + } + + @Override + public int getDamageToComponent(ItemStack stack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack stack) { + return false; + } @Override public void construct(ItemStack itemStack, boolean b) { diff --git a/src/main/java/common/tileentities/GTMTE_SOFuelCellMK2.java b/src/main/java/common/tileentities/GTMTE_SOFuelCellMK2.java index de1e9cc82f..4438c0add1 100644 --- a/src/main/java/common/tileentities/GTMTE_SOFuelCellMK2.java +++ b/src/main/java/common/tileentities/GTMTE_SOFuelCellMK2.java @@ -1,15 +1,14 @@ package common.tileentities; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlockAnyMeta; +import static gregtech.api.enums.Textures.BlockIcons.*; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_HEAT_EXCHANGER_GLOW; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; -import cpw.mods.fml.common.registry.GameRegistry; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_EnhancedMultiBlockBase; -import gregtech.api.render.TextureFactory; - import common.Blocks; +import cpw.mods.fml.common.registry.GameRegistry; import gregtech.api.GregTech_API; import gregtech.api.enums.Materials; import gregtech.api.enums.Textures; @@ -17,35 +16,33 @@ import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_EnhancedMultiBlockBase; +import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; -import gregtech.api.util.GT_Utility; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; +import gregtech.api.util.GT_Utility; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlockAnyMeta; -import static gregtech.api.enums.Textures.BlockIcons.*; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_HEAT_EXCHANGER_GLOW; -import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; - -public class GTMTE_SOFuelCellMK2 extends GT_MetaTileEntity_EnhancedMultiBlockBase<GTMTE_SOFuelCellMK2> { +public class GTMTE_SOFuelCellMK2 extends GT_MetaTileEntity_EnhancedMultiBlockBase<GTMTE_SOFuelCellMK2> { - private final int OXYGEN_PER_SEC = 2000; - private final int EU_PER_TICK = 24576; // 100% Efficiency, 3A IV - private final int STEAM_PER_SEC = 96000; // SH Steam (10,800EU/t @ 150% Efficiency) + private final int OXYGEN_PER_SEC = 2000; + private final int EU_PER_TICK = 24576; // 100% Efficiency, 3A IV + private final int STEAM_PER_SEC = 96000; // SH Steam (10,800EU/t @ 150% Efficiency) - public GTMTE_SOFuelCellMK2(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - - } + public GTMTE_SOFuelCellMK2(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } - public GTMTE_SOFuelCellMK2(String aName) { - super(aName); - } + public GTMTE_SOFuelCellMK2(String aName) { + super(aName); + } @Override public IMetaTileEntity newMetaEntity(IGregTechTileEntity var1) { @@ -56,22 +53,25 @@ public class GTMTE_SOFuelCellMK2 extends GT_MetaTileEntity_EnhancedMultiBlockBa private static final int CASING_TEXTURE_ID = 48; private static final String STRUCTURE_PIECE_MAIN = "main"; - private static final IStructureDefinition<GTMTE_SOFuelCellMK2> STRUCTURE_DEFINITION = IStructureDefinition.<GTMTE_SOFuelCellMK2>builder() - .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ - {"ccc", "ccc", "ccc", "ccc", "ccc"}, - {"c~c", "geg", "geg", "geg", "cdc"}, - {"ccc", "ccc", "ccc", "ccc", "ccc"} - })) - .addElement('c', ofChain( - onElementPass(te -> te.mCasing++, ofBlock(GregTech_API.sBlockCasings4, 0)), - ofHatchAdder(GTMTE_SOFuelCellMK2::addInputToMachineList, CASING_TEXTURE_ID, 1), - ofHatchAdder(GTMTE_SOFuelCellMK2::addMaintenanceToMachineList, CASING_TEXTURE_ID, 1), - ofHatchAdder(GTMTE_SOFuelCellMK2::addOutputToMachineList, CASING_TEXTURE_ID, 1) - )) - .addElement('d', ofHatchAdder(GTMTE_SOFuelCellMK2::addDynamoToMachineList, CASING_TEXTURE_ID, 1)) - .addElement('g', ofBlockAnyMeta(GameRegistry.findBlock("IC2", "blockAlloyGlass"))) - .addElement('e', ofBlockAnyMeta(Blocks.gdcUnit)) - .build(); + private static final IStructureDefinition<GTMTE_SOFuelCellMK2> STRUCTURE_DEFINITION = + IStructureDefinition.<GTMTE_SOFuelCellMK2>builder() + .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][] { + {"ccc", "ccc", "ccc", "ccc", "ccc"}, + {"c~c", "geg", "geg", "geg", "cdc"}, + {"ccc", "ccc", "ccc", "ccc", "ccc"} + })) + .addElement( + 'c', + ofChain( + onElementPass(te -> te.mCasing++, ofBlock(GregTech_API.sBlockCasings4, 0)), + ofHatchAdder(GTMTE_SOFuelCellMK2::addInputToMachineList, CASING_TEXTURE_ID, 1), + ofHatchAdder( + GTMTE_SOFuelCellMK2::addMaintenanceToMachineList, CASING_TEXTURE_ID, 1), + ofHatchAdder(GTMTE_SOFuelCellMK2::addOutputToMachineList, CASING_TEXTURE_ID, 1))) + .addElement('d', ofHatchAdder(GTMTE_SOFuelCellMK2::addDynamoToMachineList, CASING_TEXTURE_ID, 1)) + .addElement('g', ofBlockAnyMeta(GameRegistry.findBlock("IC2", "blockAlloyGlass"))) + .addElement('e', ofBlockAnyMeta(Blocks.gdcUnit)) + .build(); @Override public IStructureDefinition<GTMTE_SOFuelCellMK2> getStructureDefinition() { @@ -82,133 +82,152 @@ public class GTMTE_SOFuelCellMK2 extends GT_MetaTileEntity_EnhancedMultiBlockBa protected GT_Multiblock_Tooltip_Builder createTooltip() { final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); tt.addMachineType("Gas Turbine") - .addInfo("Oxidizes gas fuels to generate electricity without polluting the environment") - .addInfo("Consumes up to" + (EU_PER_TICK * 20) + "EU worth of fuel with up to 100% efficiency each second") - .addInfo("Nitrobenzene and other gas fuels above 1M EU/bucket are more efficient") - .addInfo("Steam production requires the SOFC to heat up completely first") - .addInfo("Outputs " + EU_PER_TICK + "EU/t and " + STEAM_PER_SEC + "L/s Steam") - .addInfo("Additionally, requires " + OXYGEN_PER_SEC + "L/s Oxygen gas") - .addSeparator() - .beginStructureBlock(3, 3, 5, false) - .addController("Front center") - .addCasingInfo("Robust Tungstensteel Machine Casing", 12) - .addOtherStructurePart("GDC Ceramic Electrolyte Unit", "3x, Center 1x1x3") - .addOtherStructurePart("Reinforced Glass", "6x, touching the electrolyte units on the horizontal sides") - .addDynamoHatch("Back center", 1) - .addMaintenanceHatch("Any casing") - .addInputHatch("Fuel, any casing") - .addInputHatch("Oxygen, any casing") - .addOutputHatch("Superheated Steam, any casing") - .toolTipFinisher("KekzTech"); + .addInfo("Oxidizes gas fuels to generate electricity without polluting the environment") + .addInfo("Consumes up to" + (EU_PER_TICK * 20) + + "EU worth of fuel with up to 100% efficiency each second") + .addInfo("Nitrobenzene and other gas fuels above 1M EU/bucket are more efficient") + .addInfo("Steam production requires the SOFC to heat up completely first") + .addInfo("Outputs " + EU_PER_TICK + "EU/t and " + STEAM_PER_SEC + "L/s Steam") + .addInfo("Additionally, requires " + OXYGEN_PER_SEC + "L/s Oxygen gas") + .addSeparator() + .beginStructureBlock(3, 3, 5, false) + .addController("Front center") + .addCasingInfo("Robust Tungstensteel Machine Casing", 12) + .addOtherStructurePart("GDC Ceramic Electrolyte Unit", "3x, Center 1x1x3") + .addOtherStructurePart("Reinforced Glass", "6x, touching the electrolyte units on the horizontal sides") + .addDynamoHatch("Back center", 1) + .addMaintenanceHatch("Any casing") + .addInputHatch("Fuel, any casing") + .addInputHatch("Oxygen, any casing") + .addOutputHatch("Superheated Steam, any casing") + .toolTipFinisher("KekzTech"); return tt; } - @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, - final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + @Override + public ITexture[] getTexture( + final IGregTechTileEntity aBaseMetaTileEntity, + final byte aSide, + final byte aFacing, + final byte aColorIndex, + final boolean aActive, + final boolean aRedstone) { if (aSide == aFacing) { if (aActive) - return new ITexture[]{ + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID), - TextureFactory.builder().addIcon(OVERLAY_FRONT_HEAT_EXCHANGER_ACTIVE).extFacing().build(), - TextureFactory.builder().addIcon(OVERLAY_FRONT_HEAT_EXCHANGER_ACTIVE_GLOW).extFacing().glow().build()}; - return new ITexture[]{ + TextureFactory.builder() + .addIcon(OVERLAY_FRONT_HEAT_EXCHANGER_ACTIVE) + .extFacing() + .build(), + TextureFactory.builder() + .addIcon(OVERLAY_FRONT_HEAT_EXCHANGER_ACTIVE_GLOW) + .extFacing() + .glow() + .build() + }; + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID), - TextureFactory.builder().addIcon(OVERLAY_FRONT_HEAT_EXCHANGER).extFacing().build(), - TextureFactory.builder().addIcon(OVERLAY_FRONT_HEAT_EXCHANGER_GLOW).extFacing().glow().build()}; + TextureFactory.builder() + .addIcon(OVERLAY_FRONT_HEAT_EXCHANGER) + .extFacing() + .build(), + TextureFactory.builder() + .addIcon(OVERLAY_FRONT_HEAT_EXCHANGER_GLOW) + .extFacing() + .glow() + .build() + }; + } + return new ITexture[] {Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID)}; + } + + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine( + aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), "MultiblockDisplay.png"); + } + + @Override + public boolean isCorrectMachinePart(ItemStack stack) { + return true; + } + + @Override + public boolean checkRecipe(ItemStack stack) { + final ArrayList<FluidStack> storedFluids = super.getStoredFluids(); + Collection<GT_Recipe> recipeList = GT_Recipe_Map.sTurbineFuels.mRecipeList; + + if ((storedFluids.size() > 0 && recipeList != null)) { + + final Iterator<FluidStack> fluidsIterator = storedFluids.iterator(); + while (fluidsIterator.hasNext()) { + + final FluidStack hatchFluid = fluidsIterator.next(); + final Iterator<GT_Recipe> recipeIterator = recipeList.iterator(); + while (recipeIterator.hasNext()) { + + final GT_Recipe aFuel = recipeIterator.next(); + FluidStack liquid; + if ((liquid = GT_Utility.getFluidForFilledItem(aFuel.getRepresentativeInput(0), true)) != null + && hatchFluid.isFluidEqual(liquid)) { + + liquid.amount = (int) (Math.floor((EU_PER_TICK * 20) / aFuel.mSpecialValue) + / Math.max(1, aFuel.mSpecialValue / 1000)); + + if (super.depleteInput(liquid)) { + + if (!super.depleteInput(Materials.Oxygen.getGas(OXYGEN_PER_SEC))) { + super.mEUt = 0; + super.mEfficiency = 0; + return false; + } + + super.mEUt = EU_PER_TICK; + super.mMaxProgresstime = 20; + super.mEfficiencyIncrease = 80; + if (super.mEfficiency == getMaxEfficiency(null)) { + super.addOutput(FluidRegistry.getFluidStack("ic2superheatedsteam", STEAM_PER_SEC)); + } + return true; + } + } + } + } } - return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(CASING_TEXTURE_ID)}; - } - - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), - "MultiblockDisplay.png"); - } - - @Override - public boolean isCorrectMachinePart(ItemStack stack) { - return true; - } - - @Override - public boolean checkRecipe(ItemStack stack) { - final ArrayList<FluidStack> storedFluids = super.getStoredFluids(); - Collection<GT_Recipe> recipeList = GT_Recipe_Map.sTurbineFuels.mRecipeList; - - if((storedFluids.size() > 0 && recipeList != null)) { - - final Iterator<FluidStack> fluidsIterator = storedFluids.iterator(); - while(fluidsIterator.hasNext()) { - - final FluidStack hatchFluid = fluidsIterator.next(); - final Iterator<GT_Recipe> recipeIterator = recipeList.iterator(); - while(recipeIterator.hasNext()) { - - final GT_Recipe aFuel = recipeIterator.next(); - FluidStack liquid; - if((liquid = GT_Utility.getFluidForFilledItem(aFuel.getRepresentativeInput(0), true)) != null - && hatchFluid.isFluidEqual(liquid)) { - - liquid.amount = (int) (Math.floor((EU_PER_TICK * 20) / aFuel.mSpecialValue) / Math.max(1, aFuel.mSpecialValue / 1000)); - - if(super.depleteInput(liquid)) { - - if(!super.depleteInput(Materials.Oxygen.getGas(OXYGEN_PER_SEC))) { - super.mEUt = 0; - super.mEfficiency = 0; - return false; - } - - super.mEUt = EU_PER_TICK; - super.mMaxProgresstime = 20; - super.mEfficiencyIncrease = 80; - if(super.mEfficiency == getMaxEfficiency(null)) { - super.addOutput(FluidRegistry.getFluidStack("ic2superheatedsteam", STEAM_PER_SEC)); - } - return true; - } - } - } - } - } - - super.mEUt = 0; - super.mEfficiency = 0; - return false; - } + + super.mEUt = 0; + super.mEfficiency = 0; + return false; + } @Override public boolean checkMachine(IGregTechTileEntity thisController, ItemStack guiSlotItem) { this.mCasing = 0; - if(!checkPiece(STRUCTURE_PIECE_MAIN, 1, 1, 0)) - return false; + if (!checkPiece(STRUCTURE_PIECE_MAIN, 1, 1, 0)) return false; - return (this.mCasing >= 12 && - this.mMaintenanceHatches.size() == 1 && - this.mInputHatches.size() >= 2 - ); + return (this.mCasing >= 12 && this.mMaintenanceHatches.size() == 1 && this.mInputHatches.size() >= 2); } - @Override - public int getMaxEfficiency(ItemStack stack) { - return 10000; - } - - @Override - public int getPollutionPerTick(ItemStack stack) { - return 0; - } - - @Override - public int getDamageToComponent(ItemStack stack) { - return 0; - } - - @Override - public boolean explodesOnComponentBreak(ItemStack stack) { - return false; - } + @Override + public int getMaxEfficiency(ItemStack stack) { + return 10000; + } + + @Override + public int getPollutionPerTick(ItemStack stack) { + return 0; + } + + @Override + public int getDamageToComponent(ItemStack stack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack stack) { + return false; + } @Override public void construct(ItemStack itemStack, boolean b) { diff --git a/src/main/java/common/tileentities/GTMTE_SpaceElevator.java b/src/main/java/common/tileentities/GTMTE_SpaceElevator.java index 3469528f78..cabf4552d6 100644 --- a/src/main/java/common/tileentities/GTMTE_SpaceElevator.java +++ b/src/main/java/common/tileentities/GTMTE_SpaceElevator.java @@ -9,19 +9,17 @@ import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; import gregtech.api.objects.GT_RenderedTexture; +import java.util.ArrayList; +import java.util.HashSet; import net.minecraft.block.Block; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.common.util.ForgeDirection; -import org.lwjgl.input.Keyboard; import util.Vector3i; import util.Vector3ic; -import java.util.ArrayList; -import java.util.HashSet; - public class GTMTE_SpaceElevator extends GT_MetaTileEntity_MultiBlockBase { private static final Block BASE_BLOCK = Blocks.spaceElevatorStructure; @@ -29,7 +27,7 @@ public class GTMTE_SpaceElevator extends GT_MetaTileEntity_MultiBlockBase { private static final Block TETHER_BLOCK = Blocks.spaceElevatorTether; private static final int BASE_META = 0; private static final int COIL_HOLDER_META = 1; - private final static String glassNameBorosilicate = "BW_GlasBlocks"; + private static final String glassNameBorosilicate = "BW_GlasBlocks"; private static final int HATCH_OVERLAY_ID = 16; // Scan positions for capacitor banks @@ -47,7 +45,9 @@ public class GTMTE_SpaceElevator extends GT_MetaTileEntity_MultiBlockBase { super(aID, aName, aNameRegional); } - public GTMTE_SpaceElevator(String aName) { super(aName); } + public GTMTE_SpaceElevator(String aName) { + super(aName); + } @Override public IMetaTileEntity newMetaEntity(IGregTechTileEntity var1) { @@ -56,8 +56,8 @@ public class GTMTE_SpaceElevator extends GT_MetaTileEntity_MultiBlockBase { @Override public String[] getDescription() { - return new String[]{"Disabled"}; - /* + return new String[] {"Disabled"}; + /* final MultiBlockTooltipBuilder b = new MultiBlockTooltipBuilder(); b.addInfo("Access for your Space Station!") .addInfo("Check out the wiki on my github if you are having trouble with the structure") @@ -82,20 +82,30 @@ public class GTMTE_SpaceElevator extends GT_MetaTileEntity_MultiBlockBase { } @Override - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, - boolean aActive, boolean aRedstone) { - ITexture[] sTexture = new ITexture[]{new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS, - Dyes.getModulation(-1, Dyes._NULL.mRGBa))}; + public ITexture[] getTexture( + IGregTechTileEntity aBaseMetaTileEntity, + byte aSide, + byte aFacing, + byte aColorIndex, + boolean aActive, + boolean aRedstone) { + ITexture[] sTexture = new ITexture[] { + new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS, Dyes.getModulation(-1, Dyes._NULL.mRGBa)) + }; if (aSide == aFacing && aActive) { - sTexture = new ITexture[]{new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS_YELLOW, - Dyes.getModulation(-1, Dyes._NULL.mRGBa))}; + sTexture = new ITexture[] { + new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS_YELLOW, + Dyes.getModulation(-1, Dyes._NULL.mRGBa)) + }; } return sTexture; } public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), - "MultiblockDisplay.png"); + return new GT_GUIContainer_MultiMachine( + aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), "MultiblockDisplay.png"); } @Override @@ -127,7 +137,7 @@ public class GTMTE_SpaceElevator extends GT_MetaTileEntity_MultiBlockBase { @Override public boolean checkMachine(IGregTechTileEntity thisController, ItemStack guiSlotItem) { // Make sure the controller is either facing up or down - if(thisController.getFrontFacing() > 1) { + if (thisController.getFrontFacing() > 1) { return false; } @@ -135,17 +145,16 @@ public class GTMTE_SpaceElevator extends GT_MetaTileEntity_MultiBlockBase { final Vector3ic forgeDirection = new Vector3i( ForgeDirection.getOrientation(thisController.getBackFacing()).offsetX, ForgeDirection.getOrientation(thisController.getBackFacing()).offsetY, - ForgeDirection.getOrientation(thisController.getBackFacing()).offsetZ - ); + ForgeDirection.getOrientation(thisController.getBackFacing()).offsetZ); boolean formationChecklist = true; int minCasingAmount = 320; int firstCoilMeta = -1; capacitors.clear(); // Base floor - for(int X = -7; X <= 7; X++){ - for(int Y = -7; Y <= 7; Y++){ - if(X == 0 && Y == 0){ + for (int X = -7; X <= 7; X++) { + for (int Y = -7; Y <= 7; Y++) { + if (X == 0 && Y == 0) { continue; // Skip controller } @@ -154,8 +163,9 @@ public class GTMTE_SpaceElevator extends GT_MetaTileEntity_MultiBlockBase { thisController.getIGregTechTileEntityOffset(offset.x(), offset.y(), offset.z()); // Tries to add TE as either of those kinds of hatches. - // The number is the texture index number for the texture that needs to be painted over the hatch texture - if ( !super.addMaintenanceToMachineList(currentTE, HATCH_OVERLAY_ID) + // The number is the texture index number for the texture that needs to be painted over the hatch + // texture + if (!super.addMaintenanceToMachineList(currentTE, HATCH_OVERLAY_ID) && !this.addEnergyInputToMachineList(currentTE, HATCH_OVERLAY_ID)) { // If it's not a hatch, is it the right casing for this machine? Check block and block meta. @@ -171,34 +181,39 @@ public class GTMTE_SpaceElevator extends GT_MetaTileEntity_MultiBlockBase { } System.out.println(""); // Capacitor banks - for(int bank = 0; bank < 4; bank++) { - for(int Z = 1; Z <= 5; Z++) { - for(int scan = 0; scan < 5; scan++){ - final Vector3ic offset = rotateOffsetVector(forgeDirection, + for (int bank = 0; bank < 4; bank++) { + for (int Z = 1; Z <= 5; Z++) { + for (int scan = 0; scan < 5; scan++) { + final Vector3ic offset = rotateOffsetVector( + forgeDirection, bankOffsetsX[bank] + scanOffsetsX[scan], bankOffsetsY[bank] + scanOffsetsY[scan], Z); - if(Z == 1 || Z == 5) { + if (Z == 1 || Z == 5) { // Check for casings - if(thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == BASE_BLOCK + if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == BASE_BLOCK && thisController.getMetaIDOffset(offset.x(), offset.y(), offset.z()) == BASE_META) { minCasingAmount--; } else { formationChecklist = false; } } else { - if(scan == 4){ + if (scan == 4) { // Check for capacitors - final TileEntity te = thisController.getTileEntityOffset(offset.x(), offset.y(), offset.z()); - if(thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == CAP_BLOCK - && te instanceof TE_SpaceElevatorCapacitor) { + final TileEntity te = + thisController.getTileEntityOffset(offset.x(), offset.y(), offset.z()); + if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == CAP_BLOCK + && te instanceof TE_SpaceElevatorCapacitor) { capacitors.add((TE_SpaceElevatorCapacitor) te); } else { formationChecklist = false; } } else { // Check for Glass - if(!thisController.getBlockOffset(offset.x(), offset.y(), offset.z()).getUnlocalizedName().equals(glassNameBorosilicate)) { + if (!thisController + .getBlockOffset(offset.x(), offset.y(), offset.z()) + .getUnlocalizedName() + .equals(glassNameBorosilicate)) { formationChecklist = false; } } @@ -212,11 +227,11 @@ public class GTMTE_SpaceElevator extends GT_MetaTileEntity_MultiBlockBase { // Coils - if(minCasingAmount > 0) { + if (minCasingAmount > 0) { formationChecklist = false; } - for(TE_SpaceElevatorCapacitor cap : capacitors){ + for (TE_SpaceElevatorCapacitor cap : capacitors) { cap.setIsDamaged(false); } @@ -228,9 +243,10 @@ public class GTMTE_SpaceElevator extends GT_MetaTileEntity_MultiBlockBase { final ArrayList<String> ll = new ArrayList<>(); ll.add(EnumChatFormatting.YELLOW + "Operational Data:" + EnumChatFormatting.RESET); - ll.add("Maintenance Status: " + ((super.getRepairStatus() == super.getIdealStatus()) - ? EnumChatFormatting.GREEN + "Working perfectly" + EnumChatFormatting.RESET - : EnumChatFormatting.RED + "Has Problems" + EnumChatFormatting.RESET)); + ll.add("Maintenance Status: " + + ((super.getRepairStatus() == super.getIdealStatus()) + ? EnumChatFormatting.GREEN + "Working perfectly" + EnumChatFormatting.RESET + : EnumChatFormatting.RED + "Has Problems" + EnumChatFormatting.RESET)); ll.add("---------------------------------------------"); final String[] a = new String[ll.size()]; @@ -243,14 +259,22 @@ public class GTMTE_SpaceElevator extends GT_MetaTileEntity_MultiBlockBase { } @Override - public int getMaxEfficiency(ItemStack stack) { return 10000; } + public int getMaxEfficiency(ItemStack stack) { + return 10000; + } @Override - public int getPollutionPerTick(ItemStack stack) { return 0; } + public int getPollutionPerTick(ItemStack stack) { + return 0; + } @Override - public int getDamageToComponent(ItemStack stack) { return 0; } + public int getDamageToComponent(ItemStack stack) { + return 0; + } @Override - public boolean explodesOnComponentBreak(ItemStack stack) { return false; } + public boolean explodesOnComponentBreak(ItemStack stack) { + return false; + } } diff --git a/src/main/java/common/tileentities/GTMTE_TFFTMultiHatch.java b/src/main/java/common/tileentities/GTMTE_TFFTMultiHatch.java index fc2579604a..8c992f8cb0 100644 --- a/src/main/java/common/tileentities/GTMTE_TFFTMultiHatch.java +++ b/src/main/java/common/tileentities/GTMTE_TFFTMultiHatch.java @@ -1,6 +1,5 @@ package common.tileentities; -import client.GTTexture; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -8,6 +7,7 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Utility; +import java.util.HashMap; import kekztech.MultiFluidHandler; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -18,16 +18,16 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; -import java.util.HashMap; - public class GTMTE_TFFTMultiHatch extends GT_MetaTileEntity_Hatch { private static final HashMap<Integer, Integer> vals = new HashMap<>(); + static { vals.put(3, 2000); vals.put(5, 20000); vals.put(7, 200000); } + private static final int INV_SLOT_COUNT = 2; private MultiFluidHandler mfh; @@ -35,10 +35,10 @@ public class GTMTE_TFFTMultiHatch extends GT_MetaTileEntity_Hatch { public GTMTE_TFFTMultiHatch(int aID, String aName, String aNameRegional, int aTier) { super(aID, aName, aNameRegional, aTier, INV_SLOT_COUNT, new String[] { - "All-in-one access for the T.F.F.T", - "Right-click with a screwdriver to toggle auto-output", - "Throughput: " + vals.get(aTier) + "L/s per fluid"} - ); + "All-in-one access for the T.F.F.T", + "Right-click with a screwdriver to toggle auto-output", + "Throughput: " + vals.get(aTier) + "L/s per fluid" + }); } public GTMTE_TFFTMultiHatch(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { @@ -67,14 +67,16 @@ public class GTMTE_TFFTMultiHatch extends GT_MetaTileEntity_Hatch { @Override public ITexture[] getTexturesActive(ITexture aBaseTexture) { - //return new ITexture[]{aBaseTexture, new GT_RenderedTexture(GTTexture.MULTI_HATCH_ON)}; - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_PIPE_STEEL)}; + // return new ITexture[]{aBaseTexture, new GT_RenderedTexture(GTTexture.MULTI_HATCH_ON)}; + return new ITexture[] {aBaseTexture, new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_PIPE_STEEL)}; } @Override public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - //return new ITexture[]{aBaseTexture, new GT_RenderedTexture(GTTexture.MULTI_HATCH_OFF)}; - return new ITexture[]{aBaseTexture, new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_PIPE_POLYTETRAFLUOROETHYLENE)}; + // return new ITexture[]{aBaseTexture, new GT_RenderedTexture(GTTexture.MULTI_HATCH_OFF)}; + return new ITexture[] { + aBaseTexture, new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_PIPE_POLYTETRAFLUOROETHYLENE) + }; } @Override @@ -101,7 +103,7 @@ public class GTMTE_TFFTMultiHatch extends GT_MetaTileEntity_Hatch { public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { super.onPreTick(aBaseMetaTileEntity, aTick); if (aBaseMetaTileEntity.isServerSide() && mfh != null) { - if(outputting && (aTick % 20 == 0)) { + if (outputting && (aTick % 20 == 0)) { doAutoOutputPerSecond(aBaseMetaTileEntity); } } @@ -114,14 +116,15 @@ public class GTMTE_TFFTMultiHatch extends GT_MetaTileEntity_Hatch { */ private void doAutoOutputPerSecond(IGregTechTileEntity aBaseMetaTileEntity) { final ForgeDirection outSide = ForgeDirection.getOrientation(aBaseMetaTileEntity.getFrontFacing()); - final TileEntity adjacentTE = aBaseMetaTileEntity.getTileEntityOffset(outSide.offsetX, outSide.offsetY, outSide.offsetZ); - if(adjacentTE instanceof IFluidHandler) { + final TileEntity adjacentTE = + aBaseMetaTileEntity.getTileEntityOffset(outSide.offsetX, outSide.offsetY, outSide.offsetZ); + if (adjacentTE instanceof IFluidHandler) { final IFluidHandler adjFH = (IFluidHandler) adjacentTE; // Cycle through fluids - for(int i = 0; i < mfh.getDistinctFluids(); 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())) { + if (adjFH.canFill(outSide.getOpposite(), fluidCopy.getFluid())) { // Limit to output rate fluidCopy.amount = Math.min(fluidCopy.amount, vals.get(super.mTier)); @@ -136,7 +139,6 @@ public class GTMTE_TFFTMultiHatch extends GT_MetaTileEntity_Hatch { mfh.pullFluid(fluidCopy, true); } } - } } @@ -166,16 +168,15 @@ public class GTMTE_TFFTMultiHatch extends GT_MetaTileEntity_Hatch { */ @Override public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { - if(mfh != null) { + if (mfh != null) { final FluidStack drain = mfh.getFluidCopy(0); - if(drain != null) { + 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) - ); + mfh.pullFluid(new FluidStack(drain.getFluid(), maxDrain), selectedSlot, doDrain)); } } return null; @@ -183,14 +184,13 @@ public class GTMTE_TFFTMultiHatch extends GT_MetaTileEntity_Hatch { @Override public FluidTankInfo[] getTankInfo(ForgeDirection from) { - if (mfh == null) - return null; + if (mfh == null) return null; FluidStack[] fluids = mfh.getAllFluids(); int length = fluids.length; int maxCapcity = mfh.getCapacity(); FluidTankInfo[] tankInfo = new FluidTankInfo[length]; for (int i = 0; i < length; i++) { - tankInfo[i] = new FluidTankInfo(fluids[i],maxCapcity); + tankInfo[i] = new FluidTankInfo(fluids[i], maxCapcity); } return tankInfo; } diff --git a/src/main/java/common/tileentities/TE_IchorJar.java b/src/main/java/common/tileentities/TE_IchorJar.java index 1baa06a969..b5e85a9f2b 100644 --- a/src/main/java/common/tileentities/TE_IchorJar.java +++ b/src/main/java/common/tileentities/TE_IchorJar.java @@ -3,8 +3,8 @@ package common.tileentities; import thaumcraft.common.tiles.TileJarFillable; public class TE_IchorJar extends TileJarFillable { - - public TE_IchorJar() { - super.maxAmount = 4096; - } + + public TE_IchorJar() { + super.maxAmount = 4096; + } } diff --git a/src/main/java/common/tileentities/TE_IchorVoidJar.java b/src/main/java/common/tileentities/TE_IchorVoidJar.java index 6644461a88..9046b2bc33 100644 --- a/src/main/java/common/tileentities/TE_IchorVoidJar.java +++ b/src/main/java/common/tileentities/TE_IchorVoidJar.java @@ -3,8 +3,8 @@ package common.tileentities; import thaumcraft.common.tiles.TileJarFillableVoid; public class TE_IchorVoidJar extends TileJarFillableVoid { - - public TE_IchorVoidJar() { - super.maxAmount = 4096; - } + + public TE_IchorVoidJar() { + super.maxAmount = 4096; + } } diff --git a/src/main/java/common/tileentities/TE_ItemProxyCable.java b/src/main/java/common/tileentities/TE_ItemProxyCable.java index f4caab3d36..ac080ceab2 100644 --- a/src/main/java/common/tileentities/TE_ItemProxyCable.java +++ b/src/main/java/common/tileentities/TE_ItemProxyCable.java @@ -4,118 +4,155 @@ import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; public class TE_ItemProxyCable extends TileEntity { - - private static final float THICKNESS = 0.5F; - private byte connections = 0; - private byte connectionAllowed = 63; - private String idCache = null; - - public TE_ItemProxyCable() { - } + private static final float THICKNESS = 0.5F; + private byte connections = 0; + private byte connectionAllowed = 63; + private String idCache = null; - @Override - public void updateEntity() { - // Check all 6 sides and connect the conduit if it is allowed to - for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { - final TileEntity te = super.getWorldObj().getTileEntity( - super.xCoord + side.offsetX, - super.yCoord + side.offsetY, - super.zCoord + side.offsetZ); - if(te instanceof TE_ItemProxyCable) { - final TE_ItemProxyCable cable = (TE_ItemProxyCable) te; - setConnection(side, cable.isConnectionAllowed(side.getOpposite())); - } else { - setConnection(side, false); - } - } - } - - public static float getThickness() { - return THICKNESS; - } - - /** - * Builds a simple unique identifier for this TileEntity by appending - * the x, y, and z coordinates in a string. - * - * @return unique identifier for this TileEntity - */ - public String getIdentifier() { - if(idCache == null) { - idCache = "" + super.xCoord + super.yCoord + super.zCoord; - return idCache; - } else { - return idCache; - } - } - - /** - * 0 0 0 0 0 0 0 0 = 0 -> no connection </br> - * 0 0 0 0 0 0 0 1 = 1 -> down </br> - * 0 0 0 0 0 0 1 0 = 2 -> up </br> - * 0 0 0 0 0 1 0 0 = 4 -> north </br> - * 0 0 0 0 1 0 0 0 = 8 -> south </br> - * 0 0 0 1 0 0 0 0 = 16 -> west </br> - * 0 0 1 0 0 0 0 0 = 32 -> east </br> - * - * @param side - * The side for which to set the connection status. - * @param connected - * Whether this side should be connected or not - * @return - * True if the connection was allowed - */ - public boolean setConnection(ForgeDirection side, boolean connected) { - if(isConnectionAllowed(side)){ - switch(side) { - case DOWN: connections = (byte) ((connected) ? connections | 1 : connections ^ 1); break; - case UP: connections = (byte) ((connected) ? connections | 2 : connections ^ 2); break; - case NORTH: connections = (byte) ((connected) ? connections | 4 : connections ^ 4); break; - case SOUTH: connections = (byte) ((connected) ? connections | 8 : connections ^ 8); break; - case WEST: connections = (byte) ((connected) ? connections | 16 : connections ^ 16); break; - case EAST: connections = (byte) ((connected) ? connections | 32 : connections ^ 32); break; - default: return false; - } - return true; - } else { - return false; - } - } - - public boolean isConnected(ForgeDirection side) { - switch(side) { - case DOWN: return (connections & 1) == 1; - case UP: return (connections & 2) == 2; - case NORTH: return (connections & 4) == 4; - case SOUTH: return (connections & 8) == 8; - case WEST: return (connections & 16) == 16; - case EAST: return (connections & 32) == 32; - default: return false; - } - } + public TE_ItemProxyCable() {} - public void setConnectionAllowed(ForgeDirection side, boolean allowed) { - switch(side) { - case DOWN: connectionAllowed = (byte) ((allowed) ? connectionAllowed | 1 : connectionAllowed ^ 1); break; - case UP: connectionAllowed = (byte) ((allowed) ? connectionAllowed | 2 : connectionAllowed ^ 2); break; - case NORTH: connectionAllowed = (byte) ((allowed) ? connectionAllowed | 4 : connectionAllowed ^ 4); break; - case SOUTH: connectionAllowed = (byte) ((allowed) ? connectionAllowed | 8 : connectionAllowed ^ 8); break; - case WEST: connectionAllowed = (byte) ((allowed) ? connectionAllowed | 16 : connectionAllowed ^ 16); break; - case EAST: connectionAllowed = (byte) ((allowed) ? connectionAllowed | 32 : connectionAllowed ^ 32); break; - default: break; - } - } + @Override + public void updateEntity() { + // Check all 6 sides and connect the conduit if it is allowed to + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + final TileEntity te = super.getWorldObj() + .getTileEntity( + super.xCoord + side.offsetX, super.yCoord + side.offsetY, super.zCoord + side.offsetZ); + if (te instanceof TE_ItemProxyCable) { + final TE_ItemProxyCable cable = (TE_ItemProxyCable) te; + setConnection(side, cable.isConnectionAllowed(side.getOpposite())); + } else { + setConnection(side, false); + } + } + } - public boolean isConnectionAllowed(ForgeDirection side) { - switch(side) { - case DOWN: return (connectionAllowed & 1) == 1; - case UP: return (connectionAllowed & 2) == 2; - case NORTH: return (connectionAllowed & 4) == 4; - case SOUTH: return (connectionAllowed & 8) == 8; - case WEST: return (connectionAllowed & 16) == 16; - case EAST: return (connectionAllowed & 32) == 32; - default: return false; - } - } + public static float getThickness() { + return THICKNESS; + } + + /** + * Builds a simple unique identifier for this TileEntity by appending + * the x, y, and z coordinates in a string. + * + * @return unique identifier for this TileEntity + */ + public String getIdentifier() { + if (idCache == null) { + idCache = "" + super.xCoord + super.yCoord + super.zCoord; + return idCache; + } else { + return idCache; + } + } + + /** + * 0 0 0 0 0 0 0 0 = 0 -> no connection </br> + * 0 0 0 0 0 0 0 1 = 1 -> down </br> + * 0 0 0 0 0 0 1 0 = 2 -> up </br> + * 0 0 0 0 0 1 0 0 = 4 -> north </br> + * 0 0 0 0 1 0 0 0 = 8 -> south </br> + * 0 0 0 1 0 0 0 0 = 16 -> west </br> + * 0 0 1 0 0 0 0 0 = 32 -> east </br> + * + * @param side + * The side for which to set the connection status. + * @param connected + * Whether this side should be connected or not + * @return + * True if the connection was allowed + */ + public boolean setConnection(ForgeDirection side, boolean connected) { + if (isConnectionAllowed(side)) { + switch (side) { + case DOWN: + connections = (byte) ((connected) ? connections | 1 : connections ^ 1); + break; + case UP: + connections = (byte) ((connected) ? connections | 2 : connections ^ 2); + break; + case NORTH: + connections = (byte) ((connected) ? connections | 4 : connections ^ 4); + break; + case SOUTH: + connections = (byte) ((connected) ? connections | 8 : connections ^ 8); + break; + case WEST: + connections = (byte) ((connected) ? connections | 16 : connections ^ 16); + break; + case EAST: + connections = (byte) ((connected) ? connections | 32 : connections ^ 32); + break; + default: + return false; + } + return true; + } else { + return false; + } + } + + public boolean isConnected(ForgeDirection side) { + switch (side) { + case DOWN: + return (connections & 1) == 1; + case UP: + return (connections & 2) == 2; + case NORTH: + return (connections & 4) == 4; + case SOUTH: + return (connections & 8) == 8; + case WEST: + return (connections & 16) == 16; + case EAST: + return (connections & 32) == 32; + default: + return false; + } + } + + public void setConnectionAllowed(ForgeDirection side, boolean allowed) { + switch (side) { + case DOWN: + connectionAllowed = (byte) ((allowed) ? connectionAllowed | 1 : connectionAllowed ^ 1); + break; + case UP: + connectionAllowed = (byte) ((allowed) ? connectionAllowed | 2 : connectionAllowed ^ 2); + break; + case NORTH: + connectionAllowed = (byte) ((allowed) ? connectionAllowed | 4 : connectionAllowed ^ 4); + break; + case SOUTH: + connectionAllowed = (byte) ((allowed) ? connectionAllowed | 8 : connectionAllowed ^ 8); + break; + case WEST: + connectionAllowed = (byte) ((allowed) ? connectionAllowed | 16 : connectionAllowed ^ 16); + break; + case EAST: + connectionAllowed = (byte) ((allowed) ? connectionAllowed | 32 : connectionAllowed ^ 32); + break; + default: + break; + } + } + + public boolean isConnectionAllowed(ForgeDirection side) { + switch (side) { + case DOWN: + return (connectionAllowed & 1) == 1; + case UP: + return (connectionAllowed & 2) == 2; + case NORTH: + return (connectionAllowed & 4) == 4; + case SOUTH: + return (connectionAllowed & 8) == 8; + case WEST: + return (connectionAllowed & 16) == 16; + case EAST: + return (connectionAllowed & 32) == 32; + default: + return false; + } + } } diff --git a/src/main/java/common/tileentities/TE_ItemProxyEndpoint.java b/src/main/java/common/tileentities/TE_ItemProxyEndpoint.java index 1eca1ff3df..88a8ef8bda 100644 --- a/src/main/java/common/tileentities/TE_ItemProxyEndpoint.java +++ b/src/main/java/common/tileentities/TE_ItemProxyEndpoint.java @@ -1,7 +1,6 @@ package common.tileentities; import java.util.HashSet; - import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; @@ -11,169 +10,168 @@ import net.minecraftforge.common.util.ForgeDirection; public class TE_ItemProxyEndpoint extends TileEntity implements ISidedInventory { - private byte channel = -1; - private IInventory proxyInventory = null; - private int tickCounter = 0; - - public TE_ItemProxyEndpoint() { - channel = 0; - } - - public void setChannel(byte channel) { - this.channel = channel; - } - - public int getChannel() { return channel; } - - @Override - public void updateEntity() { - if(tickCounter == 20) { - if(channel != -1) { - proxyInventory = searchSource(); - } - tickCounter = 0; - } - tickCounter++; - } - - private TE_ItemProxySource searchSource() { - - final HashSet<TE_ItemProxySource> sources = new HashSet<>(); - final HashSet<String> visited = new HashSet<>(); - - for(ForgeDirection next : ForgeDirection.VALID_DIRECTIONS) { - final TileEntity te = super.getWorldObj().getTileEntity( - super.xCoord + next.offsetX, - super.yCoord + next.offsetY, - super.zCoord + next.offsetZ); - if(te instanceof TE_ItemProxyCable) { - final TE_ItemProxyCable cable = (TE_ItemProxyCable) te; - if(cable.isConnected(next.getOpposite())) { - searchSourceRecursive(sources, visited, next.getOpposite(), cable); - } - } - } - - if(sources.isEmpty()) { - return null; - } else { - return sources.iterator().next(); - } - - } - - private void searchSourceRecursive(HashSet<TE_ItemProxySource> sources, HashSet<String> visited, - ForgeDirection from, TE_ItemProxyCable nextTarget) { - - if(!visited.contains(nextTarget.getIdentifier())) { - visited.add(nextTarget.getIdentifier()); - - for(ForgeDirection next : ForgeDirection.VALID_DIRECTIONS) { - if(next != from) { - final TileEntity te = super.getWorldObj().getTileEntity( - nextTarget.xCoord + next.offsetX, - nextTarget.yCoord + next.offsetY, - nextTarget.zCoord + next.offsetZ); - if(te instanceof TE_ItemProxyCable) { - final TE_ItemProxyCable cable = (TE_ItemProxyCable) te; - if(cable.isConnected(next.getOpposite())) { - searchSourceRecursive(sources, visited, next.getOpposite(), cable); - } - } else if (te instanceof TE_ItemProxySource) { - sources.add((TE_ItemProxySource) te); - } - } - } - } - } - - @Override - public int getSizeInventory() { - return 1; - } - - @Override - public ItemStack getStackInSlot(int slot) { - if(proxyInventory != null && slot == 0) { - return proxyInventory.getStackInSlot(channel); - } else { - return null; - } - } - - @Override - public ItemStack decrStackSize(int slot, int amount) { - if(proxyInventory != null && slot == 0) { - return proxyInventory.decrStackSize(channel, amount); - } else { - return null; - } - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - return (proxyInventory != null) ? proxyInventory.getStackInSlotOnClosing(channel) : null; - } - - @Override - public void setInventorySlotContents(int slot, ItemStack itemStack) { - if(proxyInventory != null && slot == 0) { - proxyInventory.setInventorySlotContents(channel, itemStack); - } - } - - @Override - public String getInventoryName() { - return (proxyInventory != null) ? "Connected: " + proxyInventory.getInventoryName() : "Untethered Proxy"; - } - - @Override - public boolean hasCustomInventoryName() { - return true; - } - - @Override - public int getInventoryStackLimit() { - return (proxyInventory != null) ? proxyInventory.getInventoryStackLimit() : 0; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return true; - } - - @Override - public void openInventory() { - - } - - @Override - public void closeInventory() { - - } - - @Override - public boolean isItemValidForSlot(int slot, ItemStack itemStack) { - if(proxyInventory != null && slot == 0) { - return proxyInventory.isItemValidForSlot(channel, itemStack); - } else { - return false; - } - } - - @Override - public int[] getAccessibleSlotsFromSide(int side) { - return new int[]{0}; - } - - @Override - public boolean canInsertItem(int slot, ItemStack itemStack, int side) { - return isItemValidForSlot(slot, itemStack); - } - - @Override - public boolean canExtractItem(int slot, ItemStack itemStack, int side) { - return slot == 0; - } - + private byte channel = -1; + private IInventory proxyInventory = null; + private int tickCounter = 0; + + public TE_ItemProxyEndpoint() { + channel = 0; + } + + public void setChannel(byte channel) { + this.channel = channel; + } + + public int getChannel() { + return channel; + } + + @Override + public void updateEntity() { + if (tickCounter == 20) { + if (channel != -1) { + proxyInventory = searchSource(); + } + tickCounter = 0; + } + tickCounter++; + } + + private TE_ItemProxySource searchSource() { + + final HashSet<TE_ItemProxySource> sources = new HashSet<>(); + final HashSet<String> visited = new HashSet<>(); + + for (ForgeDirection next : ForgeDirection.VALID_DIRECTIONS) { + final TileEntity te = super.getWorldObj() + .getTileEntity( + super.xCoord + next.offsetX, super.yCoord + next.offsetY, super.zCoord + next.offsetZ); + if (te instanceof TE_ItemProxyCable) { + final TE_ItemProxyCable cable = (TE_ItemProxyCable) te; + if (cable.isConnected(next.getOpposite())) { + searchSourceRecursive(sources, visited, next.getOpposite(), cable); + } + } + } + + if (sources.isEmpty()) { + return null; + } else { + return sources.iterator().next(); + } + } + + private void searchSourceRecursive( + HashSet<TE_ItemProxySource> sources, + HashSet<String> visited, + ForgeDirection from, + TE_ItemProxyCable nextTarget) { + + if (!visited.contains(nextTarget.getIdentifier())) { + visited.add(nextTarget.getIdentifier()); + + for (ForgeDirection next : ForgeDirection.VALID_DIRECTIONS) { + if (next != from) { + final TileEntity te = super.getWorldObj() + .getTileEntity( + nextTarget.xCoord + next.offsetX, + nextTarget.yCoord + next.offsetY, + nextTarget.zCoord + next.offsetZ); + if (te instanceof TE_ItemProxyCable) { + final TE_ItemProxyCable cable = (TE_ItemProxyCable) te; + if (cable.isConnected(next.getOpposite())) { + searchSourceRecursive(sources, visited, next.getOpposite(), cable); + } + } else if (te instanceof TE_ItemProxySource) { + sources.add((TE_ItemProxySource) te); + } + } + } + } + } + + @Override + public int getSizeInventory() { + return 1; + } + + @Override + public ItemStack getStackInSlot(int slot) { + if (proxyInventory != null && slot == 0) { + return proxyInventory.getStackInSlot(channel); + } else { + return null; + } + } + + @Override + public ItemStack decrStackSize(int slot, int amount) { + if (proxyInventory != null && slot == 0) { + return proxyInventory.decrStackSize(channel, amount); + } else { + return null; + } + } + + @Override + public ItemStack getStackInSlotOnClosing(int slot) { + return (proxyInventory != null) ? proxyInventory.getStackInSlotOnClosing(channel) : null; + } + + @Override + public void setInventorySlotContents(int slot, ItemStack itemStack) { + if (proxyInventory != null && slot == 0) { + proxyInventory.setInventorySlotContents(channel, itemStack); + } + } + + @Override + public String getInventoryName() { + return (proxyInventory != null) ? "Connected: " + proxyInventory.getInventoryName() : "Untethered Proxy"; + } + + @Override + public boolean hasCustomInventoryName() { + return true; + } + + @Override + public int getInventoryStackLimit() { + return (proxyInventory != null) ? proxyInventory.getInventoryStackLimit() : 0; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer player) { + return true; + } + + @Override + public void openInventory() {} + + @Override + public void closeInventory() {} + + @Override + public boolean isItemValidForSlot(int slot, ItemStack itemStack) { + if (proxyInventory != null && slot == 0) { + return proxyInventory.isItemValidForSlot(channel, itemStack); + } else { + return false; + } + } + + @Override + public int[] getAccessibleSlotsFromSide(int side) { + return new int[] {0}; + } + + @Override + public boolean canInsertItem(int slot, ItemStack itemStack, int side) { + return isItemValidForSlot(slot, itemStack); + } + + @Override + public boolean canExtractItem(int slot, ItemStack itemStack, int side) { + return slot == 0; + } } diff --git a/src/main/java/common/tileentities/TE_ItemProxySource.java b/src/main/java/common/tileentities/TE_ItemProxySource.java index a960a7b914..15a93ed91a 100644 --- a/src/main/java/common/tileentities/TE_ItemProxySource.java +++ b/src/main/java/common/tileentities/TE_ItemProxySource.java @@ -1,7 +1,5 @@ package common.tileentities; -import java.util.UUID; - import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; @@ -9,104 +7,100 @@ import net.minecraft.tileentity.TileEntity; public class TE_ItemProxySource extends TileEntity implements IInventory { - private ItemStack[] slots = new ItemStack[16]; - private String idCache = null; - - /** - * Builds a simple unique identifier for this TileEntity by appending - * the x, y, and z coordinates in a string. - * - * @return unique identifier for this TileEntity - */ - public String getIdentifier() { - if(idCache == null) { - idCache = "" + super.xCoord + super.yCoord + super.zCoord; - return idCache; - } else { - return idCache; - } - } - - @Override - public int getSizeInventory() { - return slots.length; - } - - @Override - public ItemStack getStackInSlot(int slot) { - return slots[slot]; - } - - @Override - public ItemStack decrStackSize(int slot, int amount) { - if(slots[slot] != null) { - - ItemStack copy; - - if(slots[slot].stackSize == amount) { - copy = slots[slot]; - slots[slot] = null; - super.markDirty(); - return copy; - } else { - copy = slots[slot].splitStack(amount); - if(slots[slot].stackSize == 0) { - slots[slot] = null; - } - return copy; - } - - } else { - return null; - } - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - return null; - } - - @Override - public void setInventorySlotContents(int slot, ItemStack itemStack) { - slots[slot] = itemStack; - if(itemStack != null && itemStack.stackSize > getInventoryStackLimit()) { - itemStack.stackSize = getInventoryStackLimit(); - } - super.markDirty(); - } - - @Override - public String getInventoryName() { - return "Item Proxy Source"; - } - - @Override - public boolean hasCustomInventoryName() { - return true; - } - - @Override - public int getInventoryStackLimit() { - return 64; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer p_70300_1_) { - return true; - } - - @Override - public void openInventory() { - - } - - @Override - public void closeInventory() { - - } - - @Override - public boolean isItemValidForSlot(int slot, ItemStack itemStack) { - return true; - } + private ItemStack[] slots = new ItemStack[16]; + private String idCache = null; + + /** + * Builds a simple unique identifier for this TileEntity by appending + * the x, y, and z coordinates in a string. + * + * @return unique identifier for this TileEntity + */ + public String getIdentifier() { + if (idCache == null) { + idCache = "" + super.xCoord + super.yCoord + super.zCoord; + return idCache; + } else { + return idCache; + } + } + + @Override + public int getSizeInventory() { + return slots.length; + } + + @Override + public ItemStack getStackInSlot(int slot) { + return slots[slot]; + } + + @Override + public ItemStack decrStackSize(int slot, int amount) { + if (slots[slot] != null) { + + ItemStack copy; + + if (slots[slot].stackSize == amount) { + copy = slots[slot]; + slots[slot] = null; + super.markDirty(); + return copy; + } else { + copy = slots[slot].splitStack(amount); + if (slots[slot].stackSize == 0) { + slots[slot] = null; + } + return copy; + } + + } else { + return null; + } + } + + @Override + public ItemStack getStackInSlotOnClosing(int slot) { + return null; + } + + @Override + public void setInventorySlotContents(int slot, ItemStack itemStack) { + slots[slot] = itemStack; + if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) { + itemStack.stackSize = getInventoryStackLimit(); + } + super.markDirty(); + } + + @Override + public String getInventoryName() { + return "Item Proxy Source"; + } + + @Override + public boolean hasCustomInventoryName() { + return true; + } + + @Override + public int getInventoryStackLimit() { + return 64; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer p_70300_1_) { + return true; + } + + @Override + public void openInventory() {} + + @Override + public void closeInventory() {} + + @Override + public boolean isItemValidForSlot(int slot, ItemStack itemStack) { + return true; + } } diff --git a/src/main/java/common/tileentities/TE_TFFTMultiHatch.java b/src/main/java/common/tileentities/TE_TFFTMultiHatch.java index de274bb15e..2e55e600d3 100644 --- a/src/main/java/common/tileentities/TE_TFFTMultiHatch.java +++ b/src/main/java/common/tileentities/TE_TFFTMultiHatch.java @@ -11,58 +11,58 @@ import net.minecraftforge.fluids.IFluidHandler; @Deprecated public class TE_TFFTMultiHatch extends TileEntity implements IFluidHandler { - - public static final int BASE_OUTPUT_PER_SECOND = 2000; // L/s - - private byte facings = 0x0; - - private MultiFluidHandler mfh; - private int tickCounter = 0; - private boolean autoOutput = false; - - public boolean hasFacingOnSide(byte side) { - final byte key = (byte) Math.pow(0x2, side); - return (facings & key) == key; - } - - public void setFacingToSide(byte side) { - facings = (byte) Math.pow(0x2, side); - } - - public void setMultiFluidHandler(MultiFluidHandler mfh) { - this.mfh = mfh; - } - - public void toggleAutoOutput() { - autoOutput = !autoOutput; - } - - public boolean isOutputting() { - return autoOutput; - } - - @Override - public void updateEntity() { - // Removed deprecated code - } - - @Override - public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { - // Removed deprecated code - return 0; - } - - @Override - public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { - // Removed deprecated code - return null; - } - - /** - * Drains fluid out of 0th internal tank. + + public static final int BASE_OUTPUT_PER_SECOND = 2000; // L/s + + private byte facings = 0x0; + + private MultiFluidHandler mfh; + private int tickCounter = 0; + private boolean autoOutput = false; + + public boolean hasFacingOnSide(byte side) { + final byte key = (byte) Math.pow(0x2, side); + return (facings & key) == key; + } + + public void setFacingToSide(byte side) { + facings = (byte) Math.pow(0x2, side); + } + + public void setMultiFluidHandler(MultiFluidHandler mfh) { + this.mfh = mfh; + } + + public void toggleAutoOutput() { + autoOutput = !autoOutput; + } + + public boolean isOutputting() { + return autoOutput; + } + + @Override + public void updateEntity() { + // Removed deprecated code + } + + @Override + public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { + // Removed deprecated code + return 0; + } + + @Override + public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { + // Removed deprecated code + return null; + } + + /** + * Drains fluid out of 0th internal tank. * If the TFFT Controller contains an Integrated Circuit, drain fluid * from the slot equal to the circuit configuration. - * + * * @param from * Orientation the fluid is drained to. * @param maxDrain @@ -72,67 +72,41 @@ public class TE_TFFTMultiHatch extends TileEntity implements IFluidHandler { * @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) { - // Removed deprecated code - return null; - } - - @Override - public boolean canFill(ForgeDirection from, Fluid fluid) { - // Removed deprecated code - return false; - } - - @Override - public boolean canDrain(ForgeDirection from, Fluid fluid) { - // Removed deprecated code - return false; - } - - @Override - public FluidTankInfo[] getTankInfo(ForgeDirection from) { - // Removed deprecated code - return null; - } - - @Override - public void writeToNBT(NBTTagCompound nbt) { - super.writeToNBT(nbt); - nbt.setBoolean("autoOutput", autoOutput); - nbt.setByte("facings", facings); - } - - @Override - public void readFromNBT(NBTTagCompound nbt) { - super.readFromNBT(nbt); - autoOutput = nbt.getBoolean("autoOutput"); - facings = nbt.getByte("facings"); - } - - - - - - - - - - - - - - - - - - - - - - - - - - + @Override + public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { + // Removed deprecated code + return null; + } + + @Override + public boolean canFill(ForgeDirection from, Fluid fluid) { + // Removed deprecated code + return false; + } + + @Override + public boolean canDrain(ForgeDirection from, Fluid fluid) { + // Removed deprecated code + return false; + } + + @Override + public FluidTankInfo[] getTankInfo(ForgeDirection from) { + // Removed deprecated code + return null; + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + nbt.setBoolean("autoOutput", autoOutput); + nbt.setByte("facings", facings); + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + autoOutput = nbt.getBoolean("autoOutput"); + facings = nbt.getByte("facings"); + } } diff --git a/src/main/java/common/tileentities/TE_ThaumiumReinforcedJar.java b/src/main/java/common/tileentities/TE_ThaumiumReinforcedJar.java index 23b19495ae..e54324220f 100644 --- a/src/main/java/common/tileentities/TE_ThaumiumReinforcedJar.java +++ b/src/main/java/common/tileentities/TE_ThaumiumReinforcedJar.java @@ -3,8 +3,8 @@ package common.tileentities; import thaumcraft.common.tiles.TileJarFillable; public class TE_ThaumiumReinforcedJar extends TileJarFillable { - - public TE_ThaumiumReinforcedJar() { - super.maxAmount = 256; - } + + public TE_ThaumiumReinforcedJar() { + super.maxAmount = 256; + } } diff --git a/src/main/java/common/tileentities/TE_ThaumiumReinforcedVoidJar.java b/src/main/java/common/tileentities/TE_ThaumiumReinforcedVoidJar.java index c648d4be00..dd0166fe6e 100644 --- a/src/main/java/common/tileentities/TE_ThaumiumReinforcedVoidJar.java +++ b/src/main/java/common/tileentities/TE_ThaumiumReinforcedVoidJar.java @@ -3,8 +3,8 @@ package common.tileentities; import thaumcraft.common.tiles.TileJarFillableVoid; public class TE_ThaumiumReinforcedVoidJar extends TileJarFillableVoid { - - public TE_ThaumiumReinforcedVoidJar() { - super.maxAmount = 256; - } + + public TE_ThaumiumReinforcedVoidJar() { + super.maxAmount = 256; + } } |