From ada57aa08f5f233c0923a7290747c7f63d331587 Mon Sep 17 00:00:00 2001 From: Jakub <53441451+kuba6000@users.noreply.github.com> Date: Fri, 18 Mar 2022 06:58:27 +0100 Subject: Allow all mega's to use more than MAX voltage (#107) * Allow all mega's to use more than MAX voltage * Update slots earlier * Allow laser hatches only if there is no other type Former-commit-id: aa23a6d5d6f4ae2de6decfc31fd9b6d44f97d908 --- .../mega/GT_TileEntity_MegaBlastFurnace.java | 302 ++++++++------------- .../mega/GT_TileEntity_MegaChemicalReactor.java | 121 +++------ .../mega/GT_TileEntity_MegaDistillTower.java | 135 ++++----- .../mega/GT_TileEntity_MegaMultiBlockBase.java | 296 ++++++++++++++++++++ .../multis/mega/GT_TileEntity_MegaOilCracker.java | 198 ++++++-------- .../mega/GT_TileEntity_MegaVacuumFreezer.java | 157 +++-------- .../bartimaeusnek/bartworks/util/BW_Util.java | 29 +- .../crossmod/tectech/helper/TecTechUtils.java | 59 +++- 8 files changed, 704 insertions(+), 593 deletions(-) create mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaMultiBlockBase.java (limited to 'src/main/java/com') diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaBlastFurnace.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaBlastFurnace.java index 21be004770..292bf8e699 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaBlastFurnace.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaBlastFurnace.java @@ -27,33 +27,28 @@ import com.github.bartimaeusnek.bartworks.API.LoaderReference; import com.github.bartimaeusnek.bartworks.common.configs.ConfigHandler; import com.github.bartimaeusnek.bartworks.util.BW_Tooltip_Reference; import com.github.bartimaeusnek.bartworks.util.BW_Util; -import com.github.bartimaeusnek.bartworks.util.MegaUtils; import com.github.bartimaeusnek.bartworks.util.Pair; -import com.github.bartimaeusnek.crossmod.tectech.TecTechEnabledMulti; import com.github.bartimaeusnek.crossmod.tectech.helper.TecTechUtils; -import com.github.bartimaeusnek.crossmod.tectech.tileentites.tiered.LowPowerLaser; import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.StructureDefinition; import cpw.mods.fml.common.Optional; import gregtech.api.GregTech_API; -import gregtech.api.enums.GT_Values; import gregtech.api.enums.HeatingCoilLevel; +import gregtech.api.enums.Materials; +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_Hatch_Energy; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffler; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; +import gregtech.api.metatileentity.implementations.*; +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.common.tileentities.machines.multi.GT_MetaTileEntity_ElectricBlastFurnace; 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.EnumChatFormatting; -import net.minecraft.util.StatCollector; import net.minecraftforge.fluids.FluidStack; import java.util.*; @@ -61,21 +56,21 @@ import java.util.stream.Collectors; import static com.github.bartimaeusnek.bartworks.util.RecipeFinderForParallel.getMultiOutput; import static com.github.bartimaeusnek.bartworks.util.RecipeFinderForParallel.handleParallelRecipe; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlockAdder; import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; import static gregtech.api.enums.GT_Values.V; +import static gregtech.api.enums.Textures.BlockIcons.*; import static gregtech.api.util.GT_StructureUtility.*; import static gregtech.api.util.GT_StructureUtility.ofHatchAdderOptional; @Optional.Interface(iface = "com.github.bartimaeusnek.crossmod.tectech.TecTechEnabledMulti", modid = "tectech", striprefs = true) -public class GT_TileEntity_MegaBlastFurnace extends GT_MetaTileEntity_ElectricBlastFurnace implements TecTechEnabledMulti { +public class GT_TileEntity_MegaBlastFurnace extends GT_TileEntity_MegaMultiBlockBase { private static final int CASING_INDEX = 11; private static final IStructureDefinition STRUCTURE_DEFINITION = StructureDefinition.builder() .addShape("main", createShape()) .addElement('t', ofHatchAdderOptional(GT_TileEntity_MegaBlastFurnace::addOutputHatchToTopList, CASING_INDEX, 1, GregTech_API.sBlockCasings1, CASING_INDEX)) .addElement('m', ofHatchAdder(GT_TileEntity_MegaBlastFurnace::addMufflerToMachineList, CASING_INDEX, 2)) - .addElement('C', ofCoil(GT_TileEntity_MegaBlastFurnace::setCoilLevel, GT_MetaTileEntity_ElectricBlastFurnace::getCoilLevel)) + .addElement('C', ofCoil(GT_TileEntity_MegaBlastFurnace::setCoilLevel, GT_TileEntity_MegaBlastFurnace::getCoilLevel)) .addElement('g', BorosilicateGlass.ofBoroGlass((byte) 0, (byte) 1, Byte.MAX_VALUE, (te, t) -> te.glasTier = t, te -> te.glasTier)) .addElement('b', ofHatchAdderOptional(GT_TileEntity_MegaBlastFurnace::addBottomHatch, CASING_INDEX, 3, GregTech_API.sBlockCasings1, CASING_INDEX)) .build(); @@ -118,9 +113,14 @@ public class GT_TileEntity_MegaBlastFurnace extends GT_MetaTileEntity_ElectricBl return transpose(raw); } + private HeatingCoilLevel mCoilLevel; + protected final ArrayList mPollutionOutputHatches = new ArrayList<>(); + protected final FluidStack[] pollutionFluidStacks = {Materials.CarbonDioxide.getGas(1000), + Materials.CarbonMonoxide.getGas(1000), Materials.SulfurDioxide.getGas(1000)}; private int mHeatingCapacity; private byte glasTier; private int polPtick = ConfigHandler.basePollutionMBFSecond / 20 * ConfigHandler.megaMachinesMax; + private int mufflerTier = -1; public GT_TileEntity_MegaBlastFurnace(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); @@ -130,6 +130,11 @@ public class GT_TileEntity_MegaBlastFurnace extends GT_MetaTileEntity_ElectricBl super(aName); } + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity iGregTechTileEntity) { + return new GT_TileEntity_MegaBlastFurnace(this.mName); + } + @Override protected GT_Multiblock_Tooltip_Builder createTooltip() { GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); @@ -162,45 +167,14 @@ public class GT_TileEntity_MegaBlastFurnace extends GT_MetaTileEntity_ElectricBl return tt; } - public ArrayList TTTunnels = new ArrayList<>(); - public ArrayList TTMultiAmp = new ArrayList<>(); - @Override public void loadNBTData(NBTTagCompound aNBT) { super.loadNBTData(aNBT); this.circuitMode = aNBT.getByte("circuitMode"); this.glasTier = aNBT.getByte("glasTier"); - this.lEUt = aNBT.getLong("lEUt"); - } - - @Override - public boolean onRunningTick(ItemStack aStack) { - if (this.lEUt > 0) { - this.addEnergyOutput(this.lEUt * (long)this.mEfficiency / 10000L); - return true; - } else if (this.lEUt < 0 && !this.drainEnergyInput((-this.lEUt) * 10000L / (long)Math.max(1000, this.mEfficiency))) { - this.stopMachine(); - return false; - } else { - return true; - } - } - - - @Override - public void stopMachine() { - this.mOutputItems = null; - this.mEUt = 0; - this.lEUt = 0; - this.mEfficiency = 0; - this.mProgresstime = 0; - this.mMaxProgresstime = 0; - this.mEfficiencyIncrease = 0; - this.getBaseMetaTileEntity().disableWorking(); } private byte circuitMode = 0; - private long lEUt = 0; @Override public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { @@ -217,143 +191,66 @@ public class GT_TileEntity_MegaBlastFurnace extends GT_MetaTileEntity_ElectricBl GT_Utility.sendChatToPlayer(aPlayer, circuitMode > 0 ? "MEBF will prioritise circuit: " + circuitMode : "Circuit prioritisation disabled."); } + @Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + if (aSide == aFacing) { + if (aActive) + return new ITexture[]{ + casingTexturePages[0][CASING_INDEX], + TextureFactory.builder().addIcon(OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_ACTIVE).extFacing().build(), + TextureFactory.builder().addIcon(OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_ACTIVE_GLOW).extFacing().glow().build()}; + return new ITexture[]{ + casingTexturePages[0][CASING_INDEX], + TextureFactory.builder().addIcon(OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE).extFacing().build(), + TextureFactory.builder().addIcon(OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_GLOW).extFacing().glow().build()}; + } + return new ITexture[]{casingTexturePages[0][CASING_INDEX]}; + } + @Override public void saveNBTData(NBTTagCompound aNBT) { super.saveNBTData(aNBT); aNBT.setByte("glasTier", glasTier); aNBT.setByte("circuitMode", circuitMode); - aNBT.setLong("lEUt", lEUt); - } - - @Override - public boolean addEnergyInputToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (LoaderReference.tectech) - return TecTechUtils.addEnergyInputToMachineList(this, aTileEntity, aBaseCasingIndex); - return super.addEnergyInputToMachineList(aTileEntity, aBaseCasingIndex); - } - - /** - * Taken from the GTNH fork, made originally by Tec - * Calcualtes overclocked ness using long integers - * - * @param aEUt - recipe EUt - * @param aDuration - recipe Duration - */ - protected byte calculateOverclockednessEBF(long aEUt, int aDuration, long maxInputVoltage) { - byte mTier = (byte) Math.max(0, GT_Utility.getTier(maxInputVoltage)), timesOverclocked = 0; - if (mTier == 0) { - //Long time calculation - long xMaxProgresstime = ((long) aDuration) << 1; - if (xMaxProgresstime > Integer.MAX_VALUE - 1) { - //make impossible if too long - this.lEUt = Integer.MAX_VALUE - 1; - this.mMaxProgresstime = Integer.MAX_VALUE - 1; - } else { - this.lEUt = (int) (aEUt >> 2); - this.mMaxProgresstime = (int) xMaxProgresstime; - } - //return 0; - } else { - //Long EUt calculation - long xEUt = aEUt; - //Isnt too low EUt check? - long tempEUt = Math.max(xEUt, V[1]); - - this.mMaxProgresstime = aDuration; - while (tempEUt <= V[mTier - 1]) { - tempEUt <<= 2;//this actually controls overclocking - //xEUt *= 4;//this is effect of everclocking - this.mMaxProgresstime >>= 1;//this is effect of overclocking - xEUt = this.mMaxProgresstime <= 0 ? xEUt >> 1 : xEUt << 2;//U know, if the time is less than 1 tick make the machine use less power - timesOverclocked++; - } - if (xEUt > maxInputVoltage) { - //downclock one notch, we have overshot. - xEUt >>=2; - this.mMaxProgresstime <<= 1; - timesOverclocked--; - } - if (xEUt > Integer.MAX_VALUE - 1) { - this.lEUt = Integer.MAX_VALUE - 1; - this.mMaxProgresstime = Integer.MAX_VALUE - 1; - } else { - this.lEUt = (int) xEUt; - if (this.lEUt == 0) - this.lEUt = 1; - if (this.mMaxProgresstime <= 0) - this.mMaxProgresstime = 1;//set time to 1 tick - } - } - return timesOverclocked; } @Override - public String[] getInfoData() { - int mPollutionReduction = 0; - - for (GT_MetaTileEntity_Hatch_Muffler e : this.mMufflerHatches) - if (GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(e)) - mPollutionReduction = Math.max(e.calculatePollutionReduction(this.mPollution), mPollutionReduction); - - long storedEnergy = 0L; - long maxEnergy = 0L; - - if (LoaderReference.tectech) { - long[] info = getCurrentInfoData(); - storedEnergy = info[0]; - maxEnergy = info[1]; + public boolean addMufflerToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if(super.addMufflerToMachineList(aTileEntity, aBaseCasingIndex)) + { + if(mufflerTier == -1) + mufflerTier = this.mMufflerHatches.get(this.mMufflerHatches.size() - 1).mTier; + return mufflerTier == this.mMufflerHatches.get(this.mMufflerHatches.size() - 1).mTier; } - - for (GT_MetaTileEntity_Hatch_Energy tHatch : this.mEnergyHatches) { - if (GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(tHatch)) { - storedEnergy += tHatch.getBaseMetaTileEntity().getStoredEU(); - maxEnergy += tHatch.getBaseMetaTileEntity().getEUCapacity(); - } - } - - return new String[]{ - StatCollector.translateToLocal("GT5U.multiblock.Progress") + ": " + - EnumChatFormatting.GREEN + GT_Utility.formatNumbers(this.mProgresstime / 20) + EnumChatFormatting.RESET + " s / " + - EnumChatFormatting.YELLOW + GT_Utility.formatNumbers(this.mMaxProgresstime / 20) + EnumChatFormatting.RESET + " s", - StatCollector.translateToLocal("GT5U.multiblock.energy") + ": " + - EnumChatFormatting.GREEN + GT_Utility.formatNumbers(storedEnergy) + EnumChatFormatting.RESET + " EU / " + - EnumChatFormatting.YELLOW + GT_Utility.formatNumbers(maxEnergy) + EnumChatFormatting.RESET + " EU", - StatCollector.translateToLocal("GT5U.multiblock.usage") + ": " + - EnumChatFormatting.RED + GT_Utility.formatNumbers(-this.lEUt) + EnumChatFormatting.RESET + " EU/t", - StatCollector.translateToLocal("GT5U.multiblock.mei") + ": " + - EnumChatFormatting.YELLOW + GT_Utility.formatNumbers(this.getMaxInputVoltage()) + EnumChatFormatting.RESET + " EU/t(*2A) " + - StatCollector.translateToLocal("GT5U.machines.tier") + ": " + - EnumChatFormatting.YELLOW + GT_Values.VN[GT_Utility.getTier(this.getMaxInputVoltage())] + EnumChatFormatting.RESET, - StatCollector.translateToLocal("GT5U.multiblock.problems") + ": " + - EnumChatFormatting.RED + (this.getIdealStatus() - this.getRepairStatus()) + EnumChatFormatting.RESET + " " + - StatCollector.translateToLocal("GT5U.multiblock.efficiency") + ": " + - EnumChatFormatting.YELLOW + (float) this.mEfficiency / 100.0F + EnumChatFormatting.RESET + " %", - StatCollector.translateToLocal("GT5U.multiblock.pollution") + ": " + - EnumChatFormatting.GREEN + mPollutionReduction + EnumChatFormatting.RESET + " %"}; + return false; } @Override - public boolean drainEnergyInput(long aEU) { - if (LoaderReference.tectech) - return TecTechUtils.drainEnergyMEBFTecTech(this, aEU); - return MegaUtils.drainEnergyMegaVanilla(this, aEU); + public int getPollutionPerTick(ItemStack aStack) { + return this.polPtick; } - @Override - public long getMaxInputVoltage() { - if (LoaderReference.tectech) - return TecTechUtils.getMaxInputVoltage(this); - return super.getMaxInputVoltage(); + public boolean addOutputHatchToTopList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) return false; + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) return false; + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); + return mPollutionOutputHatches.add((GT_MetaTileEntity_Hatch_Output) aMetaTileEntity); + } + return false; } - @Override - public int getPollutionPerTick(ItemStack aStack) { - return this.polPtick; + protected boolean addBottomHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + return addMaintenanceToMachineList(aTileEntity, aBaseCasingIndex) || + addInputToMachineList(aTileEntity, aBaseCasingIndex) || + addOutputToMachineList(aTileEntity, aBaseCasingIndex) || + addEnergyInputToMachineList(aTileEntity, aBaseCasingIndex); } @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity iGregTechTileEntity) { - return new GT_TileEntity_MegaBlastFurnace(this.mName); + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "ElectricBlastFurnace.png"); } @Override @@ -394,6 +291,7 @@ public class GT_TileEntity_MegaBlastFurnace extends GT_MetaTileEntity_ElectricBl if (this.mHeatingCapacity >= tRecipe.mSpecialValue) { int tCurrentPara = handleParallelRecipe(tRecipe, tFluids, tInputs, (int) tMaxPara); + this.updateSlots(); if (tCurrentPara <= 0) return false; processed = tCurrentPara; found_Recipe = true; @@ -407,7 +305,7 @@ public class GT_TileEntity_MegaBlastFurnace extends GT_MetaTileEntity_ElectricBl this.mEfficiencyIncrease = 10000; long actualEUT = precutRecipeVoltage * processed; - byte overclockCount = this.calculateOverclockednessEBF(actualEUT, tRecipe.mDuration, nominalV); + byte overclockCount = this.calculateOverclockedNessMultiInternal(actualEUT, tRecipe.mDuration, nominalV, false); //In case recipe is too OP for that machine if (this.mMaxProgresstime == Integer.MAX_VALUE - 1 && this.lEUt == Integer.MAX_VALUE - 1) @@ -429,7 +327,6 @@ public class GT_TileEntity_MegaBlastFurnace extends GT_MetaTileEntity_ElectricBl this.mOutputItems = outputItems.toArray(this.mOutputItems); this.mOutputFluids = new FluidStack[outputFluids.size()]; this.mOutputFluids = outputFluids.toArray(this.mOutputFluids); - this.updateSlots(); return true; } return false; @@ -441,10 +338,8 @@ public class GT_TileEntity_MegaBlastFurnace extends GT_MetaTileEntity_ElectricBl } @Override - @SuppressWarnings({"rawtypes", "unchecked"}) - public IStructureDefinition getStructureDefinition() { - // hack to get around generic - return (IStructureDefinition) STRUCTURE_DEFINITION; + public IStructureDefinition getStructureDefinition() { + return STRUCTURE_DEFINITION; } @Override @@ -452,6 +347,46 @@ public class GT_TileEntity_MegaBlastFurnace extends GT_MetaTileEntity_ElectricBl buildPiece("main", stackSize, hintsOnly, 7, 17, 0); } + public void setCoilLevel(HeatingCoilLevel aCoilLevel) { + mCoilLevel = aCoilLevel; + } + + public HeatingCoilLevel getCoilLevel() { + return mCoilLevel; + } + + @Override + public boolean addOutput(FluidStack aLiquid) { + if (aLiquid == null) + return false; + FluidStack tLiquid = aLiquid.copy(); + boolean isOutputPollution = false; + for (FluidStack pollutionFluidStack : pollutionFluidStacks) { + if (!tLiquid.isFluidEqual(pollutionFluidStack)) + continue; + + isOutputPollution = true; + break; + } + ArrayList tOutputHatches; + if (isOutputPollution) { + tOutputHatches = this.mPollutionOutputHatches; + int pollutionReduction = 0; + for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) { + if (!isValidMetaTileEntity(tHatch)) + continue; + pollutionReduction = 100 - tHatch.calculatePollutionReduction(100); + break; + } + tLiquid.amount = tLiquid.amount * (pollutionReduction + 5) / 100; + } else { + tOutputHatches = this.mOutputHatches; + } + return dumpFluid(tOutputHatches, tLiquid, true) || + dumpFluid(tOutputHatches, tLiquid, false); + } + + @Override public boolean checkMachine(IGregTechTileEntity iGregTechTileEntity, ItemStack itemStack) { if (LoaderReference.tectech) { @@ -461,6 +396,7 @@ public class GT_TileEntity_MegaBlastFurnace extends GT_MetaTileEntity_ElectricBl this.mHeatingCapacity = 0; glasTier = 0; + mufflerTier = -1; setCoilLevel(HeatingCoilLevel.None); @@ -499,34 +435,10 @@ public class GT_TileEntity_MegaBlastFurnace extends GT_MetaTileEntity_ElectricBl return false; } - @SuppressWarnings("rawtypes") - @Optional.Method(modid = "tectech") - private boolean areLazorsLowPowa() { - Collection collection = this.getTecTechEnergyTunnels(); - if (!collection.isEmpty()) - for (Object tecTechEnergyMulti : collection) - if (!(tecTechEnergyMulti instanceof LowPowerLaser)) - return false; - return true; - } - @Override - @Optional.Method(modid = "tectech") - public List getVanillaEnergyHatches() { - return this.mEnergyHatches; + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sBlastRecipes; } - @Override - @SuppressWarnings({"rawtypes", "unchecked"}) - @Optional.Method(modid = "tectech") - public List getTecTechEnergyTunnels() { - return TTTunnels; - } - @Override - @SuppressWarnings({"rawtypes", "unchecked"}) - @Optional.Method(modid = "tectech") - public List getTecTechEnergyMultis() { - return TTMultiAmp; - } } diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaChemicalReactor.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaChemicalReactor.java index 948bb04148..0b5f02632a 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaChemicalReactor.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaChemicalReactor.java @@ -25,31 +25,29 @@ package com.github.bartimaeusnek.bartworks.common.tileentities.multis.mega; import com.github.bartimaeusnek.bartworks.API.BorosilicateGlass; import com.github.bartimaeusnek.bartworks.API.LoaderReference; import com.github.bartimaeusnek.bartworks.common.configs.ConfigHandler; -import com.github.bartimaeusnek.bartworks.util.BW_Tooltip_Reference; import com.github.bartimaeusnek.bartworks.util.BW_Util; -import com.github.bartimaeusnek.bartworks.util.MegaUtils; import com.github.bartimaeusnek.bartworks.util.Pair; -import com.github.bartimaeusnek.crossmod.tectech.TecTechEnabledMulti; import com.github.bartimaeusnek.crossmod.tectech.helper.TecTechUtils; -import com.github.bartimaeusnek.crossmod.tectech.tileentites.tiered.LowPowerLaser; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.StructureDefinition; import cpw.mods.fml.common.Optional; import gregtech.api.GregTech_API; +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_Hatch_Energy; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; +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.common.tileentities.machines.multi.GT_MetaTileEntity_LargeChemicalReactor; +import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import java.util.ArrayList; import java.util.Collection; -import java.util.List; import static com.github.bartimaeusnek.bartworks.util.RecipeFinderForParallel.getMultiOutput; import static com.github.bartimaeusnek.bartworks.util.RecipeFinderForParallel.handleParallelRecipe; @@ -57,13 +55,12 @@ import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; import static gregtech.api.enums.GT_Values.V; +import static gregtech.api.enums.Textures.BlockIcons.*; import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; import static gregtech.api.util.GT_StructureUtility.ofHatchAdderOptional; @Optional.Interface(iface = "com.github.bartimaeusnek.crossmod.tectech.TecTechEnabledMulti", modid = "tectech", striprefs = true) -public class GT_TileEntity_MegaChemicalReactor extends GT_MetaTileEntity_LargeChemicalReactor implements TecTechEnabledMulti { - private final ArrayList TTTunnels = new ArrayList<>(); - private final ArrayList TTMultiAmp = new ArrayList<>(); +public class GT_TileEntity_MegaChemicalReactor extends GT_TileEntity_MegaMultiBlockBase { private byte glasTier; @@ -104,28 +101,30 @@ public class GT_TileEntity_MegaChemicalReactor extends GT_MetaTileEntity_LargeCh } @Override - public boolean addEnergyInputToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (LoaderReference.tectech) { - return TecTechUtils.addEnergyInputToMachineList(this, aTileEntity, aBaseCasingIndex); + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, + boolean aRedstone) { + if (aSide == aFacing) { + if (aActive) return new ITexture[]{ + casingTexturePages[1][48], + TextureFactory.builder().addIcon(OVERLAY_FRONT_LARGE_CHEMICAL_REACTOR_ACTIVE).extFacing().build(), + TextureFactory.builder().addIcon(OVERLAY_FRONT_LARGE_CHEMICAL_REACTOR_ACTIVE_GLOW).extFacing().glow().build()}; + return new ITexture[]{ + casingTexturePages[1][48], + TextureFactory.builder().addIcon(OVERLAY_FRONT_LARGE_CHEMICAL_REACTOR).extFacing().build(), + TextureFactory.builder().addIcon(OVERLAY_FRONT_LARGE_CHEMICAL_REACTOR_GLOW).extFacing().glow().build()}; } - return super.addEnergyInputToMachineList(aTileEntity, aBaseCasingIndex); + return new ITexture[]{casingTexturePages[1][48]}; } @Override - public boolean drainEnergyInput(long aEU) { - if (LoaderReference.tectech) { - return TecTechUtils.drainEnergyMEBFTecTech(this, aEU); - } - return MegaUtils.drainEnergyMegaVanilla(this, aEU); + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "LargeChemicalReactor.png"); } @Override - public long getMaxInputVoltage() { - if (LoaderReference.tectech) { - return TecTechUtils.getMaxInputVoltage(this); - } - return super.getMaxInputVoltage(); - } + public boolean supportsSingleRecipeLocking() { + return false; + } // TO IMPLEMENT @Override public boolean checkRecipe(ItemStack itemStack) { @@ -146,6 +145,7 @@ public class GT_TileEntity_MegaChemicalReactor extends GT_MetaTileEntity_LargeCh found_Recipe = true; long tMaxPara = Math.min(ConfigHandler.megaMachinesMax, nominalV / tRecipe.mEUt); int tCurrentPara = handleParallelRecipe(tRecipe, tInputFluids, tInputs, (int) tMaxPara); + this.updateSlots(); if (tCurrentPara <= 0) { return false; } @@ -158,30 +158,20 @@ public class GT_TileEntity_MegaChemicalReactor extends GT_MetaTileEntity_LargeCh if (found_Recipe) { this.mEfficiency = (10000 - (this.getIdealStatus() - this.getRepairStatus()) * 1000); this.mEfficiencyIncrease = 10000; - long actualEUT = (long) (tRecipe.mEUt) * processed; - if (actualEUT > Integer.MAX_VALUE) { - byte divider = 0; - while (actualEUT > Integer.MAX_VALUE) { - actualEUT = actualEUT / 2; - divider++; - } - BW_Util.calculatePerfectOverclockedNessMulti((int) actualEUT, tRecipe.mDuration * (divider * 2), 1, nominalV, this); - } else { - BW_Util.calculatePerfectOverclockedNessMulti((int) actualEUT, tRecipe.mDuration, 1, nominalV, this); - } + long actualEUT = ((long)tRecipe.mEUt) * processed; + calculatePerfectOverclockedNessMulti(actualEUT, tRecipe.mDuration, nominalV); //In case recipe is too OP for that machine - if (this.mMaxProgresstime == Integer.MAX_VALUE - 1 && this.mEUt == Integer.MAX_VALUE - 1) { + if (this.mMaxProgresstime == Integer.MAX_VALUE - 1 && this.lEUt == Integer.MAX_VALUE - 1) { return false; } - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); + if (this.lEUt > 0) { + this.lEUt = (-this.lEUt); } this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); this.mOutputItems = new ItemStack[outputItems.size()]; this.mOutputItems = outputItems.toArray(this.mOutputItems); this.mOutputFluids = new FluidStack[outputFluids.size()]; this.mOutputFluids = outputFluids.toArray(this.mOutputFluids); - this.updateSlots(); return true; } return false; @@ -222,26 +212,6 @@ public class GT_TileEntity_MegaChemicalReactor extends GT_MetaTileEntity_LargeCh } - @SuppressWarnings("rawtypes") - @Optional.Method(modid = "tectech") - private boolean areThingsNotProperlyTiered(Collection collection) { - if (!collection.isEmpty()) - for (Object tecTechEnergyMulti : collection) - if (((GT_MetaTileEntity_TieredMachineBlock) tecTechEnergyMulti).mTier > this.glasTier) - return true; - return false; - } - - @SuppressWarnings("rawtypes") - @Optional.Method(modid = "tectech") - private boolean areLazorsLowPowa() { - Collection collection = this.getTecTechEnergyTunnels(); - if (!collection.isEmpty()) - for (Object tecTechEnergyMulti : collection) - if (!(tecTechEnergyMulti instanceof LowPowerLaser)) - return false; - return true; - } private static final int CASING_INDEX = 176; private static final String STRUCTURE_PIECE_MAIN = "main"; @@ -267,34 +237,19 @@ public class GT_TileEntity_MegaChemicalReactor extends GT_MetaTileEntity_LargeCh .build(); - @SuppressWarnings({"unchecked", "rawtypes"}) @Override - public IStructureDefinition getStructureDefinition() { - return (IStructureDefinition) STRUCTURE_DEFINITION; - } - - @Override - public String[] getInfoData() { - return LoaderReference.tectech ? this.getInfoDataArray(this) : super.getInfoData(); - } - - @Override - @Optional.Method(modid = "tectech") - public List getVanillaEnergyHatches() { - return this.mEnergyHatches; + public IStructureDefinition getStructureDefinition() { + return STRUCTURE_DEFINITION; } - @Override - @SuppressWarnings({"rawtypes", "unchecked"}) + @SuppressWarnings("rawtypes") @Optional.Method(modid = "tectech") - public List getTecTechEnergyTunnels() { - return TTTunnels; + private boolean areThingsNotProperlyTiered(Collection collection) { + if (!collection.isEmpty()) + for (Object tecTechEnergyMulti : collection) + if (((GT_MetaTileEntity_TieredMachineBlock) tecTechEnergyMulti).mTier > this.glasTier) + return true; + return false; } - @Override - @SuppressWarnings({"rawtypes", "unchecked"}) - @Optional.Method(modid = "tectech") - public List getTecTechEnergyMultis() { - return TTMultiAmp; - } } diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaDistillTower.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaDistillTower.java index cb3f7a77ad..3d56b3fd3b 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaDistillTower.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaDistillTower.java @@ -25,7 +25,6 @@ package com.github.bartimaeusnek.bartworks.common.tileentities.multis.mega; import com.github.bartimaeusnek.bartworks.API.LoaderReference; import com.github.bartimaeusnek.bartworks.common.configs.ConfigHandler; import com.github.bartimaeusnek.bartworks.util.*; -import com.github.bartimaeusnek.crossmod.tectech.TecTechEnabledMulti; import com.github.bartimaeusnek.crossmod.tectech.helper.TecTechUtils; import com.gtnewhorizon.structurelib.StructureLibAPI; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; @@ -34,13 +33,17 @@ import com.gtnewhorizon.structurelib.structure.StructureDefinition; import cpw.mods.fml.common.Optional; import gregtech.api.GregTech_API; import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Textures; +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_Hatch_Energy; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; +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.common.tileentities.machines.multi.GT_MetaTileEntity_DistillationTower; +import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; @@ -53,10 +56,15 @@ import static com.github.bartimaeusnek.bartworks.util.RecipeFinderForParallel.ge import static com.github.bartimaeusnek.bartworks.util.RecipeFinderForParallel.handleParallelRecipe; import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; import static gregtech.api.enums.GT_Values.V; +import static gregtech.api.enums.Textures.BlockIcons.*; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER_GLOW; import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; @Optional.Interface(iface = "com.github.bartimaeusnek.crossmod.tectech.TecTechEnabledMulti", modid = "tectech", striprefs = true) -public class GT_TileEntity_MegaDistillTower extends GT_MetaTileEntity_DistillationTower implements TecTechEnabledMulti{ +public class GT_TileEntity_MegaDistillTower extends GT_TileEntity_MegaMultiBlockBase { + protected static final int CASING_INDEX = 49; + protected static final String STRUCTURE_PIECE_BASE = "base"; + protected static final String STRUCTURE_PIECE_LAYER = "layer"; private static final IStructureDefinition STRUCTURE_DEFINITION = StructureDefinition.builder() .addShape(STRUCTURE_PIECE_BASE, transpose(new String[][]{ {"bbbbbbb~bbbbbbb", "bbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbb"}, @@ -135,13 +143,13 @@ public class GT_TileEntity_MegaDistillTower extends GT_MetaTileEntity_Distillati } ) .build(); + protected final List> mOutputHatchesByLayer = new ArrayList<>(); + protected int mHeight; + protected int mCasing; + protected boolean mTopLayerFound; // -1 => maybe top, maybe not, 0 => definitely not top, 1 => definitely top private int mTopState = -1; - @SuppressWarnings("rawtypes") - public ArrayList TTTunnels = new ArrayList<>(); - @SuppressWarnings("rawtypes") - public ArrayList TTMultiAmp = new ArrayList<>(); public GT_TileEntity_MegaDistillTower(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); @@ -156,6 +164,52 @@ public class GT_TileEntity_MegaDistillTower extends GT_MetaTileEntity_Distillati return new GT_TileEntity_MegaDistillTower(this.mName); } + protected void onCasingFound() { + mCasing++; + } + + protected boolean addLayerOutputHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null || aTileEntity.isDead() || !(aTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_Hatch_Output)) + return false; + while (mOutputHatchesByLayer.size() < mHeight) + mOutputHatchesByLayer.add(new ArrayList<>()); + GT_MetaTileEntity_Hatch_Output tHatch = (GT_MetaTileEntity_Hatch_Output) aTileEntity.getMetaTileEntity(); + tHatch.updateTexture(aBaseCasingIndex); + return mOutputHatchesByLayer.get(mHeight - 1).add(tHatch); + } + + protected void onTopLayerFound(boolean aIsCasing) { + mTopLayerFound = true; + if (aIsCasing) + onCasingFound(); + } + + @Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + if (aSide == aFacing) { + if (aActive) + return new ITexture[]{ + Textures.BlockIcons.getCasingTextureForId(CASING_INDEX), + TextureFactory.builder().addIcon(OVERLAY_FRONT_DISTILLATION_TOWER_ACTIVE).extFacing().build(), + TextureFactory.builder().addIcon(OVERLAY_FRONT_DISTILLATION_TOWER_ACTIVE_GLOW).extFacing().glow().build()}; + return new ITexture[]{ + Textures.BlockIcons.getCasingTextureForId(CASING_INDEX), + TextureFactory.builder().addIcon(OVERLAY_FRONT_DISTILLATION_TOWER).extFacing().build(), + TextureFactory.builder().addIcon(OVERLAY_FRONT_DISTILLATION_TOWER_GLOW).extFacing().glow().build()}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(CASING_INDEX)}; + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "DistillationTower.png"); + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sDistillationRecipes; + } + @Override protected GT_Multiblock_Tooltip_Builder createTooltip() { final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); @@ -179,16 +233,8 @@ public class GT_TileEntity_MegaDistillTower extends GT_MetaTileEntity_Distillati } @Override - @SuppressWarnings({"rawtypes", "unchecked"}) - public IStructureDefinition getStructureDefinition() { - return (IStructureDefinition) STRUCTURE_DEFINITION; - } - - @Override - public boolean addEnergyInputToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (LoaderReference.tectech) - return TecTechUtils.addEnergyInputToMachineList(this, aTileEntity, aBaseCasingIndex); - return super.addEnergyInputToMachineList(aTileEntity, aBaseCasingIndex); + public IStructureDefinition getStructureDefinition() { + return STRUCTURE_DEFINITION; } @Override @@ -260,6 +306,7 @@ public class GT_TileEntity_MegaDistillTower extends GT_MetaTileEntity_Distillati found_Recipe = true; long tMaxPara = Math.min(ConfigHandler.megaMachinesMax, nominalV / tRecipe.mEUt); int tCurrentPara = handleParallelRecipe(tRecipe, new FluidStack[]{tFluid}, null, (int) tMaxPara); + this.updateSlots(); processed = tCurrentPara; Outputs = getMultiOutput(tRecipe, tCurrentPara); outputFluids = Outputs.getKey(); @@ -270,21 +317,13 @@ public class GT_TileEntity_MegaDistillTower extends GT_MetaTileEntity_Distillati continue; this.mEfficiency = (10000 - (this.getIdealStatus() - this.getRepairStatus()) * 1000); this.mEfficiencyIncrease = 10000; - long actualEUT = (long) (tRecipe.mEUt) * processed; - if (actualEUT > Integer.MAX_VALUE) { - byte divider = 0; - while (actualEUT > Integer.MAX_VALUE) { - actualEUT = actualEUT / 2; - divider++; - } - BW_Util.calculateOverclockedNessMulti((int) (actualEUT / (divider * 2)), tRecipe.mDuration * (divider * 2), 1, nominalV, this); - } else - BW_Util.calculateOverclockedNessMulti((int) actualEUT, tRecipe.mDuration, 1, nominalV, this); + long actualEUT = ((long)tRecipe.mEUt) * processed; + calculateOverclockedNessMulti(actualEUT, tRecipe.mDuration, nominalV); //In case recipe is too OP for that machine - if (this.mMaxProgresstime == Integer.MAX_VALUE - 1 && this.mEUt == Integer.MAX_VALUE - 1) + if (this.mMaxProgresstime == Integer.MAX_VALUE - 1 && this.lEUt == Integer.MAX_VALUE - 1) return false; - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); + if (this.lEUt > 0) { + this.lEUt = (-this.lEUt); } this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); this.mOutputFluids = outputFluids.toArray(new FluidStack[0]); @@ -292,44 +331,10 @@ public class GT_TileEntity_MegaDistillTower extends GT_MetaTileEntity_Distillati this.mOutputItems = outputItems.toArray(new ItemStack[0]); else this.mOutputItems = null; - this.updateSlots(); return true; } } return false; } - @Override - public boolean drainEnergyInput(long aEU) { - if (LoaderReference.tectech) - return TecTechUtils.drainEnergyMEBFTecTech(this, aEU); - return MegaUtils.drainEnergyMegaVanilla(this, aEU); - } - - @Override - public long getMaxInputVoltage() { - if (LoaderReference.tectech) - return TecTechUtils.getMaxInputVoltage(this); - return super.getMaxInputVoltage(); - } - - @Override - @Optional.Method(modid = "tectech") - public List getVanillaEnergyHatches() { - return this.mEnergyHatches; - } - - @Override - @SuppressWarnings({"rawtypes", "unchecked"}) - @Optional.Method(modid = "tectech") - public List getTecTechEnergyTunnels() { - return TTTunnels; - } - - @Override - @SuppressWarnings({"rawtypes", "unchecked"}) - @Optional.Method(modid = "tectech") - public List getTecTechEnergyMultis() { - return TTMultiAmp; - } } diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaMultiBlockBase.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaMultiBlockBase.java new file mode 100644 index 0000000000..be3c46fd06 --- /dev/null +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaMultiBlockBase.java @@ -0,0 +1,296 @@ +package com.github.bartimaeusnek.bartworks.common.tileentities.multis.mega; + +import com.github.bartimaeusnek.bartworks.API.LoaderReference; +import com.github.bartimaeusnek.bartworks.util.BW_Tooltip_Reference; +import com.github.bartimaeusnek.bartworks.util.BW_Util; +import com.github.bartimaeusnek.bartworks.util.MegaUtils; +import com.github.bartimaeusnek.crossmod.tectech.TecTechEnabledMulti; +import com.github.bartimaeusnek.crossmod.tectech.helper.TecTechUtils; +import com.github.bartimaeusnek.crossmod.tectech.tileentites.tiered.LowPowerLaser; +import cpw.mods.fml.common.Optional; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.*; +import gregtech.api.util.GT_Utility; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import static gregtech.api.enums.GT_Values.V; + +@Optional.Interface(iface = "com.github.bartimaeusnek.crossmod.tectech.TecTechEnabledMulti", modid = "tectech", striprefs = true) +public abstract class GT_TileEntity_MegaMultiBlockBase> extends GT_MetaTileEntity_EnhancedMultiBlockBase implements TecTechEnabledMulti { + + protected GT_TileEntity_MegaMultiBlockBase(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GT_TileEntity_MegaMultiBlockBase(String aName) { + super(aName); + } + + long lEUt = 0; + private int energyTier = -1; + + public ArrayList TTTunnels = new ArrayList<>(); + public ArrayList TTMultiAmp = new ArrayList<>(); + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.lEUt = aNBT.getLong("lEUt"); + } + + @Override + public void clearHatches() { + super.clearHatches(); + this.energyTier = -1; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setLong("lEUt", lEUt); + } + + @SuppressWarnings("rawtypes") + @Optional.Method(modid = "tectech") + boolean areLazorsLowPowa() { + Collection collection = this.getTecTechEnergyTunnels(); + if (!collection.isEmpty()) + for (Object tecTechEnergyMulti : collection) + if (!(tecTechEnergyMulti instanceof LowPowerLaser)) + return false; + return true; + } + + @Override + @Optional.Method(modid = "tectech") + public List getVanillaEnergyHatches() { + return this.mEnergyHatches; + } + + @Override + @SuppressWarnings({"rawtypes", "unchecked"}) + @Optional.Method(modid = "tectech") + public List getTecTechEnergyTunnels() { + return TTTunnels; + } + + @Override + @SuppressWarnings({"rawtypes", "unchecked"}) + @Optional.Method(modid = "tectech") + public List getTecTechEnergyMultis() { + return TTMultiAmp; + } + + @Override + public boolean drainEnergyInput(long aEU) { + if (LoaderReference.tectech) + return TecTechUtils.drainEnergyMEBFTecTech(this, aEU); + return MegaUtils.drainEnergyMegaVanilla(this, aEU); + } + + @Override + public long getMaxInputVoltage() { + if (LoaderReference.tectech) + return TecTechUtils.getMaxInputVoltage(this); + return super.getMaxInputVoltage(); + } + + @Deprecated + @Override + protected void calculateOverclockedNessMulti(int aEUt, int aDuration, int mAmperage, long maxInputVoltage) { + calculateOverclockedNessMultiInternal((long)aEUt, aDuration, maxInputVoltage, false); + } + + @Deprecated + @Override + protected void calculatePerfectOverclockedNessMulti(int aEUt, int aDuration, int mAmperage, long maxInputVoltage) { + calculateOverclockedNessMultiInternal((long)aEUt, aDuration, maxInputVoltage, true); + } + + @Override + public String[] getInfoData() { + return LoaderReference.tectech ? this.getInfoDataArray(this) : super.getInfoData(); + } + + @Override + public String[] getInfoDataArray(GT_MetaTileEntity_MultiBlockBase multiBlockBase) { + int mPollutionReduction = 0; + + for (GT_MetaTileEntity_Hatch_Muffler tHatch : this.mMufflerHatches) { + if (GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(tHatch)) { + mPollutionReduction = Math.max(tHatch.calculatePollutionReduction(100), mPollutionReduction); + } + } + + long[] ttHatches = getCurrentInfoData(); + long storedEnergy = ttHatches[0]; + long maxEnergy = ttHatches[1]; + + for (GT_MetaTileEntity_Hatch_Energy tHatch : this.mEnergyHatches) { + if (GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(tHatch)) { + storedEnergy += tHatch.getBaseMetaTileEntity().getStoredEU(); + maxEnergy += tHatch.getBaseMetaTileEntity().getEUCapacity(); + } + } + + return new String[]{ + StatCollector.translateToLocal("GT5U.multiblock.Progress") + ": " + + EnumChatFormatting.GREEN + GT_Utility.formatNumbers(this.mProgresstime / 20) + EnumChatFormatting.RESET + " s / " + + EnumChatFormatting.YELLOW + GT_Utility.formatNumbers(this.mMaxProgresstime / 20) + EnumChatFormatting.RESET + " s", + StatCollector.translateToLocal("GT5U.multiblock.energy") + ": " + + EnumChatFormatting.GREEN + GT_Utility.formatNumbers(storedEnergy) + EnumChatFormatting.RESET + " EU / " + + EnumChatFormatting.YELLOW + GT_Utility.formatNumbers(maxEnergy) + EnumChatFormatting.RESET + " EU", + StatCollector.translateToLocal("GT5U.multiblock.usage") + ": " + + EnumChatFormatting.RED + GT_Utility.formatNumbers(-this.lEUt) + EnumChatFormatting.RESET + " EU/t", + StatCollector.translateToLocal("GT5U.multiblock.mei") + ": " + + EnumChatFormatting.YELLOW + GT_Utility.formatNumbers(this.getMaxInputVoltage()) + EnumChatFormatting.RESET + " EU/t(*" + TecTechUtils.getMaxInputAmperage(this) + "A) " + + StatCollector.translateToLocal("GT5U.machines.tier") + ": " + + EnumChatFormatting.YELLOW + BW_Util.getTierNameFromVoltage(this.getMaxInputVoltage()) + EnumChatFormatting.RESET, + StatCollector.translateToLocal("GT5U.multiblock.problems") + ": " + + EnumChatFormatting.RED + (this.getIdealStatus() - this.getRepairStatus()) + EnumChatFormatting.RESET + " " + + StatCollector.translateToLocal("GT5U.multiblock.efficiency") + ": " + + EnumChatFormatting.YELLOW + (float) this.mEfficiency / 100.0F + EnumChatFormatting.RESET + " %", + StatCollector.translateToLocal("GT5U.multiblock.pollution") + ": " + + EnumChatFormatting.GREEN + mPollutionReduction + EnumChatFormatting.RESET + " %", + BW_Tooltip_Reference.ADDED_BY_BARTIMAEUSNEK_VIA_BARTWORKS.get()}; + } + + + // Special overclocking to handle over MAX voltage + protected byte calculateOverclockedNessMultiInternal(long aEUt, int aDuration, long maxInputVoltage, boolean perfectOC) { + byte mTier = (byte) Math.max(0, BW_Util.getTier(maxInputVoltage)), overclockCount = 0; + if (mTier == 0) { + //Long time calculation + long xMaxProgresstime = ((long) aDuration) << 1; + if (xMaxProgresstime > Integer.MAX_VALUE - 1) { + //make impossible if too long + this.lEUt = Integer.MAX_VALUE - 1; + this.mMaxProgresstime = Integer.MAX_VALUE - 1; + } else { + this.lEUt = aEUt >> 2; + this.mMaxProgresstime = (int) xMaxProgresstime; + } + } else { + //Long EUt calculation + long xEUt = aEUt; + //Isnt too low EUt check? + long tempEUt = Math.max(xEUt, V[1]); + + this.mMaxProgresstime = aDuration; + + while (tempEUt <= BW_Util.getTierVoltage(mTier - 1)) { + tempEUt <<= 2;//this actually controls overclocking + //xEUt *= 4;//this is effect of everclocking + this.mMaxProgresstime >>= perfectOC ? 2 : 1;//this is effect of overclocking + xEUt = this.mMaxProgresstime <= 0 ? xEUt >> 1 : xEUt << 2;//U know, if the time is less than 1 tick make the machine use less power + overclockCount++; + } + + while (xEUt > maxInputVoltage && xEUt >= aEUt){ + //downclock one notch until we are good again, we have overshot. + xEUt >>= 2; + this.mMaxProgresstime <<= perfectOC ? 2 : 1; + overclockCount--; + } + + if (xEUt < aEUt){ + xEUt <<= 2; + this.mMaxProgresstime >>= perfectOC ? 2 : 1; + overclockCount++; + } + + this.lEUt = xEUt; + if (this.lEUt == 0) + this.lEUt = 1; + if (this.mMaxProgresstime <= 0) + this.mMaxProgresstime = 1;//set time to 1 tick + } + return overclockCount; + } + + + protected void calculateOverclockedNessMulti(long aEUt, int aDuration, long maxInputVoltage){ + calculateOverclockedNessMultiInternal(aEUt, aDuration, maxInputVoltage, false); + } + + protected void calculatePerfectOverclockedNessMulti(long aEUt, int aDuration, long maxInputVoltage){ + calculateOverclockedNessMultiInternal(aEUt, aDuration, maxInputVoltage, true); + } + + @Override + public boolean addEnergyInputToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (LoaderReference.tectech) { + int tier = TecTechUtils.addEnergyInputToMachineList(this, aTileEntity, aBaseCasingIndex, energyTier); + if(energyTier == -1) energyTier = tier; + return tier != -1; + } + else + { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy) { + if(energyTier == -1) + energyTier = ((GT_MetaTileEntity_Hatch_Energy) aMetaTileEntity).mTier; + if(((GT_MetaTileEntity_Hatch_Energy) aMetaTileEntity).mTier != energyTier) + return false; + ((GT_MetaTileEntity_Hatch)aMetaTileEntity).updateTexture(aBaseCasingIndex); + return this.mEnergyHatches.add((GT_MetaTileEntity_Hatch_Energy)aMetaTileEntity); + } else { + return false; + } + } + } + } + + @Override + public void stopMachine() { + this.lEUt = 0L; + super.stopMachine(); + } + + @Override + public boolean onRunningTick(ItemStack aStack) { + if (this.lEUt > 0) { + this.addEnergyOutput(this.lEUt * (long)this.mEfficiency / 10000L); + return true; + } else if (this.lEUt < 0 && !this.drainEnergyInput((-this.lEUt) * 10000L / (long)Math.max(1000, this.mEfficiency))) { + this.stopMachine(); + return false; + } else { + return true; + } + } + + @Override + public boolean isCorrectMachinePart(ItemStack itemStack) { + return true; + } + + @Override + public int getDamageToComponent(ItemStack itemStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack itemStack) { + return false; + } + + @Override + public int getMaxEfficiency(ItemStack itemStack) { + return 10000; + } + +} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaOilCracker.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaOilCracker.java index 4a7ac80aa8..6c0ba378d6 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaOilCracker.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaOilCracker.java @@ -25,27 +25,27 @@ package com.github.bartimaeusnek.bartworks.common.tileentities.multis.mega; import com.github.bartimaeusnek.bartworks.API.BorosilicateGlass; import com.github.bartimaeusnek.bartworks.API.LoaderReference; import com.github.bartimaeusnek.bartworks.common.configs.ConfigHandler; -import com.github.bartimaeusnek.bartworks.util.BW_Tooltip_Reference; import com.github.bartimaeusnek.bartworks.util.BW_Util; -import com.github.bartimaeusnek.bartworks.util.MegaUtils; import com.github.bartimaeusnek.bartworks.util.Pair; -import com.github.bartimaeusnek.crossmod.tectech.TecTechEnabledMulti; import com.github.bartimaeusnek.crossmod.tectech.helper.TecTechUtils; -import com.github.bartimaeusnek.crossmod.tectech.tileentites.tiered.LowPowerLaser; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.StructureDefinition; import cpw.mods.fml.common.Optional; import gregtech.api.GregTech_API; +import gregtech.api.enums.HeatingCoilLevel; +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_Hatch_Energy; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; +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.common.tileentities.machines.multi.GT_MetaTileEntity_OilCracker; +import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; @@ -57,15 +57,47 @@ import static com.github.bartimaeusnek.bartworks.util.RecipeFinderForParallel.ge import static com.github.bartimaeusnek.bartworks.util.RecipeFinderForParallel.handleParallelRecipe; import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; import static gregtech.api.enums.GT_Values.V; +import static gregtech.api.enums.Textures.BlockIcons.*; import static gregtech.api.util.GT_StructureUtility.*; @Optional.Interface(iface = "com.github.bartimaeusnek.crossmod.tectech.TecTechEnabledMulti", modid = "tectech", striprefs = true) -public class GT_TileEntity_MegaOilCracker extends GT_MetaTileEntity_OilCracker implements TecTechEnabledMulti { - - private final ArrayList TTTunnels = new ArrayList<>(); - private final ArrayList TTMultiAmp = new ArrayList<>(); - +public class GT_TileEntity_MegaOilCracker extends GT_TileEntity_MegaMultiBlockBase { + private static final int CASING_INDEX = 49; + private static final String STRUCTURE_PIECE_MAIN = "main"; + private static final IStructureDefinition STRUCTURE_DEFINITION = StructureDefinition.builder() + .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ + {" p p ", "ppgggggggggpp", " pgggggggggp ", " pgggpppgggp ", " pgggpMpgggp ", " pgggpppgggp ", " pgggggggggp ", "ppgggggggggpp", " p p "}, + {" p p ", "pgggggggggggp", " g c c c c g ", " g c c c c g ", " g c c c c g ", " g c c c c g ", " g c c c c g ", "pgggggggggggp", " p p "}, + {" p p ", "pgggggggggggp", " g c c c c g ", " p c c p ", " p c c c c p ", " p c c p ", " g c c c c g ", "pgggggggggggp", " p p "}, + {" p p ", "pgggggggggggp", " g c c c c g ", " p c c c c p ", " l c c c c r ", " p c c c c p ", " g c c c c g ", "pgggggggggggp", " p p "}, + {" p p ", "pgggggggggggp", " g c c c c g ", " p c c p ", " p c c c c p ", " p c c p ", " g c c c c g ", "pgggggggggggp", " p p "}, + {" p p ", "pgggggggggggp", " g c c c c g ", " g c c c c g ", " g c c c c g ", " g c c c c g ", " g c c c c g ", "pgggggggggggp", " p p "}, + {"ppmmmm~mmmmpp", "ppppppppppppp", "ppppppppppppp", "ppppppppppppp", "ppppppppppppp", "ppppppppppppp", "ppppppppppppp", "ppppppppppppp", "ppmmmmmmmmmpp"}, + + })) + .addElement('c', ofCoil(GT_TileEntity_MegaOilCracker::setCoilLevel, GT_TileEntity_MegaOilCracker::getCoilLevel)) + .addElement('p', ofBlock(GregTech_API.sBlockCasings4, 1)) + .addElement('l', ofChain( + ofHatchAdder(GT_TileEntity_MegaOilCracker::addLeftHatchToMachineList, CASING_INDEX, 2) + )) + .addElement('r', ofChain( + ofHatchAdder(GT_TileEntity_MegaOilCracker::addRightHatchToMachineList, CASING_INDEX, 3) + )) + .addElement('m', ofChain( + ofHatchAdder(GT_TileEntity_MegaOilCracker::addEnergyInputToMachineList, CASING_INDEX, 1), + ofHatchAdder(GT_TileEntity_MegaOilCracker::addMaintenanceToMachineList, CASING_INDEX, 1), + ofBlock(GregTech_API.sBlockCasings4, 1) + )) + .addElement('M', ofChain( + ofHatchAdder(GT_TileEntity_MegaOilCracker::addMiddleInputToMachineList, CASING_INDEX, 4) + )) + .addElement('g', BorosilicateGlass.ofBoroGlass((byte) 0, (byte) 1, Byte.MAX_VALUE, (te, t) -> te.glasTier = t, te -> te