diff options
author | Glease <4586901+Glease@users.noreply.github.com> | 2022-01-30 16:56:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-30 09:56:29 +0100 |
commit | f46771464dbae32e8fe03892e6a729bf041ecae1 (patch) | |
tree | 97eddc420dcfa1a912fec560da6282041544a7b4 /src/main/java/gregtech/api/enums/Element.java | |
parent | 33b1408fccd8db37a75d4571e6ab8b0a92c30bc2 (diff) | |
download | GT5-Unofficial-f46771464dbae32e8fe03892e6a729bf041ecae1.tar.gz GT5-Unofficial-f46771464dbae32e8fe03892e6a729bf041ecae1.tar.bz2 GT5-Unofficial-f46771464dbae32e8fe03892e6a729bf041ecae1.zip |
Add compat for EnumHelper to Element#get (#908)
Diffstat (limited to 'src/main/java/gregtech/api/enums/Element.java')
-rw-r--r-- | src/main/java/gregtech/api/enums/Element.java | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/main/java/gregtech/api/enums/Element.java b/src/main/java/gregtech/api/enums/Element.java index 343f8ec0ed..72b2adfab8 100644 --- a/src/main/java/gregtech/api/enums/Element.java +++ b/src/main/java/gregtech/api/enums/Element.java @@ -1,8 +1,8 @@ package gregtech.api.enums; -import gregtech.api.util.GT_Utility; - import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; /** * This is some kind of Periodic Table, which I use to determine Properties of the Materials. @@ -300,13 +300,11 @@ public enum Element { mDecayTo = aDecayTo; mName = aName; mIsIsotope = aIsIsotope; + Companion.VALUES.put(name(), this); } public static Element get(String aMaterialName) { - Object tObject = GT_Utility.getFieldContent(Element.class, aMaterialName, false, false); - if (tObject instanceof Element) - return (Element) tObject; - return _NULL; + return Companion.VALUES.getOrDefault(aMaterialName, _NULL); } public long getProtons() { @@ -320,4 +318,15 @@ public enum Element { public long getMass() { return mProtons + mNeutrons + mAdditionalMass; } + + /** + * A companion object to workaround java limitations + */ + private static final class Companion { + /** + * Why is this a separate map and populated by enum constructor instead of a Map prepoluated with values()? + * Because apparently there are people hacking into this enum via EnumHelper. + */ + private static final Map<String, Element> VALUES = new HashMap<>(); + } } |