aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/metatileentity/implementations
diff options
context:
space:
mode:
authorConnor-Colenso <52056774+Connor-Colenso@users.noreply.github.com>2022-07-31 07:23:05 +0100
committerGitHub <noreply@github.com>2022-07-31 13:23:05 +0700
commitb9fea1be881fa1e21d3385f8c378dca636f885bf (patch)
treed5d1d46a42554ef9c80f04147e5ec2a82a68f782 /src/main/java/gregtech/api/metatileentity/implementations
parent445003d9f1b9f57fd8dc1b597be5ba529e558202 (diff)
downloadGT5-Unofficial-b9fea1be881fa1e21d3385f8c378dca636f885bf.tar.gz
GT5-Unofficial-b9fea1be881fa1e21d3385f8c378dca636f885bf.tar.bz2
GT5-Unofficial-b9fea1be881fa1e21d3385f8c378dca636f885bf.zip
Better Endgame Wireless EU (#1144)
* Basis of changes * Adjust voltage tiers to remove OpV * Better textures, move IDs around etc. * Format cleanup * Log level change * Dynamos * More stuff * More OpV purging. * Fixes * Remove wire support. * Textures * IDs * Update hatch/dynamo * New number formatter * Add default method * Add save method on world close * Cleanup old comments/debug * Author * Author * Author * Author * Restructuring of code * Unit tests * More unit tests + cleanup * Fix ID shift + add spares Co-authored-by: GTNH-Colen <54497873+GTNH-Colen@users.noreply.github.com>
Diffstat (limited to 'src/main/java/gregtech/api/metatileentity/implementations')
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Dynamo.java4
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Energy.java9
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Wireless_Dynamo.java148
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Wireless_Hatch.java166
4 files changed, 327 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Dynamo.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Dynamo.java
index 1156ed7117..ae2aea8e4a 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Dynamo.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Dynamo.java
@@ -14,6 +14,10 @@ public class GT_MetaTileEntity_Hatch_Dynamo extends GT_MetaTileEntity_Hatch {
super(aID, aName, aNameRegional, aTier, 0, new String[]{"Generating electric Energy from Multiblocks", "Puts out up to 1 Amp"});
}
+ public GT_MetaTileEntity_Hatch_Dynamo(int aID, String aName, String aNameRegional, int aTier, String[] aDescription) {
+ super(aID, aName, aNameRegional, aTier, 0, aDescription);
+ }
+
public GT_MetaTileEntity_Hatch_Dynamo(String aName, int aTier, String aDescription, ITexture[][][] aTextures) {
super(aName, aTier, 0, aDescription, aTextures);
}
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Energy.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Energy.java
index d9fb5f01cc..a6bdc6726c 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Energy.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Energy.java
@@ -10,6 +10,11 @@ import net.minecraft.item.ItemStack;
import static gregtech.api.enums.GT_Values.V;
public class GT_MetaTileEntity_Hatch_Energy extends GT_MetaTileEntity_Hatch {
+
+ public GT_MetaTileEntity_Hatch_Energy(int aID, String aName, String aNameRegional, int aTier, String[] aDescription) {
+ super(aID, aName, aNameRegional, aTier, 0, aDescription);
+ }
+
public GT_MetaTileEntity_Hatch_Energy(int aID, String aName, String aNameRegional, int aTier) {
super(aID, aName, aNameRegional, aTier, 0, new String[]{"Energy Injector for Multiblocks", "Accepts up to 2 Amps"});
}
@@ -22,6 +27,10 @@ public class GT_MetaTileEntity_Hatch_Energy extends GT_MetaTileEntity_Hatch {
super(aName, aTier, 0, aDescription, aTextures);
}
+ public GT_MetaTileEntity_Hatch_Energy(String aName, int aTier, int aInvSlotCount, String[] aDescription, ITexture[][][] aTextures) {
+ super(aName, aTier, 0, aDescription, aTextures);
+ }
+
@Override
public ITexture[] getTexturesActive(ITexture aBaseTexture) {
return new ITexture[]{aBaseTexture, Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[mTier]};
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Wireless_Dynamo.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Wireless_Dynamo.java
new file mode 100644
index 0000000000..7f59b13669
--- /dev/null
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Wireless_Dynamo.java
@@ -0,0 +1,148 @@
+package gregtech.api.metatileentity.implementations;
+
+import gregtech.api.enums.Textures;
+import gregtech.api.interfaces.IGlobalWirelessEnergy;
+import gregtech.api.interfaces.ITexture;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.metatileentity.MetaTileEntity;
+import gregtech.api.util.GT_Utility;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.EnumChatFormatting;
+import java.math.BigInteger;
+
+import static gregtech.GT_Mod.gregtechproxy;
+import static gregtech.api.enums.GT_Values.*;
+
+public class GT_MetaTileEntity_Wireless_Dynamo extends GT_MetaTileEntity_Hatch_Dynamo implements IGlobalWirelessEnergy {
+
+ private static final long ticks_between_energy_addition = 100L*20L;
+ private static final long number_of_energy_additions = 2L;
+ private final BigInteger eu_transferred_per_operation = BigInteger.valueOf(2L * V[mTier] * ticks_between_energy_addition);
+ private String owner_uuid;
+ private String owner_name;
+
+ public GT_MetaTileEntity_Wireless_Dynamo(String aName, byte aTier, String[] aDescription, ITexture[][][] aTextures) {
+ super(aName, aTier, aDescription, aTextures);
+ }
+
+ public GT_MetaTileEntity_Wireless_Dynamo(int aID, String aName, String aNameRegional, int aTier) {
+ super(aID, aName, aNameRegional, aTier, new String[] {""});
+ }
+
+ @Override
+ public ITexture[] getTexturesActive(ITexture aBaseTexture) {
+ return new ITexture[]{aBaseTexture, Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI_WIRELESS_ON[mTier]};
+ }
+
+ @Override
+ public ITexture[] getTexturesInactive(ITexture aBaseTexture) {
+ return new ITexture[]{aBaseTexture, Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI_WIRELESS_ON[mTier]};
+ }
+
+ @Override
+ public boolean isSimpleMachine() {
+ return true;
+ }
+
+ @Override
+ public boolean isFacingValid(byte aFacing) {
+ return true;
+ }
+
+ @Override
+ public boolean isAccessAllowed(EntityPlayer aPlayer) {
+ return true;
+ }
+
+ @Override
+ public boolean isEnetOutput() {
+ return false;
+ }
+
+ @Override
+ public boolean isInputFacing(byte aSide) {
+ return aSide == getBaseMetaTileEntity().getFrontFacing();
+ }
+
+ @Override
+ public boolean isValidSlot(int aIndex) {
+ return false;
+ }
+
+ @Override
+ public long getMinimumStoredEU() {
+ return 2 * V[mTier];
+ }
+
+ @Override
+ public long maxEUOutput() {
+ return V[mTier];
+ }
+
+ @Override
+ public long maxEUStore() {
+ return V[mTier] * number_of_energy_additions * ticks_between_energy_addition;
+ }
+
+ @Override
+ public String[] getDescription() {
+ String uuid = gregtechproxy.getThePlayer().getUniqueID().toString();
+ return new String[] {
+// "Transmits " + EnumChatFormatting.RED + GT_Utility.formatNumbers(eu_transferred_per_operation/V[mTier]) + EnumChatFormatting.GRAY + " A of " + TIER_COLORS[mTier] + VN[mTier] + EnumChatFormatting.GRAY + " through trans-dimensional space every " + EnumChatFormatting.RED + GT_Utility.formatNumbers(ticks_between_energy_addition) + EnumChatFormatting.GRAY + " ticks.",
+ EnumChatFormatting.GRAY + "Does not connect to wires.",
+ EnumChatFormatting.GRAY + "There is currently " + EnumChatFormatting.RED + GT_Utility.formatNumbers(GlobalEnergy.getOrDefault(uuid, BigInteger.ZERO)) + EnumChatFormatting.GRAY + " EU in your network.",
+ AuthorColen
+ };
+ }
+
+ @Override
+ public long maxAmperesOut() {
+ return 2;
+ }
+
+ @Override
+ public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
+ return new GT_MetaTileEntity_Wireless_Dynamo(mName, mTier, new String[] {""}, mTextures);
+ }
+
+ @Override
+ public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) {
+ return false;
+ }
+
+ @Override
+ public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) {
+ return false;
+ }
+
+ @Override
+ public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
+ super.onPreTick(aBaseMetaTileEntity, aTick);
+
+ if (aBaseMetaTileEntity.isServerSide()) {
+
+ // On first tick find the player name and attempt to add them to the map.
+ if (aTick == 1) {
+
+ // UUID and username of the owner.
+ owner_uuid = aBaseMetaTileEntity.getOwnerUuid().toString();
+ owner_name = aBaseMetaTileEntity.getOwnerName();
+
+ // Attempt to load in map from file.
+ if (GlobalEnergy.size() == 0)
+ IGlobalWirelessEnergy.super.LoadGlobalEnergyInfo(aBaseMetaTileEntity.getWorld());
+
+ IGlobalWirelessEnergy.super.StrongCheckOrAddUser(owner_uuid, owner_name);
+
+ }
+
+ // Every ticks_between_energy_addition ticks change the energy content of the machine.
+ if (aTick % ticks_between_energy_addition == 0L) {
+ IGlobalWirelessEnergy.super.addEUToGlobalEnergyMap(owner_uuid, getEUVar());
+ setEUVar(0L);
+ }
+ }
+ }
+}
+
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Wireless_Hatch.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Wireless_Hatch.java
new file mode 100644
index 0000000000..cd999fce4e
--- /dev/null
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Wireless_Hatch.java
@@ -0,0 +1,166 @@
+package gregtech.api.metatileentity.implementations;
+
+import gregtech.api.enums.Textures;
+import gregtech.api.interfaces.IGlobalWirelessEnergy;
+import gregtech.api.interfaces.ITexture;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.metatileentity.MetaTileEntity;
+import gregtech.api.util.GT_Utility;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.EnumChatFormatting;
+
+import java.math.BigInteger;
+
+import static gregtech.GT_Mod.gregtechproxy;
+import static gregtech.api.enums.GT_Values.*;
+
+public class GT_MetaTileEntity_Wireless_Hatch extends GT_MetaTileEntity_Hatch_Energy implements IGlobalWirelessEnergy {
+
+ private static final long ticks_between_energy_addition = 100L*20L;
+ private static final long number_of_energy_additions = 2L;
+ private final BigInteger eu_transferred_per_operation = BigInteger.valueOf(2L * V[mTier] * ticks_between_energy_addition);
+ private final long eu_transferred_per_operation_long = eu_transferred_per_operation.longValueExact();
+ private String owner_uuid;
+ private String owner_name;
+
+
+ public GT_MetaTileEntity_Wireless_Hatch(String aName, byte aTier, String[] aDescription, ITexture[][][] aTextures) {
+ super(aName, aTier, 0, aDescription, aTextures);
+ }
+
+ public GT_MetaTileEntity_Wireless_Hatch(int aID, String aName, String aNameRegional, int aTier) {
+ super(aID, aName, aNameRegional, aTier, new String[] {""});
+ }
+
+ @Override
+ public String[] getDescription() {
+ String uuid = gregtechproxy.getThePlayer().getUniqueID().toString();
+ return new String[] {
+// "Receives " + EnumChatFormatting.RED + GT_Utility.formatNumbers(eu_transferred_per_operation.divide(BigInteger.valueOf(V[mTier]))) + EnumChatFormatting.GRAY + " A of " + TIER_COLORS[mTier] + VN[mTier] + EnumChatFormatting.GRAY + " through trans-dimensional space every " + EnumChatFormatting.RED + GT_Utility.formatNumbers(ticks_between_energy_addition) + EnumChatFormatting.GRAY + " ticks.",
+ EnumChatFormatting.GRAY + "Does not connect to wires.",
+ EnumChatFormatting.GRAY + "There is currently " + EnumChatFormatting.RED + GT_Utility.formatNumbers(IGlobalWirelessEnergy.super.GetUserEU(uuid)) + EnumChatFormatting.GRAY + " EU in your network.",
+ AuthorColen
+ };
+ }
+
+ @Override
+ public ITexture[] getTexturesActive(ITexture aBaseTexture) {
+ return new ITexture[]{aBaseTexture, Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI_WIRELESS_ON[mTier]};
+ }
+
+ @Override
+ public ITexture[] getTexturesInactive(ITexture aBaseTexture) {
+ return new ITexture[]{aBaseTexture, Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI_WIRELESS_ON[mTier]};
+ }
+
+ @Override
+ public boolean isSimpleMachine() {
+ return true;
+ }
+
+ @Override
+ public boolean isFacingValid(byte aFacing) {
+ return true;
+ }
+
+ @Override
+ public boolean isAccessAllowed(EntityPlayer aPlayer) {
+ return true;
+ }
+
+ @Override
+ public boolean isEnetInput() {
+ return false;
+ }
+
+ @Override
+ public boolean isInputFacing(byte aSide) {
+ return aSide == getBaseMetaTileEntity().getFrontFacing();
+ }
+
+ @Override
+ public boolean isValidSlot(int aIndex) {
+ return false;
+ }
+
+ @Override
+ public long getMinimumStoredEU() {
+ return 2 * V[mTier];
+ }
+
+ @Override
+ public long maxEUInput() {
+ return V[mTier];
+ }
+
+ @Override
+ public long maxEUStore() {
+ return V[mTier] * number_of_energy_additions * ticks_between_energy_addition;
+ }
+
+ public long getEUCapacity() { return 40000L; }
+
+ @Override
+ public long maxAmperesIn() {
+ return 2;
+ }
+
+ @Override
+ public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
+ return new GT_MetaTileEntity_Wireless_Hatch(mName, mTier, new String[] {""}, mTextures);
+ }
+
+ @Override
+ public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) {
+ return false;
+ }
+
+ @Override
+ public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) {
+ return false;
+ }
+
+ @Override
+ public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
+
+ super.onPreTick(aBaseMetaTileEntity, aTick);
+
+ if (aBaseMetaTileEntity.isServerSide()) {
+
+ // On first tick find the player name and attempt to add them to the map.
+ if (aTick == 1) {
+
+ // UUID and username of the owner.
+ owner_uuid = aBaseMetaTileEntity.getOwnerUuid().toString();
+ owner_name = aBaseMetaTileEntity.getOwnerName();
+
+ // Attempt to load in map from file.
+ if (GlobalEnergy.size() == 0)
+ IGlobalWirelessEnergy.super.LoadGlobalEnergyInfo(aBaseMetaTileEntity.getWorld());
+
+ IGlobalWirelessEnergy.super.StrongCheckOrAddUser(owner_uuid, owner_name);
+
+ if (IGlobalWirelessEnergy.super.addEUToGlobalEnergyMap(owner_uuid, eu_transferred_per_operation.negate()))
+ setEUVar(eu_transferred_per_operation_long);
+ }
+
+ // This is set up in a way to be as optimised as possible. If a user has a relatively plentiful energy network
+ // it should make no difference to them. Minimising the number of operations on BigInteger is essential.
+
+ // Every ticks_between_energy_addition add eu_transferred_per_operation to internal EU storage from network.
+ if (aTick % ticks_between_energy_addition == 0L) {
+ long total_eu = this.getBaseMetaTileEntity().getStoredEU();
+
+ // Can the machine store the EU being added?
+ if (total_eu + eu_transferred_per_operation_long <= maxEUStore()) {
+
+ // Attempt to remove energy from the network and add it to the internal buffer of the machine.
+ if (IGlobalWirelessEnergy.super.addEUToGlobalEnergyMap(owner_uuid, eu_transferred_per_operation.negate())) {
+ setEUVar(total_eu + eu_transferred_per_operation_long);
+ }
+ }
+ }
+ }
+ }
+}