diff options
Diffstat (limited to 'src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java')
-rw-r--r-- | src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java | 588 |
1 files changed, 362 insertions, 226 deletions
diff --git a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java index 5aa0c75cad..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,31 +790,31 @@ 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 /energyInputValues.size(); + 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 /energyOutputValues.size(); + return sum / Math.max(energyOutputValues.size(), 1); } @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; } } |