From f46771464dbae32e8fe03892e6a729bf041ecae1 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Sun, 30 Jan 2022 16:56:29 +0800 Subject: Add compat for EnumHelper to Element#get (#908) --- src/main/java/gregtech/api/enums/Element.java | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/main/java/gregtech/api') 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 VALUES = new HashMap<>(); + } } -- cgit