diff options
author | Connor-Colenso <52056774+Connor-Colenso@users.noreply.github.com> | 2022-07-31 07:23:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-31 13:23:05 +0700 |
commit | b9fea1be881fa1e21d3385f8c378dca636f885bf (patch) | |
tree | d5d1d46a42554ef9c80f04147e5ec2a82a68f782 /src/main/java/gregtech/api | |
parent | 445003d9f1b9f57fd8dc1b597be5ba529e558202 (diff) | |
download | GT5-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')
11 files changed, 713 insertions, 8 deletions
diff --git a/src/main/java/gregtech/api/enums/GT_Values.java b/src/main/java/gregtech/api/enums/GT_Values.java index 5765fc42c2..f0a29e2dfc 100644 --- a/src/main/java/gregtech/api/enums/GT_Values.java +++ b/src/main/java/gregtech/api/enums/GT_Values.java @@ -98,6 +98,7 @@ public class GT_Values { //TODO:AND ALL THE MATERIALS... for that //TODO:LIST OF MACHINES WITH POINTLESS TIERS (unless you implement some other tiering mechanism like reducing eu cost if time=1tick) //Macerator/Compressor/Furnace... and for cheap recipes any + /** * keeping Voltage*Amps < Integer.MAX_VALUE-7 for machines (and tier logic 4x EUt 2/ time) * AMV[4]= max amps at tier 4 @@ -448,9 +449,22 @@ public class GT_Values { public static boolean worldTickHappened = false; public static final int[] emptyIntArray = new int[0]; + + public static final IFluidTank[] emptyFluidTank = new IFluidTank[0]; public static final FluidTankGT[] emptyFluidTankGT = new FluidTankGT[0]; public static final FluidTankInfo[] emptyFluidTankInfo = new FluidTankInfo[0]; public static final FluidStack[] emptyFluidStack = new FluidStack[0]; public static final ItemStack[] emptyItemStackArray = new ItemStack[0]; + + /** + * Pretty formatting for author names. + */ + public static final String AuthorColen = "Author: " + + EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + EnumChatFormatting.ITALIC + EnumChatFormatting.UNDERLINE + "C" + + EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + EnumChatFormatting.ITALIC + EnumChatFormatting.UNDERLINE + "o" + + EnumChatFormatting.GREEN + EnumChatFormatting.BOLD + EnumChatFormatting.ITALIC + EnumChatFormatting.UNDERLINE + "l" + + EnumChatFormatting.DARK_AQUA + EnumChatFormatting.BOLD + EnumChatFormatting.ITALIC + EnumChatFormatting.UNDERLINE + "e" + + EnumChatFormatting.DARK_PURPLE + EnumChatFormatting.BOLD + EnumChatFormatting.ITALIC + EnumChatFormatting.UNDERLINE + "n"; + } diff --git a/src/main/java/gregtech/api/enums/ItemList.java b/src/main/java/gregtech/api/enums/ItemList.java index b73e6bd3a8..6996a139c4 100644 --- a/src/main/java/gregtech/api/enums/ItemList.java +++ b/src/main/java/gregtech/api/enums/ItemList.java @@ -967,6 +967,38 @@ public enum ItemList implements IItemContainer { Hatch_Energy_UV, Hatch_Energy_MAX, + Wireless_Hatch_Energy_ULV, + Wireless_Hatch_Energy_LV, + Wireless_Hatch_Energy_MV, + Wireless_Hatch_Energy_HV, + Wireless_Hatch_Energy_EV, + Wireless_Hatch_Energy_IV, + Wireless_Hatch_Energy_LuV, + Wireless_Hatch_Energy_ZPM, + Wireless_Hatch_Energy_UV, + Wireless_Hatch_Energy_UHV, + Wireless_Hatch_Energy_UEV, + Wireless_Hatch_Energy_UIV, + Wireless_Hatch_Energy_UMV, + Wireless_Hatch_Energy_UXV, + Wireless_Hatch_Energy_MAX, + + Wireless_Dynamo_Energy_ULV, + Wireless_Dynamo_Energy_LV, + Wireless_Dynamo_Energy_MV, + Wireless_Dynamo_Energy_HV, + Wireless_Dynamo_Energy_EV, + Wireless_Dynamo_Energy_IV, + Wireless_Dynamo_Energy_LuV, + Wireless_Dynamo_Energy_ZPM, + Wireless_Dynamo_Energy_UV, + Wireless_Dynamo_Energy_UHV, + Wireless_Dynamo_Energy_UEV, + Wireless_Dynamo_Energy_UIV, + Wireless_Dynamo_Energy_UMV, + Wireless_Dynamo_Energy_UXV, + Wireless_Dynamo_Energy_MAX, + Hatch_Input_ULV, Hatch_Input_LV, Hatch_Input_MV, diff --git a/src/main/java/gregtech/api/enums/Materials.java b/src/main/java/gregtech/api/enums/Materials.java index c51086369b..e080df4e0f 100644 --- a/src/main/java/gregtech/api/enums/Materials.java +++ b/src/main/java/gregtech/api/enums/Materials.java @@ -2324,13 +2324,6 @@ public class Materials implements IColorModulationContainer, ISubTagContainer { } private static void addHasGasFluid(Materials aMaterial, String aConfigPath) { -// System.out.println("ABC4321 " + aMaterial.mDefaultLocalName + " " + aMaterial.mIconSet.is_custom + " " + aMaterial.mName); -// if (aMaterial.mDefaultLocalName.toLowerCase().contains("spacetime")) { -//// GT_Mod.gregtechproxy.addFluid("molten.spacetime", "Molten SpaceTime", Materials.SpaceTime, 0, 0, GT_OreDictUnificator.get(OrePrefixes.cell, Materials.SpaceTime, 1L), ItemList.Cell_Empty.get(1L, new Object[0]), 100); -// System.out.println("TESTING 1234"); -// System.out.println("ABC4321 " + aMaterial.mDefaultLocalName + " " + aMaterial.mIconSet.is_custom + " " + aMaterial.mName + " " + aMaterial.mHasPlasma + " " + aMaterial.mHasGas); -// return; -// } if (aMaterial.mIconSet.is_custom) { return; diff --git a/src/main/java/gregtech/api/enums/Textures.java b/src/main/java/gregtech/api/enums/Textures.java index fb1ff424fc..26cd952a8d 100644 --- a/src/main/java/gregtech/api/enums/Textures.java +++ b/src/main/java/gregtech/api/enums/Textures.java @@ -548,6 +548,8 @@ public class Textures { OVERLAY_FRONT_VACUUM_FREEZER_GLOW, OVERLAY_FRONT_VACUUM_FREEZER_ACTIVE, OVERLAY_FRONT_VACUUM_FREEZER_ACTIVE_GLOW, + OVERLAY_ENERGY_ON_WIRELESS, + OVERLAY_ENERGY_OFF_WIRELESS, OVERLAY_FRONT_MULTI_SMELTER, OVERLAY_FRONT_MULTI_SMELTER_GLOW, @@ -1850,6 +1852,45 @@ public class Textures { TextureFactory.of(OVERLAY_ENERGY_IN_MULTI, new short[]{60, 60, 245, 0}), TextureFactory.of(OVERLAY_ENERGY_IN_MULTI, new short[]{40, 40, 245, 0}), }; + + public static final ITexture[] OVERLAYS_ENERGY_IN_MULTI_WIRELESS_ON = { + TextureFactory.of(OVERLAY_ENERGY_ON_WIRELESS, new short[]{255, 255, 255, 0}), + TextureFactory.of(OVERLAY_ENERGY_ON_WIRELESS, new short[]{255, 255, 255, 0}), + TextureFactory.of(OVERLAY_ENERGY_ON_WIRELESS, new short[]{255, 255, 255, 0}), + TextureFactory.of(OVERLAY_ENERGY_ON_WIRELESS, new short[]{255, 255, 255, 0}), + TextureFactory.of(OVERLAY_ENERGY_ON_WIRELESS, new short[]{255, 255, 255, 0}), + TextureFactory.of(OVERLAY_ENERGY_ON_WIRELESS, new short[]{255, 255, 255, 0}), + TextureFactory.of(OVERLAY_ENERGY_ON_WIRELESS, new short[]{255, 255, 255, 0}), + TextureFactory.of(OVERLAY_ENERGY_ON_WIRELESS, new short[]{255, 255, 255, 0}), + TextureFactory.of(OVERLAY_ENERGY_ON_WIRELESS, new short[]{255, 255, 255, 0}), + TextureFactory.of(OVERLAY_ENERGY_ON_WIRELESS, new short[]{255, 255, 255, 0}), + TextureFactory.of(OVERLAY_ENERGY_ON_WIRELESS, new short[]{255, 255, 255, 0}), + TextureFactory.of(OVERLAY_ENERGY_ON_WIRELESS, new short[]{255, 255, 255, 0}), + TextureFactory.of(OVERLAY_ENERGY_ON_WIRELESS, new short[]{255, 255, 255, 0}), + TextureFactory.of(OVERLAY_ENERGY_ON_WIRELESS, new short[]{255, 255, 255, 0}), + TextureFactory.of(OVERLAY_ENERGY_ON_WIRELESS, new short[]{255, 255, 255, 0}), + TextureFactory.of(OVERLAY_ENERGY_ON_WIRELESS, new short[]{255, 255, 255, 0}), + }; + + public static final ITexture[] OVERLAYS_ENERGY_IN_MULTI_WIRELESS_OFF = { + TextureFactory.of(OVERLAY_ENERGY_OFF_WIRELESS, new short[]{0, 0, 0, 0}), + TextureFactory.of(OVERLAY_ENERGY_OFF_WIRELESS, new short[]{0, 0, 0, 0}), + TextureFactory.of(OVERLAY_ENERGY_OFF_WIRELESS, new short[]{0, 0, 0, 0}), + TextureFactory.of(OVERLAY_ENERGY_OFF_WIRELESS, new short[]{0, 0, 0, 0}), + TextureFactory.of(OVERLAY_ENERGY_OFF_WIRELESS, new short[]{0, 0, 0, 0}), + TextureFactory.of(OVERLAY_ENERGY_OFF_WIRELESS, new short[]{0, 0, 0, 0}), + TextureFactory.of(OVERLAY_ENERGY_OFF_WIRELESS, new short[]{0, 0, 0, 0}), + TextureFactory.of(OVERLAY_ENERGY_OFF_WIRELESS, new short[]{0, 0, 0, 0}), + TextureFactory.of(OVERLAY_ENERGY_OFF_WIRELESS, new short[]{0, 0, 0, 0}), + TextureFactory.of(OVERLAY_ENERGY_OFF_WIRELESS, new short[]{0, 0, 0, 0}), + TextureFactory.of(OVERLAY_ENERGY_OFF_WIRELESS, new short[]{0, 0, 0, 0}), + TextureFactory.of(OVERLAY_ENERGY_OFF_WIRELESS, new short[]{0, 0, 0, 0}), + TextureFactory.of(OVERLAY_ENERGY_OFF_WIRELESS, new short[]{0, 0, 0, 0}), + TextureFactory.of(OVERLAY_ENERGY_OFF_WIRELESS, new short[]{0, 0, 0, 0}), + TextureFactory.of(OVERLAY_ENERGY_OFF_WIRELESS, new short[]{0, 0, 0, 0}), + TextureFactory.of(OVERLAY_ENERGY_OFF_WIRELESS, new short[]{0, 0, 0, 0}), + }; + public static final ITexture[] OVERLAYS_ENERGY_OUT_MULTI = { TextureFactory.of(OVERLAY_ENERGY_OUT_MULTI, new short[]{180, 180, 180, 0}), TextureFactory.of(OVERLAY_ENERGY_OUT_MULTI, new short[]{220, 220, 220, 0}), diff --git a/src/main/java/gregtech/api/interfaces/IGlobalWirelessEnergy.java b/src/main/java/gregtech/api/interfaces/IGlobalWirelessEnergy.java new file mode 100644 index 0000000000..bc0bf4a9e8 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/IGlobalWirelessEnergy.java @@ -0,0 +1,293 @@ +package gregtech.api.interfaces; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +import java.io.File; +import java.io.IOException; +import java.math.BigInteger; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +// If you are adding very late-game content feel free to tap into this interface. +// The eventual goal is to bypass laser/dynamo stuff and have energy deposited directly from ultra-endgame +// multi-blocks directly into the users network. +public interface IGlobalWirelessEnergy { + + // --------------------- NEVER access these maps! Use the methods provided! --------------------- + + // Global EU map. + HashMap<String, BigInteger> GlobalEnergy = new HashMap<>(100, 0.9f); + + // Maps user IDs to usernames and vice versa. Seems redundant but this makes accessing this + // easier in certain locations (like gt commands). + HashMap<String, String> GlobalEnergyName = new HashMap<>(100, 0.9f); + + // Maps UUIDs to other UUIDs. This allows users to join a team. + HashMap<String, String> GlobalEnergyTeam = new HashMap<>(100, 0.9f); + + // ---------------------------------------------------------------------------------------------- + + // Folder + String GlobalEnergyFolderName = "GlobalEnergyInformationStorage"; + + // 3 txt file names. Do not change. + String GlobalEnergyMapFileName = "GlobalEnergyMap"; + String GlobalEnergyNameFileName = "GlobalEnergyNameMap"; + String GlobalEnergyTeamFileName = "GlobalEnergyTeamMap"; + + // User 0 will join user 1 by calling this function. They will share the same energy network. + default void JoinUserNetwork(String user_uuid_0, String user_uuid_1) { + GlobalEnergyTeam.put(user_uuid_0, user_uuid_1); + } + + // --- Save data for global energy network -- + + default void SaveGlobalEnergyInfo(String world_name) { + CreateStorageIfNotExist(world_name); + SaveGlobalEnergyMap(world_name); + SaveGlobalEnergyName(world_name); + SaveGlobalEnergyTeam(world_name); + + } + + default void SaveGlobalEnergyMap(String world_name) { + try { + List<String> lines = GlobalEnergy.entrySet() + .stream() + .map(entry -> entry.getKey() + ":" + entry.getValue()) + .collect(Collectors.toList()); + + Path path = Paths.get("./saves/" + world_name + "/" + GlobalEnergyFolderName + "/" + GlobalEnergyMapFileName + ".txt").toAbsolutePath(); + Files.write(path, lines); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + default void SaveGlobalEnergyName(String world_name) { + try { + List<String> lines = GlobalEnergyName.entrySet() + .stream() + .map(entry -> entry.getKey() + ":" + entry.getValue()) + .collect(Collectors.toList()); + + Path path = Paths.get("./saves/" + world_name + "/" + GlobalEnergyFolderName + "/" + GlobalEnergyNameFileName + ".txt").toAbsolutePath(); + Files.write(path, lines); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + default void SaveGlobalEnergyTeam(String world_name) { + try { + List<String> lines = GlobalEnergyTeam.entrySet() + .stream() + .map(entry -> entry.getKey() + ":" + entry.getValue()) + .collect(Collectors.toList()); + + Path path = Paths.get("./saves/" + world_name + "/" + GlobalEnergyFolderName + "/" + GlobalEnergyTeamFileName + ".txt").toAbsolutePath(); + Files.write(path, lines); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + // --- Load data for global energy network --- + + default void LoadGlobalEnergyInfo(World world) { + CreateStorageIfNotExist(world.getWorldInfo().getWorldName()); + LoadGlobalEnergyMap(world); + LoadGlobalEnergyName(world); + LoadGlobalEnergyTeam(world); + } + + default void LoadGlobalEnergyMap(World world) { + try { + Path path = Paths.get("./saves/" + world.getWorldInfo().getWorldName() + "/" + GlobalEnergyFolderName + "/" + GlobalEnergyMapFileName + ".txt").toAbsolutePath(); + + String[] data; + for(String line : Files.readAllLines(path)) { + data = line.split(":"); + + String UUID = data[0]; + BigInteger num = new BigInteger(data[1]); + + GlobalEnergy.put(UUID, num); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + default void LoadGlobalEnergyName(World world) { + try { + Path path = Paths.get("./saves/" + world.getWorldInfo().getWorldName() + "/" + + GlobalEnergyFolderName + "/" + GlobalEnergyNameFileName + ".txt").toAbsolutePath(); + + String[] data; + for(String line : Files.readAllLines(path)) { + data = line.split(":"); + + GlobalEnergyName.put(data[0], data[1]); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + default void LoadGlobalEnergyTeam(World world) { + try { + Path path = Paths.get("./saves/" + world.getWorldInfo().getWorldName() + "/" + + GlobalEnergyFolderName + "/" + GlobalEnergyTeamFileName + ".txt").toAbsolutePath(); + + String[] data; + for(String line : Files.readAllLines(path)) { + data = line.split(":"); + + GlobalEnergyName.put(data[0], data[1]); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + // ------------------ + + default void CreateStorageIfNotExist(String world_name) { + Path folder_path = Paths.get("./saves/" + world_name + "/" + GlobalEnergyFolderName).toAbsolutePath(); + + // Create folder for storing global energy network info. + try { + Files.createDirectories(folder_path); + } catch (IOException e) { + e.printStackTrace(); + } + + // Create txt files. + try { + File file_0 = new File(folder_path + "/" + GlobalEnergyMapFileName + ".txt"); + file_0.createNewFile(); + File file_1 = new File(folder_path + "/" + GlobalEnergyNameFileName + ".txt"); + file_1.createNewFile(); + File file_2 = new File(folder_path + "/" + GlobalEnergyTeamFileName + ".txt"); + file_2.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + // Adds a user to the energy map if they do not already exist. Otherwise, do nothing. Will also check if the user + // has changed their username and adjust the maps accordingly. This should be called infrequently. Ideally on first + // tick of a machine being placed only. + + default void StrongCheckOrAddUser(EntityPlayer user) { + StrongCheckOrAddUser(user.getUniqueID().toString(), user.getDisplayName()); + } + + default void StrongCheckOrAddUser(UUID user_uuid, String user_name) { + StrongCheckOrAddUser(user_uuid.toString(), user_name); + } + + default void StrongCheckOrAddUser(String user_uuid, String user_name) { + + // Check if the user has a team. Add them if not. + GlobalEnergyTeam.putIfAbsent(user_uuid, user_uuid); + + // Check if the user is in the global energy map. + GlobalEnergy.putIfAbsent(user_uuid, BigInteger.ZERO); + + // If the username linked to the users fixed uuid is not equal to their current name then remove it. + // This indicates that their username has changed. + if (!(GlobalEnergyName.getOrDefault(user_uuid, "").equals(user_name))) { + String old_name = GlobalEnergyName.get(user_uuid); + GlobalEnergyName.remove(old_name); + } + + // Add UUID -> Name, Name -> UUID. + GlobalEnergyName.put(user_name, user_uuid); + GlobalEnergyName.put(user_uuid, user_name); + } + + // ------------------------------------------------------------------------------------ + // Add EU to the users global energy. You can enter a negative number to subtract it. + // If the value goes below 0 it will return false and not perform the operation. + // BigIntegers have much slower operations than longs/ints. You should call these methods + // as infrequently as possible and bulk store values to add to the global map. + default boolean addEUToGlobalEnergyMap(String user_uuid, BigInteger EU) { + + // Get the team UUID. Users are by default in a team with a UUID equal to their player UUID. + String team_uuid = GlobalEnergyTeam.getOrDefault(user_uuid, user_uuid); + + // Get the teams total energy stored. If they are not in the map, return 0 EU. + BigInteger total_eu = GlobalEnergy.getOrDefault(team_uuid, BigInteger.ZERO); + total_eu = total_eu.add(EU); + + // If there is sufficient EU then complete the operation and return true. + if (total_eu.signum() >= 0) { + GlobalEnergy.put(team_uuid, total_eu); + return true; + } + + // There is insufficient EU so cancel the operation and return false. + return false; + } + + default boolean addEUToGlobalEnergyMap(UUID user_uuid, BigInteger EU) { + return addEUToGlobalEnergyMap(user_uuid.toString(), EU); + } + + default boolean addEUToGlobalEnergyMap(UUID user_uuid, long EU) { + return addEUToGlobalEnergyMap(user_uuid.toString(), BigInteger.valueOf(EU)); + } + + default boolean addEUToGlobalEnergyMap(UUID user_uuid, int EU) { + return addEUToGlobalEnergyMap(user_uuid.toString(), BigInteger.valueOf(EU)); + } + + default boolean addEUToGlobalEnergyMap(String user_uuid, long EU) { + return addEUToGlobalEnergyMap(user_uuid, BigInteger.valueOf(EU)); + } + + default boolean addEUToGlobalEnergyMap(String user_uuid, int EU) { + return addEUToGlobalEnergyMap(user_uuid, BigInteger.valueOf(EU)); + } + + // ------------------------------------------------------------------------------------ + + default BigInteger GetUserEU(String user_uuid) { + return GlobalEnergy.getOrDefault(GlobalEnergyTeam.getOrDefault(user_uuid, user_uuid), BigInteger.ZERO); + } + + // This overwrites the EU in the network. Only use this if you are absolutely sure you know what you are doing. + default void SetUserEU(String user_uuid, BigInteger EU) { + GlobalEnergy.put(GlobalEnergyTeam.get(user_uuid), EU); + } + + default String GetUsernameFromUUID(String uuid) { + return GlobalEnergyName.getOrDefault(GlobalEnergyTeam.getOrDefault(uuid, ""), ""); + } + + default String GetUUIDFromUsername(String username) { + return GlobalEnergyTeam.getOrDefault(GlobalEnergyName.getOrDefault(username, ""), ""); + } + + default void ClearMaps() { + // Do not use this unless you are 100% certain you know what you are doing. + GlobalEnergy.clear(); + GlobalEnergyName.clear(); + GlobalEnergyTeam.clear(); + } + +} + + diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java index 524e377010..16a8ec8cca 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java @@ -346,7 +346,7 @@ public class BaseMetaPipeEntity extends CommonMetaTileEntity implements IGregTec @Override public ArrayList<String> getDebugInfo(EntityPlayer aPlayer, int aLogLevel) { final ArrayList<String> tList = new ArrayList<>(); - if (aLogLevel > 2) { + if (aLogLevel > 3) { tList.add("Meta-ID: " + EnumChatFormatting.BLUE+ mID +EnumChatFormatting.RESET + (hasValidMetaTileEntity() ? EnumChatFormatting.GREEN+" valid"+EnumChatFormatting.RESET : EnumChatFormatting.RED+" invalid"+EnumChatFormatting.RESET) + (mMetaTileEntity == null ? EnumChatFormatting.RED+" MetaTileEntity == null!"+EnumChatFormatting.RESET : " ")); } if (aLogLevel > 1) { 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); + } + } + } + } + } +} diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index e244bb4460..47d66ff816 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -95,6 +95,7 @@ import javax.annotation.Nullable; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.math.BigInteger; import java.math.RoundingMode; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; @@ -2563,6 +2564,10 @@ public class GT_Utility { }); } + public static String formatNumbers(BigInteger aNumber) { + return getDecimalFormat().format(aNumber); + } + public static String formatNumbers(long aNumber) { return getDecimalFormat().format(aNumber); } |