aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorGTNH-Colen <54497873+GTNH-Colen@users.noreply.github.com>2022-08-12 11:21:00 +0100
committerGTNH-Colen <54497873+GTNH-Colen@users.noreply.github.com>2022-08-12 11:21:00 +0100
commit8fa500152f38bc4c85c88bf028ceb0e3d2a482bd (patch)
tree166c32cd40efca7fd107969a69a66decc74aeefc /src/main
parentb6a9cd22ee25df89298d05296195564c8e957e11 (diff)
downloadGT5-Unofficial-8fa500152f38bc4c85c88bf028ceb0e3d2a482bd.tar.gz
GT5-Unofficial-8fa500152f38bc4c85c88bf028ceb0e3d2a482bd.tar.bz2
GT5-Unofficial-8fa500152f38bc4c85c88bf028ceb0e3d2a482bd.zip
Add wireless support to LSC
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java144
1 files changed, 124 insertions, 20 deletions
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<GTMTE_LapotronicSuperCapacitor> {
+public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_EnhancedMultiBlockBase<GTMTE_LapotronicSuperCapacitor> 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<String, Integer> 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."));
+ }
}