From 8fa500152f38bc4c85c88bf028ceb0e3d2a482bd Mon Sep 17 00:00:00 2001 From: GTNH-Colen <54497873+GTNH-Colen@users.noreply.github.com> Date: Fri, 12 Aug 2022 11:21:00 +0100 Subject: Add wireless support to LSC --- .../GTMTE_LapotronicSuperCapacitor.java | 144 ++++++++++++++++++--- 1 file changed, 124 insertions(+), 20 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java index d77d5df09c..6262a4519a 100644 --- a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java +++ b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java @@ -5,43 +5,49 @@ import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_H import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoTunnel; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyMulti; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyTunnel; +import com.google.common.eventbus.Subscribe; import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import common.Blocks; import gregtech.api.enums.Dyes; import gregtech.api.enums.Textures.BlockIcons; import gregtech.api.gui.GT_GUIContainer_MultiMachine; +import gregtech.api.interfaces.IGlobalWirelessEnergy; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.*; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import java.math.BigDecimal; import java.math.BigInteger; import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; +import java.util.*; +import static com.google.common.math.LongMath.pow; import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; -public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMultiBlockBase { +public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMultiBlockBase implements IGlobalWirelessEnergy { private enum TopState { MayBeTop, Top, NotTop } + private boolean wireless_mode = false; + private boolean not_processed_lsc = true; + private enum Capacitor { IV(2, BigInteger.valueOf(600000000L), BigInteger.valueOf(600000000L)), LuV(3, BigInteger.valueOf(6000000000L), BigInteger.valueOf(6000000000L)), @@ -232,16 +238,19 @@ 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("Battery Buffer") - .addInfo("Power storage structure. Does not charge batteries or tools, however.") - .addInfo("Loses energy equal to 1% of the total capacity every 24 hours.") - .addInfo("Exception: Ultimate Capacitors only count as Lapotronic Capacitors (UV) for the") - .addInfo("purposes of passive loss calculation. The full capacity is counted towards the actual power capacity.") - .addSeparator() - .addInfo("Glass shell has to be Tier - 3 of the highest capacitor tier") - .addInfo("UV-tier glass required for TecTech Laser Hatches") - .addInfo("Add more or better capacitors to increase capacity") - .addSeparator() - .beginVariableStructureBlock(5, 5, 4, 18, 5, 5, false) + .addInfo("Power storage structure. Does not charge batteries or tools, however.") + .addInfo("Loses energy equal to 1% of the total capacity every 24 hours.") + .addInfo("Exception: Ultimate Capacitors only count as Lapotronic Capacitors (UV) for the") + .addInfo("purposes of passive loss calculation. The full capacity is counted towards the") + .addInfo("actual power capacity.") + .addSeparator() + .addInfo("Wireless mode can be enabled with a left click with a screwdriver.") + .addSeparator() + .addInfo("Glass shell has to be Tier - 3 of the highest capacitor tier") + .addInfo("UV-tier glass required for TecTech Laser Hatches") + .addInfo("Add more or better capacitors to increase capacity") + .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)") @@ -274,6 +283,50 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu "MultiblockDisplay.png"); } + private String user_name; + private String global_energy_user_uuid; + + @Override + public void onPreTick(IGregTechTileEntity tileEntity, long aTick) { + super.onPreTick(tileEntity, aTick); + + // On first tick (aTick restarts from 0 upon world reload). + if (not_processed_lsc && tileEntity.isServerSide()) { + // Add user to wireless network. + StrongCheckOrAddUser(tileEntity.getOwnerUuid(), tileEntity.getOwnerName()); + + // Get team UUID. + user_name = tileEntity.getOwnerName(); + global_energy_user_uuid = GetUUIDFromUsername(tileEntity.getOwnerName()); +// +// int existing_lsc_amount = LSC_ownership_map.getOrDefault(global_energy_user_uuid, 0); +// +// // Add them to the ownership map. +// LSC_ownership_map.put(global_energy_user_uuid, existing_lsc_amount + 1); +// +// System.out.println("TEST1234 " + tileEntity.getOwnerName()); +// System.out.println("TEST1234 " + global_energy_user_uuid); +// System.out.println("TEST1234 " + LSC_ownership_map.get(GetUUIDFromUsername(tileEntity.getOwnerName()))); + not_processed_lsc = false; + } + } + +// private static HashMap LSC_ownership_map = new HashMap<>(100, 0.9f); + +// @Override +// public void onRemoval() { +// super.onRemoval(); +// +// if (getBaseMetaTileEntity().isServerSide()) { +// +// // Get number of LSC controllers in world. +// int existing_lsc_amount = LSC_ownership_map.get(global_energy_user_uuid); +// +// // Update the map. +// LSC_ownership_map.put(global_energy_user_uuid, existing_lsc_amount - 1); +// } +// } + @Override public boolean isCorrectMachinePart(ItemStack stack) { return true; @@ -290,6 +343,9 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu @Override public boolean checkMachine(IGregTechTileEntity thisController, ItemStack guiSlotItem) { + + StrongCheckOrAddUser(thisController.getOwnerUuid(), thisController.getOwnerName()); + // Reset capacitor counts Arrays.fill(capacitors, 0); // Clear TT hatches @@ -391,6 +447,7 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu outputLastTick = outputLastTick.add(BigInteger.valueOf(power)); } } + // Draw energy from TT hatches for(GT_MetaTileEntity_Hatch_EnergyMulti eHatch : mEnergyHatchesTT) { if(eHatch == null || eHatch.getBaseMetaTileEntity().isInvalidTileEntity()) { @@ -403,6 +460,7 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu inputLastTick = inputLastTick.add(BigInteger.valueOf(power)); } } + // Output energy to TT hatches for(GT_MetaTileEntity_Hatch_DynamoMulti eDynamo : mDynamoHatchesTT){ if(eDynamo == null || eDynamo.getBaseMetaTileEntity().isInvalidTileEntity()){ @@ -415,6 +473,7 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu outputLastTick = outputLastTick.add(BigInteger.valueOf(power)); } } + // Draw energy from TT Laser hatches for(GT_MetaTileEntity_Hatch_EnergyTunnel eHatch : mEnergyTunnelsTT) { if(eHatch == null || eHatch.getBaseMetaTileEntity().isInvalidTileEntity()) { @@ -428,6 +487,7 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu inputLastTick = inputLastTick.add(BigInteger.valueOf(power)); } } + // Output energy to TT Laser hatches for(GT_MetaTileEntity_Hatch_DynamoTunnel eDynamo : mDynamoTunnelsTT){ if(eDynamo == null || eDynamo.getBaseMetaTileEntity().isInvalidTileEntity()){ @@ -441,8 +501,9 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu outputLastTick = outputLastTick.add(BigInteger.valueOf(power)); } } - // Loose some energy - // Recalculate if the repair status changed + + // Lose some energy. + // Re-calculate if the repair status changed. if(super.getRepairStatus() != repairStatusCache) { passiveDischargeAmount = recalculateLossWithMaintenance(super.getRepairStatus()); } @@ -454,9 +515,41 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu tBMTE.injectEnergyUnits((byte)ForgeDirection.UNKNOWN.ordinal(), inputLastTick.longValue(), 1L); tBMTE.drainEnergyUnits((byte)ForgeDirection.UNKNOWN.ordinal(), outputLastTick.longValue(), 1L); + if (wireless_mode && ((counter++ % 20) == 0)) { + System.out.println("TEST1"); + + counter = 1; + + BigInteger transferred_eu = stored.subtract(LSC_wireless_max_stored_eu); + + System.out.println("TEST2 " + transferred_eu); + + if (addEUToGlobalEnergyMap(global_energy_user_uuid, transferred_eu)) { + System.out.println("TEST3"); + stored = LSC_wireless_max_stored_eu; + } + +// // If EU inside LSC is > 100 trillion EU then dump excess into wireless network. +// if (stored.compareTo(LSC_wireless_max_stored_eu) >= 0) { +// addEUToGlobalEnergyMap(global_energy_user_uuid, stored.subtract(LSC_wireless_max_stored_eu)); +// } else { +// System.out.println("TEST2"); +// // If the user has sufficient energy then withdraw it from the energy net and add it to the LSC. +// if (addEUToGlobalEnergyMap(global_energy_user_uuid, stored.subtract(LSC_wireless_max_stored_eu))) { +// System.out.println("TEST4: " + stored.subtract(LSC_wireless_max_stored_eu)); +// stored = LSC_wireless_max_stored_eu; +// } +// } + } + return true; } + // 100 Trillion EU. + private static BigInteger LSC_wireless_max_stored_eu = BigInteger.valueOf(pow(10L,14)); + + private int counter = 1; + /** * To be called whenever the maintenance status changes or the capacity was recalculated * @param repairStatus @@ -508,7 +601,8 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu ll.add("Maintenance Status: " + ((super.getRepairStatus() == super.getIdealStatus()) ? EnumChatFormatting.GREEN + "Working perfectly" + EnumChatFormatting.RESET : EnumChatFormatting.RED + "Has Problems" + EnumChatFormatting.RESET)); - ll.add("---------------------------------------------"); + ll.add("Wireless mode: " + (wireless_mode ? "enabled." : "disabled.")); + ll.add("---------------------------------------------"); final String[] a = new String[ll.size()]; return ll.toArray(a); @@ -522,7 +616,9 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu nbt.setByteArray("stored", stored.toByteArray()); nbt.setByteArray("passiveDischargeAmount", passiveDischargeAmount.toByteArray()); - super.saveNBTData(nbt); + nbt.setBoolean("wireless_mode", wireless_mode); + + super.saveNBTData(nbt); } @Override @@ -533,7 +629,9 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu stored = new BigInteger(nbt.getByteArray("stored")); passiveDischargeAmount = new BigInteger(nbt.getByteArray("passiveDischargeAmount")); - super.loadNBTData(nbt); + wireless_mode = nbt.getBoolean("wireless_mode"); + + super.loadNBTData(nbt); } @Override @@ -605,4 +703,10 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu { return true; } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + wireless_mode = !wireless_mode; + GT_Utility.sendChatToPlayer(aPlayer, "Wireless network mode " + (wireless_mode ? "enabled." : "disabled.")); + } } -- cgit From f6eeaaf9e834a15f09e9db64442e8f634be0faee Mon Sep 17 00:00:00 2001 From: GTNH-Colen <54497873+GTNH-Colen@users.noreply.github.com> Date: Fri, 12 Aug 2022 20:11:21 +0100 Subject: Clean up --- .../common/itemBlocks/IB_LapotronicEnergyUnit.java | 46 ++++-- .../GTMTE_LapotronicSuperCapacitor.java | 175 ++++++++++----------- 2 files changed, 122 insertions(+), 99 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/common/itemBlocks/IB_LapotronicEnergyUnit.java b/src/main/java/common/itemBlocks/IB_LapotronicEnergyUnit.java index 6a2b4cbca8..25695d91e6 100644 --- a/src/main/java/common/itemBlocks/IB_LapotronicEnergyUnit.java +++ b/src/main/java/common/itemBlocks/IB_LapotronicEnergyUnit.java @@ -1,19 +1,25 @@ package common.itemBlocks; +import java.math.BigInteger; import java.util.List; +import gregtech.api.enums.GT_Values; +import gregtech.api.util.GT_Utility; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; +import static com.google.common.math.LongMath.pow; + public class IB_LapotronicEnergyUnit extends ItemBlock { - - public IB_LapotronicEnergyUnit(Block block) { + + public IB_LapotronicEnergyUnit(Block block) { super(block); } - + @Override public int getMetadata(int meta) { return meta; @@ -28,19 +34,37 @@ public class IB_LapotronicEnergyUnit extends ItemBlock { public String getUnlocalizedName(ItemStack stack) { return super.getUnlocalizedName() + "." + stack.getItemDamage(); } - - @SuppressWarnings("unchecked") + + // 5 minutes, 5 mins * 60s * 20 ticks. + public static long LSC_time_between_wireless_rebalance_in_ticks = 5L*60L*20L; + + // 100 Trillion EU. + public static BigInteger LSC_wireless_eu_cap = BigInteger.valueOf(pow(10L,14)); + + private static BigInteger UHV_cap_eu_per_tick = LSC_wireless_eu_cap.divide(BigInteger.valueOf(LSC_time_between_wireless_rebalance_in_ticks)); + + public static long EV_cap_storage = 60_000_000L; + public static long IV_cap_storage = 600_000_000L; + public static long LuV_cap_storage = 6_000_000_000L; + public static long ZPM_cap_storage = 60_000_000_000L; + public static long UV_cap_storage = 600_000_000_000L; + public static long UHV_cap_storage = Long.MAX_VALUE; + + @SuppressWarnings("unchecked") @Override public void addInformation(ItemStack stack, EntityPlayer player, List lines, boolean advancedTooltips) { lines.add(StatCollector.translateToLocal("tile.kekztech_lapotronicenergyunit_block.desc")); switch(stack.getItemDamage()) { - case 1: lines.add("Capacity: 600,000,000 EU"); break; - case 2: lines.add("Capacity: 6,000,000,000 EU"); break; - case 3: lines.add("Capacity: 60,000,000,000 EU"); break; - case 4: lines.add("Capacity: 600,000,000,000 EU"); break; - case 5: lines.add("Capacity: 9,223,372,036,854,775,807 EU"); break; + case 1: lines.add("Capacity: " + EnumChatFormatting.RED + GT_Utility.formatNumbers(IV_cap_storage) + EnumChatFormatting.GRAY + "EU"); break; + case 2: lines.add("Capacity: " + EnumChatFormatting.RED + GT_Utility.formatNumbers(LuV_cap_storage) + EnumChatFormatting.GRAY + "EU"); break; + case 3: lines.add("Capacity: " + EnumChatFormatting.RED + GT_Utility.formatNumbers(ZPM_cap_storage) + EnumChatFormatting.GRAY + "EU"); break; + case 4: lines.add("Capacity: " + EnumChatFormatting.RED + GT_Utility.formatNumbers(UV_cap_storage) + EnumChatFormatting.GRAY + "EU"); break; + case 5: + lines.add("Capacity: " + EnumChatFormatting.RED + GT_Utility.formatNumbers(UHV_cap_storage) + EnumChatFormatting.GRAY + "EU"); + lines.add("Supports up to " + EnumChatFormatting.RED + GT_Utility.formatNumbers(UHV_cap_eu_per_tick) + EnumChatFormatting.GRAY + "EU/t of wireless transfer per " + GT_Values.TIER_COLORS[9] + GT_Values.VN[9] + EnumChatFormatting.GRAY + " capacitor."); + break; case 6: lines.add("Capacity: None"); break; - case 7: lines.add("Capacity: 60,000,000 EU"); break; + case 7: lines.add("Capacity: " + EnumChatFormatting.RED + GT_Utility.formatNumbers(EV_cap_storage) + EnumChatFormatting.GRAY + " EU"); break; } } } diff --git a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java index 6262a4519a..8ab48e0862 100644 --- a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java +++ b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java @@ -5,11 +5,11 @@ import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_H import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoTunnel; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyMulti; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyTunnel; -import com.google.common.eventbus.Subscribe; import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import common.Blocks; import gregtech.api.enums.Dyes; +import gregtech.api.enums.GT_Values; import gregtech.api.enums.Textures.BlockIcons; import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.IGlobalWirelessEnergy; @@ -26,7 +26,6 @@ import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; -import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import java.math.BigDecimal; @@ -36,7 +35,9 @@ import java.util.*; 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.util.GT_StructureUtility.ofHatchAdder; +import static java.lang.Math.max; public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMultiBlockBase implements IGlobalWirelessEnergy { private enum TopState { @@ -48,14 +49,20 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu private boolean wireless_mode = false; private boolean not_processed_lsc = true; + private long uhv_cap_count = 0; + + private int counter = 1; + + private long max_passive_drain_eu_per_tick_per_uhv_cap = 1_000_000; + private enum Capacitor { - IV(2, BigInteger.valueOf(600000000L), BigInteger.valueOf(600000000L)), - LuV(3, BigInteger.valueOf(6000000000L), BigInteger.valueOf(6000000000L)), - ZPM(4, BigInteger.valueOf(60000000000L), BigInteger.valueOf(60000000000L)), - UV(5, BigInteger.valueOf(600000000000L), BigInteger.valueOf(600000000000L)), - UHV(6, BigInteger.valueOf(100000000000L), MAX_LONG), - None(0, BigInteger.ZERO, BigInteger.ZERO), - EV(1, BigInteger.valueOf(60000000L), BigInteger.valueOf(60000000L)); + IV( 2, BigInteger.valueOf(IV_cap_storage), BigInteger.valueOf(IV_cap_storage)), + LuV( 3, BigInteger.valueOf(LuV_cap_storage), BigInteger.valueOf(LuV_cap_storage)), + ZPM( 4, BigInteger.valueOf(ZPM_cap_storage), BigInteger.valueOf(ZPM_cap_storage)), + UV( 5, BigInteger.valueOf(UV_cap_storage), BigInteger.valueOf(UV_cap_storage)), + UHV( 6, BigInteger.valueOf(UHV_cap_storage), BigInteger.valueOf(UHV_cap_storage)), + None(0, BigInteger.ZERO, BigInteger.ZERO), + EV( 1, BigInteger.valueOf(EV_cap_storage), BigInteger.valueOf(EV_cap_storage)); private final int minimalGlassTier; private final BigInteger passiveDischargeValue; @@ -117,9 +124,9 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu ofHatchAdder(GTMTE_LapotronicSuperCapacitor::addBottomHatches, CASING_TEXTURE_ID, 1), onElementPass(te -> te.casingAmount++, ofBlock(LSC_PART, CASING_META)) )) - .addElement('g', BorosilicateGlass.ofBoroGlass((byte) -1, (te, t) -> te.glasTier = t, te -> te.glasTier)) + .addElement('g', 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, BorosilicateGlass.ofBoroGlass((byte) -1, (te, t) -> te.glasTier = t, te -> te.glasTier))), + onlyIf(te -> te.topState != TopState.NotTop, onElementPass(te -> te.topState = TopState.Top, BorosilicateGlass.ofBoroGlass((byte) -1, (te, t) -> te.glassTier = t, te -> te.glassTier))), onlyIf(te -> te.topState != TopState.Top, onElementPass(te -> te.topState = TopState.NotTop, ofBlockAdder(GTMTE_LapotronicSuperCapacitor::addStorageCell, LSC_PART, 1) )) @@ -147,7 +154,7 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu private BigInteger outputLastTick = BigInteger.ZERO; private int repairStatusCache = 0; - private byte glasTier = -1; + private byte glassTier = -1; private int casingAmount = 0; private TopState topState = TopState.MayBeTop; @@ -231,7 +238,11 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu private boolean addStorageCell(Block block, int meta) { if (block != LSC_PART || meta == 0) return false; capacitors[meta - 1]++; - return true; + + if (meta == 5) { + uhv_cap_count++; + } + return true; } @Override @@ -239,17 +250,20 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); tt.addMachineType("Battery Buffer") .addInfo("Power storage structure. Does not charge batteries or tools, however.") - .addInfo("Loses energy equal to 1% of the total capacity every 24 hours.") - .addInfo("Exception: Ultimate Capacitors only count as Lapotronic Capacitors (UV) for the") - .addInfo("purposes of passive loss calculation. The full capacity is counted towards the") - .addInfo("actual power capacity.") - .addSeparator() - .addInfo("Wireless mode can be enabled with a left click with a screwdriver.") + .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.") .addSeparator() .addInfo("Glass shell has to be Tier - 3 of the highest capacitor tier") .addInfo("UV-tier glass required for TecTech 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 UHV 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 it. If there is more it will add it to the network") + .addInfo("and remove it from the internal EU storage.") + .addSeparator() .beginVariableStructureBlock(5, 5, 4, 18, 5, 5, false) .addStructureInfo("Modular height of 4-18 blocks.") .addController("Front center bottom") @@ -283,7 +297,6 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu "MultiblockDisplay.png"); } - private String user_name; private String global_energy_user_uuid; @Override @@ -293,40 +306,16 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu // On first tick (aTick restarts from 0 upon world reload). if (not_processed_lsc && tileEntity.isServerSide()) { // Add user to wireless network. + LoadGlobalEnergyInfo(tileEntity.getWorld()); StrongCheckOrAddUser(tileEntity.getOwnerUuid(), tileEntity.getOwnerName()); // Get team UUID. - user_name = tileEntity.getOwnerName(); global_energy_user_uuid = GetUUIDFromUsername(tileEntity.getOwnerName()); -// -// int existing_lsc_amount = LSC_ownership_map.getOrDefault(global_energy_user_uuid, 0); -// -// // Add them to the ownership map. -// LSC_ownership_map.put(global_energy_user_uuid, existing_lsc_amount + 1); -// -// System.out.println("TEST1234 " + tileEntity.getOwnerName()); -// System.out.println("TEST1234 " + global_energy_user_uuid); -// System.out.println("TEST1234 " + LSC_ownership_map.get(GetUUIDFromUsername(tileEntity.getOwnerName()))); + not_processed_lsc = false; } } -// private static HashMap LSC_ownership_map = new HashMap<>(100, 0.9f); - -// @Override -// public void onRemoval() { -// super.onRemoval(); -// -// if (getBaseMetaTileEntity().isServerSide()) { -// -// // Get number of LSC controllers in world. -// int existing_lsc_amount = LSC_ownership_map.get(global_energy_user_uuid); -// -// // Update the map. -// LSC_ownership_map.put(global_energy_user_uuid, existing_lsc_amount - 1); -// } -// } - @Override public boolean isCorrectMachinePart(ItemStack stack) { return true; @@ -343,6 +332,7 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu @Override public boolean checkMachine(IGregTechTileEntity thisController, ItemStack guiSlotItem) { + uhv_cap_count = 0; StrongCheckOrAddUser(thisController.getOwnerUuid(), thisController.getOwnerName()); @@ -379,14 +369,14 @@ 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() > glasTier) + if (Capacitor.VALUES[highestCapacitor].getMinimalGlassTier() > glassTier) return false; break; } } // Glass has to be at least UV-tier to allow TT Laser hatches - if (glasTier < 8) { + if (glassTier < 8) { if(mEnergyTunnelsTT.size() > 0 || mDynamoTunnelsTT.size() > 0) return false; } @@ -423,6 +413,10 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu inputLastTick = BigInteger.ZERO; outputLastTick = BigInteger.ZERO; + long temp_stored = 0L; + long temp_inputLastTick = 0L; + long temp_outputLastTick = 0L; + // Draw energy from GT hatches for(GT_MetaTileEntity_Hatch_Energy eHatch : super.mEnergyHatches) { if(eHatch == null || eHatch.getBaseMetaTileEntity().isInvalidTileEntity()) { @@ -431,10 +425,11 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu final long power = getPowerToDraw(eHatch.maxEUInput() * eHatch.maxAmperesIn()); if(eHatch.getEUVar() >= power) { eHatch.setEUVar(eHatch.getEUVar() - power); - stored = stored.add(BigInteger.valueOf(power)); - inputLastTick = inputLastTick.add(BigInteger.valueOf(power)); + temp_stored += power; + temp_inputLastTick += power; } } + // Output energy to GT hatches for(GT_MetaTileEntity_Hatch_Dynamo eDynamo : super.mDynamoHatches){ if(eDynamo == null || eDynamo.getBaseMetaTileEntity().isInvalidTileEntity()){ @@ -443,8 +438,8 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu final long power = getPowerToPush(eDynamo.maxEUOutput() * eDynamo.maxAmperesOut()); if(power <= eDynamo.maxEUStore() - eDynamo.getEUVar()) { eDynamo.setEUVar(eDynamo.getEUVar() + power); - stored = stored.subtract(BigInteger.valueOf(power)); - outputLastTick = outputLastTick.add(BigInteger.valueOf(power)); + temp_stored -= power; + temp_outputLastTick += power; } } @@ -456,8 +451,8 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu final long power = getPowerToDraw(eHatch.maxEUInput() * eHatch.maxAmperesIn()); if(eHatch.getEUVar() >= power) { eHatch.setEUVar(eHatch.getEUVar() - power); - stored = stored.add(BigInteger.valueOf(power)); - inputLastTick = inputLastTick.add(BigInteger.valueOf(power)); + temp_stored += power; + temp_inputLastTick += power; } } @@ -469,8 +464,8 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu final long power = getPowerToPush(eDynamo.maxEUOutput() * eDynamo.maxAmperesOut()); if(power <= eDynamo.maxEUStore() - eDynamo.getEUVar()) { eDynamo.setEUVar(eDynamo.getEUVar() + power); - stored = stored.subtract(BigInteger.valueOf(power)); - outputLastTick = outputLastTick.add(BigInteger.valueOf(power)); + temp_stored -= power; + temp_outputLastTick += power; } } @@ -483,8 +478,8 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu final long power = getPowerToDraw(ttLaserWattage); if(eHatch.getEUVar() >= power) { eHatch.setEUVar(eHatch.getEUVar() - power); - stored = stored.add(BigInteger.valueOf(power)); - inputLastTick = inputLastTick.add(BigInteger.valueOf(power)); + temp_stored += power; + temp_inputLastTick += power; } } @@ -497,8 +492,8 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu final long power = getPowerToPush(ttLaserWattage); if(power <= eDynamo.maxEUStore() - eDynamo.getEUVar()) { eDynamo.setEUVar(eDynamo.getEUVar() + power); - stored = stored.subtract(BigInteger.valueOf(power)); - outputLastTick = outputLastTick.add(BigInteger.valueOf(power)); + temp_stored -= power; + temp_outputLastTick += power; } } @@ -507,7 +502,11 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu if(super.getRepairStatus() != repairStatusCache) { passiveDischargeAmount = recalculateLossWithMaintenance(super.getRepairStatus()); } - stored = stored.subtract(passiveDischargeAmount); + + temp_stored -= passiveDischargeAmount.longValue(); + stored = stored.add(BigInteger.valueOf(temp_stored)); + + // Check that the machine has positive EU stored. stored = (stored.compareTo(BigInteger.ZERO) <= 0) ? BigInteger.ZERO : stored; IGregTechTileEntity tBMTE = this.getBaseMetaTileEntity(); @@ -515,41 +514,33 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu tBMTE.injectEnergyUnits((byte)ForgeDirection.UNKNOWN.ordinal(), inputLastTick.longValue(), 1L); tBMTE.drainEnergyUnits((byte)ForgeDirection.UNKNOWN.ordinal(), outputLastTick.longValue(), 1L); - if (wireless_mode && ((counter++ % 20) == 0)) { - System.out.println("TEST1"); + if (uhv_cap_count <= 0) { + wireless_mode = false; + } + + // Every LSC_time_between_wireless_rebalance_in_ticks check against wireless network for re-balancing. + if (wireless_mode && (counter++ == LSC_time_between_wireless_rebalance_in_ticks)) { + // Reset tick counter. counter = 1; - BigInteger transferred_eu = stored.subtract(LSC_wireless_max_stored_eu); + // Find difference. + BigInteger transferred_eu = stored.subtract(LSC_wireless_eu_cap.multiply(BigInteger.valueOf(uhv_cap_count))); - System.out.println("TEST2 " + transferred_eu); + // If that difference can be added then do so. if (addEUToGlobalEnergyMap(global_energy_user_uuid, transferred_eu)) { - System.out.println("TEST3"); - stored = LSC_wireless_max_stored_eu; + // If it succeeds there was sufficient energy so set the internal capacity as such. + stored = LSC_wireless_eu_cap.multiply(BigInteger.valueOf(uhv_cap_count)); } - -// // If EU inside LSC is > 100 trillion EU then dump excess into wireless network. -// if (stored.compareTo(LSC_wireless_max_stored_eu) >= 0) { -// addEUToGlobalEnergyMap(global_energy_user_uuid, stored.subtract(LSC_wireless_max_stored_eu)); -// } else { -// System.out.println("TEST2"); -// // If the user has sufficient energy then withdraw it from the energy net and add it to the LSC. -// if (addEUToGlobalEnergyMap(global_energy_user_uuid, stored.subtract(LSC_wireless_max_stored_eu))) { -// System.out.println("TEST4: " + stored.subtract(LSC_wireless_max_stored_eu)); -// stored = LSC_wireless_max_stored_eu; -// } -// } } + inputLastTick = BigInteger.valueOf(temp_inputLastTick); + outputLastTick = BigInteger.valueOf(temp_outputLastTick); + return true; } - // 100 Trillion EU. - private static BigInteger LSC_wireless_max_stored_eu = BigInteger.valueOf(pow(10L,14)); - - private int counter = 1; - /** * To be called whenever the maintenance status changes or the capacity was recalculated * @param repairStatus @@ -558,8 +549,10 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu */ private BigInteger recalculateLossWithMaintenance(int repairStatus) { repairStatusCache = repairStatus; - return new BigDecimal(passiveDischargeAmount) - .multiply(BigDecimal.valueOf(1.0D + 0.2D * (getIdealStatus() - repairStatus))).toBigInteger(); + + // Maximum of 100,000 EU/t drained per UHV cell. + + return capacity.divide(BigInteger.valueOf(100L * 86400L * 20L)).min(BigInteger.valueOf(max_passive_drain_eu_per_tick_per_uhv_cap * max(1, uhv_cap_count))).multiply(BigInteger.valueOf(getIdealStatus() - repairStatus + 1)); } /** @@ -602,6 +595,7 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu ? EnumChatFormatting.GREEN + "Working perfectly" + EnumChatFormatting.RESET : EnumChatFormatting.RED + "Has Problems" + EnumChatFormatting.RESET)); ll.add("Wireless mode: " + (wireless_mode ? "enabled." : "disabled.")); + ll.add("UHV Capacitors detected: " + uhv_cap_count); ll.add("---------------------------------------------"); final String[] a = new String[ll.size()]; @@ -706,7 +700,12 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu @Override public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - wireless_mode = !wireless_mode; - GT_Utility.sendChatToPlayer(aPlayer, "Wireless network mode " + (wireless_mode ? "enabled." : "disabled.")); + if (uhv_cap_count != 0) { + 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.GRAY + " capacitor."); + wireless_mode = false; + } } } -- cgit From 7eb99b2c6627915fdc7ea4bc9e1c22d3959d13cc Mon Sep 17 00:00:00 2001 From: GTNH-Colen <54497873+GTNH-Colen@users.noreply.github.com> Date: Sat, 13 Aug 2022 17:26:21 +0100 Subject: Fix wireless interface update. --- .../common/itemBlocks/IB_LapotronicEnergyUnit.java | 9 +- .../GTMTE_LapotronicSuperCapacitor.java | 104 +++++++++++---------- 2 files changed, 58 insertions(+), 55 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/common/itemBlocks/IB_LapotronicEnergyUnit.java b/src/main/java/common/itemBlocks/IB_LapotronicEnergyUnit.java index 25695d91e6..488d2cdcd9 100644 --- a/src/main/java/common/itemBlocks/IB_LapotronicEnergyUnit.java +++ b/src/main/java/common/itemBlocks/IB_LapotronicEnergyUnit.java @@ -35,12 +35,13 @@ public class IB_LapotronicEnergyUnit extends ItemBlock { return super.getUnlocalizedName() + "." + stack.getItemDamage(); } - // 5 minutes, 5 mins * 60s * 20 ticks. - public static long LSC_time_between_wireless_rebalance_in_ticks = 5L*60L*20L; + // 5 Minutes, 5 mins * 60s * 20 ticks. + public static long LSC_time_between_wireless_rebalance_in_ticks = 5L * 60L * 20L; - // 100 Trillion EU. - public static BigInteger LSC_wireless_eu_cap = BigInteger.valueOf(pow(10L,14)); + // 60 Trillion EU. + public static BigInteger LSC_wireless_eu_cap = BigInteger.valueOf(60 * pow(10,12)); + // 10 Billion EU/t private static BigInteger UHV_cap_eu_per_tick = LSC_wireless_eu_cap.divide(BigInteger.valueOf(LSC_time_between_wireless_rebalance_in_ticks)); public static long EV_cap_storage = 60_000_000L; diff --git a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java index 8ab48e0862..6eb9c81f52 100644 --- a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java +++ b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java @@ -38,6 +38,7 @@ import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; import static common.itemBlocks.IB_LapotronicEnergyUnit.*; import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; import static java.lang.Math.max; +import static java.lang.Math.min; public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMultiBlockBase implements IGlobalWirelessEnergy { private enum TopState { @@ -48,30 +49,26 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu private boolean wireless_mode = false; private boolean not_processed_lsc = true; - private long uhv_cap_count = 0; - private int counter = 1; private long max_passive_drain_eu_per_tick_per_uhv_cap = 1_000_000; private enum Capacitor { - IV( 2, BigInteger.valueOf(IV_cap_storage), BigInteger.valueOf(IV_cap_storage)), - LuV( 3, BigInteger.valueOf(LuV_cap_storage), BigInteger.valueOf(LuV_cap_storage)), - ZPM( 4, BigInteger.valueOf(ZPM_cap_storage), BigInteger.valueOf(ZPM_cap_storage)), - UV( 5, BigInteger.valueOf(UV_cap_storage), BigInteger.valueOf(UV_cap_storage)), - UHV( 6, BigInteger.valueOf(UHV_cap_storage), BigInteger.valueOf(UHV_cap_storage)), - None(0, BigInteger.ZERO, BigInteger.ZERO), - EV( 1, BigInteger.valueOf(EV_cap_storage), BigInteger.valueOf(EV_cap_storage)); + IV(2, BigInteger.valueOf(IV_cap_storage)), + LuV(3, BigInteger.valueOf(LuV_cap_storage)), + ZPM(4, BigInteger.valueOf(ZPM_cap_storage)), + UV(5, BigInteger.valueOf(UV_cap_storage)), + UHV(6, MAX_LONG), + None(0, BigInteger.ZERO), + EV(1, BigInteger.valueOf(EV_cap_storage)); private final int minimalGlassTier; - private final BigInteger passiveDischargeValue; private final BigInteger providedCapacity; static final Capacitor[] VALUES = values(); - Capacitor(int minimalGlassTier, BigInteger passiveDischargeValue, BigInteger providedCapacity) { + Capacitor(int minimalGlassTier, BigInteger providedCapacity) { this.minimalGlassTier = minimalGlassTier; - this.passiveDischargeValue = passiveDischargeValue; this.providedCapacity = providedCapacity; } @@ -79,10 +76,6 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu return minimalGlassTier; } - public BigInteger getPassiveDischargeValue() { - return passiveDischargeValue; - } - public BigInteger getProvidedCapacity() { return providedCapacity; } @@ -135,8 +128,6 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu .build(); private static final BigInteger MAX_LONG = BigInteger.valueOf(Long.MAX_VALUE); - private static final BigDecimal PASSIVE_DISCHARGE_FACTOR_PER_TICK = - BigDecimal.valueOf(0.01D / 1728000.0D); // The magic number is ticks per 24 hours private final Set mEnergyHatchesTT = new HashSet<>(); private final Set mDynamoHatchesTT = new HashSet<>(); @@ -149,7 +140,7 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu private final int[] capacitors = new int[7]; private BigInteger capacity = BigInteger.ZERO; private BigInteger stored = BigInteger.ZERO; - private BigInteger passiveDischargeAmount = BigInteger.ZERO; + private long passiveDischargeAmount = 0; private BigInteger inputLastTick = BigInteger.ZERO; private BigInteger outputLastTick = BigInteger.ZERO; private int repairStatusCache = 0; @@ -248,32 +239,31 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu @Override protected GT_Multiblock_Tooltip_Builder createTooltip() { final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType("Battery Buffer") - .addInfo("Power storage structure. Does not charge batteries or tools, however.") + 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.") .addSeparator() - .addInfo("Glass shell has to be Tier - 3 of the highest capacitor tier") - .addInfo("UV-tier glass required for TecTech Laser Hatches") - .addInfo("Add more or better capacitors to increase capacity") + .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 UHV capacitor in the multiblock.") + .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 it. If there is more it will add it to the network") - .addInfo("and remove it from the internal EU storage.") + .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 (EV-UV), Ultimate Capacitor (UHV)", "Center 3x(1-15)x3 above base (9-135 blocks)") + .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 UV-tier glass") + .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") .addMaintenanceHatch("Any casing") .toolTipFinisher("KekzTech"); @@ -306,11 +296,11 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu // On first tick (aTick restarts from 0 upon world reload). if (not_processed_lsc && tileEntity.isServerSide()) { // Add user to wireless network. - LoadGlobalEnergyInfo(tileEntity.getWorld()); - StrongCheckOrAddUser(tileEntity.getOwnerUuid(), tileEntity.getOwnerName()); + loadGlobalEnergyInfo(tileEntity.getWorld()); + strongCheckOrAddUser(tileEntity.getOwnerUuid(), tileEntity.getOwnerName()); // Get team UUID. - global_energy_user_uuid = GetUUIDFromUsername(tileEntity.getOwnerName()); + global_energy_user_uuid = getUUIDFromUsername(tileEntity.getOwnerName()); not_processed_lsc = false; } @@ -334,7 +324,7 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu public boolean checkMachine(IGregTechTileEntity thisController, ItemStack guiSlotItem) { uhv_cap_count = 0; - StrongCheckOrAddUser(thisController.getOwnerUuid(), thisController.getOwnerName()); + strongCheckOrAddUser(thisController.getOwnerUuid(), thisController.getOwnerName()); // Reset capacitor counts Arrays.fill(capacitors, 0); @@ -386,21 +376,19 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu return false; // Calculate total capacity - passiveDischargeAmount = capacity = BigInteger.ZERO; + capacity = BigInteger.ZERO; for(int i = 0; i < capacitors.length; i++) { int count = capacitors[i]; capacity = capacity.add(Capacitor.VALUES[i].getProvidedCapacity().multiply(BigInteger.valueOf(count))); - passiveDischargeAmount = passiveDischargeAmount.add(Capacitor.VALUES[i].getPassiveDischargeValue().multiply(BigInteger.valueOf(count))); } // Calculate how much energy to void each tick - passiveDischargeAmount = new BigDecimal(passiveDischargeAmount).multiply(PASSIVE_DISCHARGE_FACTOR_PER_TICK).toBigInteger(); passiveDischargeAmount = recalculateLossWithMaintenance(getRepairStatus()); return mMaintenanceHatches.size() == 1; } @Override public void construct(ItemStack stackSize, boolean hintsOnly) { - int layer = Math.min(stackSize.stackSize + 3, 18); + 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); @@ -503,7 +491,8 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu passiveDischargeAmount = recalculateLossWithMaintenance(super.getRepairStatus()); } - temp_stored -= passiveDischargeAmount.longValue(); + // This will break if you transfer more than 2^63 EU/t, so don't do that. Thanks <3 + temp_stored -= passiveDischargeAmount; stored = stored.add(BigInteger.valueOf(temp_stored)); // Check that the machine has positive EU stored. @@ -519,7 +508,8 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu } // Every LSC_time_between_wireless_rebalance_in_ticks check against wireless network for re-balancing. - if (wireless_mode && (counter++ == LSC_time_between_wireless_rebalance_in_ticks)) { + counter++; + if (wireless_mode && (counter == LSC_time_between_wireless_rebalance_in_ticks)) { // Reset tick counter. counter = 1; @@ -527,6 +517,11 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu // Find difference. BigInteger transferred_eu = stored.subtract(LSC_wireless_eu_cap.multiply(BigInteger.valueOf(uhv_cap_count))); + if (transferred_eu.signum() == 1) { + temp_inputLastTick += transferred_eu.longValue(); + } else { + temp_outputLastTick += transferred_eu.longValue(); + } // If that difference can be added then do so. if (addEUToGlobalEnergyMap(global_energy_user_uuid, transferred_eu)) { @@ -547,12 +542,21 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu * This machine's repair status * @return new BigInteger instance for passiveDischargeAmount */ - private BigInteger recalculateLossWithMaintenance(int repairStatus) { + private long recalculateLossWithMaintenance(int repairStatus) { repairStatusCache = repairStatus; - // Maximum of 100,000 EU/t drained per UHV cell. + // This cannot overflow because there is a 135 capacitor maximum per LSC. + long temp_capacity_divided = capacity.divide(BigInteger.valueOf(100L * 86400L * 20L)).longValue(); - return capacity.divide(BigInteger.valueOf(100L * 86400L * 20L)).min(BigInteger.valueOf(max_passive_drain_eu_per_tick_per_uhv_cap * max(1, uhv_cap_count))).multiply(BigInteger.valueOf(getIdealStatus() - repairStatus + 1)); + // 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, uhv_cap_count)); + + // 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). + return total_passive_loss; } /** @@ -564,7 +568,7 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu private long getPowerToDraw(long hatchWatts){ final BigInteger remcapActual = capacity.subtract(stored); final BigInteger recampLimited = (MAX_LONG.compareTo(remcapActual) > 0) ? remcapActual : MAX_LONG; - return Math.min(hatchWatts, recampLimited.longValue()); + return min(hatchWatts, recampLimited.longValue()); } /** @@ -575,7 +579,7 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu */ private long getPowerToPush(long hatchWatts){ final BigInteger remStoredLimited = (MAX_LONG.compareTo(stored) > 0) ? stored : MAX_LONG; - return Math.min(hatchWatts, remStoredLimited.longValue()); + return min(hatchWatts, remStoredLimited.longValue()); } @Override @@ -594,8 +598,10 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu 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 ? "enabled." : "disabled.")); - ll.add("UHV Capacitors detected: " + uhv_cap_count); + 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: " + uhv_cap_count); ll.add("---------------------------------------------"); final String[] a = new String[ll.size()]; @@ -608,8 +614,6 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu nbt.setByteArray("capacity", capacity.toByteArray()); nbt.setByteArray("stored", stored.toByteArray()); - nbt.setByteArray("passiveDischargeAmount", passiveDischargeAmount.toByteArray()); - nbt.setBoolean("wireless_mode", wireless_mode); super.saveNBTData(nbt); @@ -621,8 +625,6 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu capacity = new BigInteger(nbt.getByteArray("capacity")); stored = new BigInteger(nbt.getByteArray("stored")); - passiveDischargeAmount = new BigInteger(nbt.getByteArray("passiveDischargeAmount")); - wireless_mode = nbt.getBoolean("wireless_mode"); super.loadNBTData(nbt); @@ -704,7 +706,7 @@ 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.GRAY + " 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; } } -- cgit From f93a963e709bbd317f5427d15a25c87476b1694a Mon Sep 17 00:00:00 2001 From: GTNH-Colen <54497873+GTNH-Colen@users.noreply.github.com> Date: Sat, 13 Aug 2022 18:33:22 +0100 Subject: Add LSC wireless display --- src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/main/java') diff --git a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java index 6eb9c81f52..ff932dd518 100644 --- a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java +++ b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java @@ -602,6 +602,9 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu ? 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: " + uhv_cap_count); + if (uhv_cap_count > 0) { + ll.add("Total wireless EU: " + EnumChatFormatting.RED + GT_Utility.formatNumbers(getUserEU(global_energy_user_uuid))); + } ll.add("---------------------------------------------"); final String[] a = new String[ll.size()]; -- cgit From fd1dbea0a9d54f528c054ac81a83b5a90b94f131 Mon Sep 17 00:00:00 2001 From: GTNH-Colen <54497873+GTNH-Colen@users.noreply.github.com> Date: Sat, 13 Aug 2022 18:58:03 +0100 Subject: Clarify maintenance. --- src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main/java') diff --git a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java index ff932dd518..ce72a7e7b8 100644 --- a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java +++ b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java @@ -242,6 +242,7 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu 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.") -- cgit From b7cc080b6c01b7d45526a64bae736b8ceccbe24e Mon Sep 17 00:00:00 2001 From: GTNH-Colen <54497873+GTNH-Colen@users.noreply.github.com> Date: Sun, 14 Aug 2022 23:02:06 +0100 Subject: Small change --- .../java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java index ce72a7e7b8..901b60a929 100644 --- a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java +++ b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java @@ -555,7 +555,6 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu // 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). return total_passive_loss; } @@ -603,9 +602,8 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu ? 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: " + uhv_cap_count); - if (uhv_cap_count > 0) { - ll.add("Total wireless EU: " + EnumChatFormatting.RED + GT_Utility.formatNumbers(getUserEU(global_energy_user_uuid))); - } + ll.add("Total wireless EU: " + EnumChatFormatting.RED + GT_Utility.formatNumbers(getUserEU(global_energy_user_uuid))); + ll.add("Wireless Network EU/t: " + EnumChatFormatting.RED + GT_Utility.formatNumbers(getUserEU(global_energy_user_uuid))); ll.add("---------------------------------------------"); final String[] a = new String[ll.size()]; -- cgit From 5b9a8a55f48444b9b1c803cbf82d2ef2ca5a202d Mon Sep 17 00:00:00 2001 From: GTNH-Colen <54497873+GTNH-Colen@users.noreply.github.com> Date: Mon, 15 Aug 2022 21:37:53 +0100 Subject: Debug statement --- .../tileentities/GTMTE_LapotronicSuperCapacitor.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/main/java') diff --git a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java index 901b60a929..06f017c121 100644 --- a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java +++ b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java @@ -27,6 +27,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.common.util.ForgeDirection; +import org.lwjgl.Sys; import java.math.BigDecimal; import java.math.BigInteger; @@ -606,6 +607,7 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu ll.add("Wireless Network EU/t: " + EnumChatFormatting.RED + GT_Utility.formatNumbers(getUserEU(global_energy_user_uuid))); ll.add("---------------------------------------------"); + printDebug(); final String[] a = new String[ll.size()]; return ll.toArray(a); } @@ -712,4 +714,17 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu wireless_mode = false; } } + + public void printDebug() { + System.out.println("DEBUG INFO: LSC"); + System.out.println("X: " + getBaseMetaTileEntity().getXCoord()); + System.out.println("Y: " + getBaseMetaTileEntity().getYCoord()); + System.out.println("Z: " + getBaseMetaTileEntity().getZCoord()); + + System.out.println("wireless_mode: " + wireless_mode); + System.out.println("uhv_cap_count: " + uhv_cap_count); + System.out.println("counter: " + counter); + System.out.println("(uhv_cap_count <= 0) " + (uhv_cap_count <= 0)); + System.out.println("(wireless_mode && (counter == LSC_time_between_wireless_rebalance_in_ticks)) " + (wireless_mode && (counter == LSC_time_between_wireless_rebalance_in_ticks))); + } } -- cgit From 5eccc275e27e1b4cf42088cddd480fdf00654d93 Mon Sep 17 00:00:00 2001 From: GTNH-Colen <54497873+GTNH-Colen@users.noreply.github.com> Date: Mon, 15 Aug 2022 21:52:02 +0100 Subject: Remove --- src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java | 1 - 1 file changed, 1 deletion(-) (limited to 'src/main/java') diff --git a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java index 06f017c121..5e47512dcb 100644 --- a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java +++ b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java @@ -607,7 +607,6 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMu ll.add("Wireless Network EU/t: " + EnumChatFormatting.RED + GT_Utility.formatNumbers(getUserEU(global_energy_user_uuid))); ll.add("---------------------------------------------"); - printDebug(); final String[] a = new String[ll.size()]; return ll.toArray(a); } -- cgit From deecc1d59de46944c890109131c514469c6bad2b Mon Sep 17 00:00:00 2001 From: GTNH-Colen <54497873+GTNH-Colen@users.noreply.github.com> Date: Thu, 18 Aug 2022 13:47:51 +0100 Subject: Idk --- .../GT