aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/detrav
diff options
context:
space:
mode:
authorAlexdoru <57050655+Alexdoru@users.noreply.github.com>2024-09-14 16:45:43 +0200
committerGitHub <noreply@github.com>2024-09-14 14:45:43 +0000
commitb05ecea2a07232a7a13260aafadeebe829b03076 (patch)
treeaafd6354c8ccc0b53446240bb54a3d5284e74f17 /src/main/java/detrav
parent21a087fba239ca87e01eaa8df62e00cc26a201c2 (diff)
downloadGT5-Unofficial-b05ecea2a07232a7a13260aafadeebe829b03076.tar.gz
GT5-Unofficial-b05ecea2a07232a7a13260aafadeebe829b03076.tar.bz2
GT5-Unofficial-b05ecea2a07232a7a13260aafadeebe829b03076.zip
Reduce (useless) memory allocation for detrav fluid scanner (#3185)
Diffstat (limited to 'src/main/java/detrav')
-rw-r--r--src/main/java/detrav/DetravLoaderAfterGTPreload.java21
-rw-r--r--src/main/java/detrav/DetravScannerMod.java9
-rw-r--r--src/main/java/detrav/net/ProspectingPacket.java15
-rw-r--r--src/main/java/detrav/utils/FluidColors.java137
4 files changed, 43 insertions, 139 deletions
diff --git a/src/main/java/detrav/DetravLoaderAfterGTPreload.java b/src/main/java/detrav/DetravLoaderAfterGTPreload.java
deleted file mode 100644
index 45ce3c2381..0000000000
--- a/src/main/java/detrav/DetravLoaderAfterGTPreload.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package detrav;
-
-import detrav.items.DetravMetaGeneratedTool01;
-import detrav.items.processing.ProcessingDetravToolProspector;
-
-/**
- * Created by wital_000 on 18.03.2016.
- */
-public class DetravLoaderAfterGTPreload implements Runnable {
-
- @Override
- public void run() {
-
- // items
- new DetravMetaGeneratedTool01();
-
- // recipes and etc
- new ProcessingDetravToolProspector();
-
- }
-}
diff --git a/src/main/java/detrav/DetravScannerMod.java b/src/main/java/detrav/DetravScannerMod.java
index d79ed76010..c65bc49a34 100644
--- a/src/main/java/detrav/DetravScannerMod.java
+++ b/src/main/java/detrav/DetravScannerMod.java
@@ -10,10 +10,11 @@ import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
+import detrav.items.DetravMetaGeneratedTool01;
+import detrav.items.processing.ProcessingDetravToolProspector;
import detrav.net.DetravNetwork;
import detrav.proxies.CommonProxy;
import detrav.utils.DetravCreativeTab;
-import detrav.utils.FluidColors;
import detrav.utils.GTppHelper;
import gregtech.GT_Version;
import gregtech.api.GregTechAPI;
@@ -35,7 +36,10 @@ public class DetravScannerMod {
public static DetravScannerMod instance;
public DetravScannerMod() {
- GregTechAPI.sAfterGTPreload.add(new DetravLoaderAfterGTPreload());
+ GregTechAPI.sAfterGTPreload.add(() -> {
+ new DetravMetaGeneratedTool01(); // items
+ new ProcessingDetravToolProspector(); // recipes and etc
+ });
new DetravNetwork();
}
@@ -61,6 +65,5 @@ public class DetravScannerMod {
public void onPostLoad(FMLPostInitializationEvent aEvent) {
proxy.onPostLoad();
GTppHelper.generate_OreIDs();
- FluidColors.makeColors();
}
}
diff --git a/src/main/java/detrav/net/ProspectingPacket.java b/src/main/java/detrav/net/ProspectingPacket.java
index bfa22511e3..901a57d932 100644
--- a/src/main/java/detrav/net/ProspectingPacket.java
+++ b/src/main/java/detrav/net/ProspectingPacket.java
@@ -20,6 +20,7 @@ import bartworks.system.material.Werkstoff;
import detrav.DetravScannerMod;
import detrav.gui.DetravScannerGUI;
import detrav.gui.textures.DetravMapTexture;
+import detrav.utils.FluidColors;
import detrav.utils.GTppHelper;
import gregtech.api.GregTechAPI;
import gregtech.api.enums.Materials;
@@ -39,7 +40,6 @@ public class ProspectingPacket extends DetravPacket {
public final HashMap<Byte, Short>[][] map;
public final HashMap<String, Integer> ores;
public final HashMap<Short, String> metaMap;
- public static final HashMap<Integer, short[]> fluidColors = new HashMap<>();
public int level = -1;
@@ -56,9 +56,8 @@ public class ProspectingPacket extends DetravPacket {
}
private static void addOre(ProspectingPacket packet, byte y, int i, int j, short meta) {
+ final short[] rgba;
final String name;
- short[] rgba;
-
try {
if (packet.ptype == 0 || packet.ptype == 1) {
// Ore or Small Ore
@@ -72,7 +71,7 @@ public class ProspectingPacket extends DetravPacket {
final Werkstoff werkstoff = Werkstoff.werkstoffHashMap.getOrDefault((short) (meta * -1), null);
String translated = GTLanguageManager.getTranslation("bw.blocktype.ore");
name = translated.replace("%material", werkstoff.getLocalizedName());
- rgba = werkstoff != null ? werkstoff.getRGBA() : new short[] { 0, 0, 0, 0 };
+ rgba = werkstoff.getRGBA();
}
} else {
gtPlusPlus.core.material.Material pMaterial = GTppHelper.decodeoresGTpp.get((short) (meta - 7000));
@@ -81,13 +80,7 @@ public class ProspectingPacket extends DetravPacket {
}
} else if (packet.ptype == 2) {
// Fluid
- rgba = fluidColors.get((int) meta);
- if (rgba == null) {
- DetravScannerMod.proxy
- .sendPlayerExeption("Unknown fluid ID = " + meta + " Please add to FluidColors.java!");
- rgba = new short[] { 0, 0, 0, 0 };
- }
-
+ rgba = FluidColors.getColor(meta);
name = Objects.firstNonNull(
FluidRegistry.getFluid(meta)
.getLocalizedName(new FluidStack(FluidRegistry.getFluid(meta), 0)),
diff --git a/src/main/java/detrav/utils/FluidColors.java b/src/main/java/detrav/utils/FluidColors.java
index 6d18a3adda..29e2181bea 100644
--- a/src/main/java/detrav/utils/FluidColors.java
+++ b/src/main/java/detrav/utils/FluidColors.java
@@ -1,122 +1,51 @@
package detrav.utils;
-import static detrav.net.ProspectingPacket.fluidColors;
+import java.util.HashMap;
-import java.util.Arrays;
-import java.util.Objects;
+import javax.annotation.Nonnull;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
-import gregtech.api.enums.Materials;
+import gregtech.GTMod;
+import gregtech.api.enums.UndergroundFluidNames;
public class FluidColors {
- public static void makeColors() {
-
- reFillFluidColors();
-
- Arrays.stream(Materials.values())
- .forEach(mat -> {
- if (mat.getSolid(0) != null) fluidColors.putIfAbsent(
- mat.getSolid(0)
- .getFluidID(),
- mat.mRGBa);
- if (mat.getGas(0) != null) fluidColors.putIfAbsent(
- mat.getGas(0)
- .getFluidID(),
- mat.mRGBa);
- if (mat.getFluid(0) != null) fluidColors.putIfAbsent(
- mat.getFluid(0)
- .getFluidID(),
- mat.mRGBa);
- if (mat.getMolten(0) != null) fluidColors.putIfAbsent(
- mat.getMolten(0)
- .getFluidID(),
- mat.mRGBa);
- });
- FluidRegistry.getRegisteredFluids()
- .values()
- .stream()
- .filter(Objects::nonNull)
- .forEach(fluid -> { fluidColors.putIfAbsent(fluid.getID(), convertColorInt(fluid.getColor())); });
- }
-
- private static void reFillFluidColors() {
-
- // Should probably be put somewhere else, but I suck at Java
- fluidColors.put(Materials.NatruralGas.mGas.getID(), new short[] { 0x00, 0xff, 0xff });
- fluidColors.put(Materials.OilLight.mFluid.getID(), new short[] { 0xff, 0xff, 0x00 });
- fluidColors.put(Materials.OilMedium.mFluid.getID(), new short[] { 0x00, 0xFF, 0x00 });
- fluidColors.put(Materials.OilHeavy.mFluid.getID(), new short[] { 0xFF, 0x00, 0xFF });
- fluidColors.put(Materials.Oil.mFluid.getID(), new short[] { 0x00, 0x00, 0x00 });
- fluidColors.put(Materials.Helium_3.mGas.getID(), new short[] { 0x80, 0x20, 0xe0 });
- fluidColors.put(Materials.SaltWater.mFluid.getID(), new short[] { 0x80, 0xff, 0x80 });
- fluidColors.put(
- Materials.Lead.getMolten(0)
- .getFluid()
- .getID(),
- new short[] { 0xd0, 0xd0, 0xd0 });
- fluidColors.put(Materials.Chlorobenzene.mFluid.getID(), new short[] { 0x40, 0x80, 0x40 });
- fluidColors.put(
- FluidRegistry.getFluid("liquid_extra_heavy_oil")
- .getID(),
- new short[] { 0x00, 0x00, 0x50 });
- fluidColors.put(Materials.Oxygen.mGas.getID(), new short[] { 0x40, 0x40, 0xA0 });
- fluidColors.put(Materials.Nitrogen.mGas.getID(), new short[] { 0x00, 0x80, 0xd0 });
- fluidColors.put(Materials.Methane.mGas.getID(), new short[] { 0x80, 0x20, 0x20 });
- fluidColors.put(Materials.Ethane.mGas.getID(), new short[] { 0x40, 0x80, 0x20 });
- fluidColors.put(Materials.Ethylene.mGas.getID(), new short[] { 0xd0, 0xd0, 0xd0 });
- fluidColors.put(FluidRegistry.LAVA.getID(), new short[] { 0xFF, 0x00, 0x00 });
- Fluid unknownWater = FluidRegistry.getFluid("unknowwater");
- if (unknownWater != null) {
- fluidColors.put(
- FluidRegistry.getFluid("unknowwater")
- .getID(),
- new short[] { 0x8A, 0x2B, 0xE2 });
+ private static boolean initialized;
+ private static final HashMap<Integer, short[]> fluidColors = new HashMap<>();
+
+ private static void generateFluidColors() {
+ for (UndergroundFluidNames value : UndergroundFluidNames.values()) {
+ final Fluid fluid = FluidRegistry.getFluid(value.name);
+ if (fluid != null) {
+ if (value.renderColor != null) {
+ fluidColors.put(fluid.getID(), value.renderColor);
+ } else {
+ fluidColors.put(fluid.getID(), convertColorInt(fluid.getColor()));
+ }
+ } else {
+ GTMod.GT_FML_LOGGER.error("[FluidColors] no registered fluid named " + value.name);
+ }
}
- fluidColors.put(Materials.Hydrogen.mGas.getID(), new short[] { 0x32, 0x32, 0xD6 });
- fluidColors.put(Materials.SulfuricAcid.mFluid.getID(), new short[] { 0xFF, 0xB9, 0x0F });
- fluidColors.put(Materials.HydricSulfide.mGas.getID(), new short[] { 0xFF, 0x8F, 0x43 });
- fluidColors.put(Materials.CarbonMonoxide.mGas.getID(), new short[] { 0x10, 0x4E, 0x8B });
- fluidColors.put(Materials.CarbonDioxide.mGas.getID(), new short[] { 0x69, 0x69, 0x69 });
- fluidColors.put(
- FluidRegistry.getFluid("ic2distilledwater")
- .getID(),
- new short[] { 0x1E, 0x90, 0xFF });
- fluidColors.put(Materials.Deuterium.mGas.getID(), new short[] { 0xFF, 0xE3, 0x9F });
- fluidColors.put(
- Materials.Iron.getMolten(0)
- .getFluid()
- .getID(),
- new short[] { 0x8B, 0x88, 0x78 });
- fluidColors.put(
- Materials.Tin.getMolten(0)
- .getFluid()
- .getID(),
- new short[] { 0xE7, 0xE7, 0xE4 });
- fluidColors.put(
- Materials.Copper.getMolten(0)
- .getFluid()
- .getID(),
- new short[] { 0xFF, 0x7F, 0x24 });
- fluidColors.put(
- FluidRegistry.getFluid("fluorine")
- .getID(),
- new short[] { 0x99, 0xC1, 0xAD });
- fluidColors.put(
- FluidRegistry.getFluid("hydrofluoricacid")
- .getID(),
- new short[] { 0x00, 0xCE, 0xD1 });
- fluidColors.put(Materials.PhosphoricAcid.mFluid.getID(), new short[] { 0xEE, 0x76, 0x00 });
-
- // possible nulls
- fluidColors.put(Materials.LiquidAir.mFluid.getID(), new short[] { 0x99, 0x99, 0xEA });
-
}
private static short[] convertColorInt(int color) {
return new short[] { (short) (color << 16 & 0xff), (short) (color << 8 & 0xff), (short) (color & 0xff) };
}
+ @Nonnull
+ public static short[] getColor(int fluidID) {
+ if (!initialized) {
+ generateFluidColors();
+ initialized = true;
+ }
+ final short[] color = fluidColors.get(fluidID);
+ if (color == null) {
+ GTMod.GT_FML_LOGGER.error("Unknown fluid ID = " + fluidID + " This shouldn't happen!");
+ return new short[] { 0, 0, 0, 0 };
+ }
+ return color;
+ }
+
}