diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2019-03-04 18:10:39 +0000 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2019-03-04 18:10:39 +0000 |
commit | 8ead0095f30769b0c12d558953323d45a2790d6e (patch) | |
tree | 36fb314ace8d36603230560c390a1049b1484099 /src/Java | |
parent | 91371c9020ec10827653414d58dc7311b73ea686 (diff) | |
download | GT5-Unofficial-8ead0095f30769b0c12d558953323d45a2790d6e.tar.gz GT5-Unofficial-8ead0095f30769b0c12d558953323d45a2790d6e.tar.bz2 GT5-Unofficial-8ead0095f30769b0c12d558953323d45a2790d6e.zip |
+ Added more Wrappers for TC.
- Removed some obsolete classes.
$ Rewrote more TC code to be reflective.
Diffstat (limited to 'src/Java')
14 files changed, 973 insertions, 315 deletions
diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/HANDLER_Thaumcraft.java b/src/Java/gtPlusPlus/xmod/thaumcraft/HANDLER_Thaumcraft.java index be3b23531c..b02ba40392 100644 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/HANDLER_Thaumcraft.java +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/HANDLER_Thaumcraft.java @@ -3,31 +3,23 @@ package gtPlusPlus.xmod.thaumcraft; import java.util.Arrays; import java.util.List; -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; - -import gregtech.api.enums.GT_Values; -import gregtech.api.interfaces.internal.IThaumcraftCompat; -import gregtech.api.util.GT_Utility; - import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.api.objects.data.Pair; import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.util.reflect.ReflectionUtils; -import gtPlusPlus.xmod.thaumcraft.aspect.GTPP_Aspects.TC_AspectStack_Ex; +import gtPlusPlus.xmod.thaumcraft.aspect.GTPP_AspectCompat; +import gtPlusPlus.xmod.thaumcraft.aspect.GTPP_AspectStack; import gtPlusPlus.xmod.thaumcraft.util.ThaumcraftUtils; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; public class HANDLER_Thaumcraft { - public static IThaumcraftCompat sThaumcraftCompat; + public static GTPP_AspectCompat sThaumcraftCompat; public static Item mResearchNotes; - public static final AutoMap<Pair<ItemStack, TC_AspectStack_Ex[]>> sItemsToGetAspects = new AutoMap<Pair<ItemStack, TC_AspectStack_Ex[]>>(); - - static { - sThaumcraftCompat = (IThaumcraftCompat) GT_Utility.callConstructor("gtPlusPlus.xmod.thaumcraft.aspect.GTPP_AspectCompat", 0, null, GT_Values.D1, new Object[0]); - } + public static final AutoMap<Pair<ItemStack, GTPP_AspectStack[]>> sItemsToGetAspects = new AutoMap<Pair<ItemStack, GTPP_AspectStack[]>>(); public static void preInit(){ if (LoadedMods.Thaumcraft){ @@ -47,10 +39,16 @@ public class HANDLER_Thaumcraft { public static void postInit(){ if (LoadedMods.Thaumcraft){ + //Add Custom Aspects + + + //sThaumcraftCompat = (IThaumcraftCompat) GT_Utility.callConstructor("gtPlusPlus.xmod.thaumcraft.aspect.GTPP_AspectCompat", 0, null, GT_Values.D1, new Object[0]); + sThaumcraftCompat = new GTPP_AspectCompat(); + if (!sItemsToGetAspects.isEmpty()) { - for (Pair<ItemStack, TC_AspectStack_Ex[]> j : sItemsToGetAspects) { + for (Pair<ItemStack, GTPP_AspectStack[]> j : sItemsToGetAspects) { if (j .getKey() != null && (j.getValue() != null && j.getValue().length > 0)) { - List<TC_AspectStack_Ex> list = Arrays.asList(j.getValue()); + List<GTPP_AspectStack> list = Arrays.asList(j.getValue()); if (ThaumcraftUtils.registerThaumcraftAspectsToItem(j.getKey(), list, true)) { Logger.WARNING("[Aspect] Successfully added Aspects to "+j.getKey().getDisplayName()+"."); } diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/GTPP_AspectCompat.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/GTPP_AspectCompat.java index c363cba459..ea4c97fbfc 100644 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/GTPP_AspectCompat.java +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/GTPP_AspectCompat.java @@ -1,40 +1,29 @@ package gtPlusPlus.xmod.thaumcraft.aspect; -import gregtech.common.GT_ThaumcraftCompat; - -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.xmod.thaumcraft.aspect.GTPP_Aspects.TC_AspectStack_Ex; -import gtPlusPlus.xmod.thaumcraft.util.ThaumcraftUtils; - -import gregtech.api.enums.TC_Aspects; -import gregtech.api.enums.TC_Aspects.TC_AspectStack; -import gregtech.api.interfaces.internal.IThaumcraftCompat; -import gregtech.api.util.GT_LanguageManager; - import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; -import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; +import gregtech.api.enums.TC_Aspects; +import gregtech.api.util.GT_LanguageManager; +import gregtech.common.GT_ThaumcraftCompat; +import gtPlusPlus.api.objects.Logger; import net.minecraft.util.ResourceLocation; -import thaumcraft.api.aspects.Aspect; -import thaumcraft.api.aspects.AspectList; -public class GTPP_AspectCompat implements IThaumcraftCompat { +public class GTPP_AspectCompat { public static volatile Method m = null; - private static HashMap<String, TC_Aspect> mAspectCache = new LinkedHashMap<String, TC_Aspect>(); + private static HashMap<String, TC_Aspect_Wrapper> mAspectCache = new LinkedHashMap<String, TC_Aspect_Wrapper>(); - public static TC_Aspect ASPECT_BALANCE; - public static TC_Aspect ASPECT_LUST; - public static TC_Aspect ASPECT_STARBOUND; - public static TC_Aspect ASPECT_TOXIC; - public static TC_Aspect ASPECT_HEAVEN; + public static TC_Aspect_Wrapper ASPECT_BALANCE; + public static TC_Aspect_Wrapper ASPECT_LUST; + public static TC_Aspect_Wrapper ASPECT_STARBOUND; + public static TC_Aspect_Wrapper ASPECT_TOXIC; + public static TC_Aspect_Wrapper ASPECT_HEAVEN; /* TC_Aspects.AER.mAspect = Aspect.AIR; @@ -92,11 +81,11 @@ public class GTPP_AspectCompat implements IThaumcraftCompat { // Generate all existing Aspects as TC_Aspects - LinkedHashMap<String, Object> h = TC_Aspect.getVanillaAspectList(); + LinkedHashMap<String, Object> h = TC_Aspect_Wrapper.getVanillaAspectList(); for (String g : h.keySet()) { Object aBaseAspect = h.get(g); - if (aBaseAspect != null && TC_Aspect.isObjectAnAspect(aBaseAspect)) { - TC_Aspect aS = TC_Aspect.getAspect(g); + if (aBaseAspect != null && TC_Aspect_Wrapper.isObjectAnAspect(aBaseAspect)) { + TC_Aspect_Wrapper aS = TC_Aspect_Wrapper.getAspect(g); if (aS != null) { mAspectCache.put(g, aS); continue; @@ -109,10 +98,10 @@ public class GTPP_AspectCompat implements IThaumcraftCompat { // Custom Aspects ASPECT_BALANCE = - new TC_Aspect( + new TC_Aspect_Wrapper( "Purity", 15647411, - new TC_Aspect[]{ + new TC_Aspect_Wrapper[]{ get(TC_Aspects.GELUM), get(TC_Aspects.IGNIS) }, @@ -120,10 +109,10 @@ public class GTPP_AspectCompat implements IThaumcraftCompat { false, 1); ASPECT_LUST = - new TC_Aspect( + new TC_Aspect_Wrapper( "Vengeance", 15647411, - new TC_Aspect[]{ + new TC_Aspect_Wrapper[]{ get(TC_Aspects.CORPUS), get(TC_Aspects.ORDO) }, @@ -149,24 +138,24 @@ public class GTPP_AspectCompat implements IThaumcraftCompat { GT_LanguageManager.addStringLocalization("tc.aspect.custom5", "Heaven"); } - private TC_Aspect get(TC_Aspects aGtObjects) { + private TC_Aspect_Wrapper get(TC_Aspects aGtObjects) { try { - return TC_Aspect.generate(aGtObjects.mAspect); - } catch (IllegalArgumentException | IllegalAccessException e) { + return TC_Aspect_Wrapper.generate(aGtObjects.mAspect); + } catch (IllegalArgumentException e) { e.printStackTrace(); return null; } } - public static synchronized final AspectList getAspectList(final List<TC_AspectStack_Ex> aAspects) { - AspectList o = null; + public static synchronized final TC_AspectList_Wrapper getTC_AspectList_Wrapper(final List<GTPP_AspectStack> aAspects) { + TC_AspectList_Wrapper o = null; try { if (m == null || (m != null && !m.isAccessible())) { - m = GT_ThaumcraftCompat.class.getDeclaredMethod("getAspectList", List.class); + m = GT_ThaumcraftCompat.class.getDeclaredMethod("getTC_AspectList_Wrapper", List.class); m.setAccessible(true); } if (m != null) { - o = (AspectList) m.invoke(null, aAspects); + o = (TC_AspectList_Wrapper) m.invoke(null, aAspects); } } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { @@ -177,44 +166,6 @@ public class GTPP_AspectCompat implements IThaumcraftCompat { } return o; } - - public static synchronized final AspectList getAspectList_Ex(final List<TC_AspectStack_Ex> aAspects) { - final AspectList rAspects = new AspectList(); - for (final TC_AspectStack_Ex tAspect : aAspects) { - rAspects.add((Aspect) tAspect.mAspect.mAspect, (int) tAspect.mAmount); - } - return rAspects; - } - - @Override - public boolean registerPortholeBlacklistedBlock(Block p0) { - return ThaumcraftUtils.registerPortholeBlacklistedBlock(p0); - } - - @Override - public boolean registerThaumcraftAspectsToItem(ItemStack p0, List<TC_AspectStack> p1, boolean p2) { - return ThaumcraftUtils.registerThaumcraftAspectsToItem(p0, ThaumcraftUtils.convertAspectStack(p1), p2); - } - - @Override - public boolean registerThaumcraftAspectsToItem(ItemStack p0, List<TC_AspectStack> p1, String p2) { - return ThaumcraftUtils.registerThaumcraftAspectsToItem(p0, ThaumcraftUtils.convertAspectStack(p1), p2); - } - - @Override - public Object addCrucibleRecipe(String p0, Object p1, ItemStack p2, List<TC_AspectStack> p3) { - return ThaumcraftUtils.addCrucibleRecipe(p0, p1, p2, ThaumcraftUtils.convertAspectStack(p3)); - } - @Override - public Object addInfusionRecipe(String p0, ItemStack p1, ItemStack[] p2, ItemStack p3, int p4, List<TC_AspectStack> p5) { - return ThaumcraftUtils.addInfusionRecipe(p0, p1, p2, p3, p4, ThaumcraftUtils.convertAspectStack(p5)); - } - - @Override - public Object addResearch(String p0, String p1, String p2, String[] p3, String p4, ItemStack p5, int p6, int p7, - int p8, int p9, List<TC_AspectStack> p10, ItemStack[] p11, Object[] p12) { - return ThaumcraftUtils.addResearch(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, ThaumcraftUtils.convertAspectStack(p10), p11, p12); - } }
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/GTPP_AspectStack.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/GTPP_AspectStack.java new file mode 100644 index 0000000000..d7cfa7d326 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/GTPP_AspectStack.java @@ -0,0 +1,13 @@ +package gtPlusPlus.xmod.thaumcraft.aspect; + +public class GTPP_AspectStack { + + public final TC_Aspect_Wrapper mAspect; + public final int mAmount; + + public GTPP_AspectStack(TC_Aspect_Wrapper aAspect, int aAmount) { + mAspect = aAspect; + mAmount= aAmount; + } + +} diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/GTPP_Aspects.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/GTPP_Aspects.java deleted file mode 100644 index e1df0dabf5..0000000000 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/GTPP_Aspects.java +++ /dev/null @@ -1,77 +0,0 @@ -package gtPlusPlus.xmod.thaumcraft.aspect; - -import java.util.List; - -import thaumcraft.api.aspects.Aspect; - -public enum GTPP_Aspects { - - //Standard TC and GT Aspects - AER(1), ALIENIS(20), AQUA(3), ARBOR(1), AURAM(16), BESTIA(6), - COGNITIO(2), CORPUS(2), ELECTRUM(24), EXANIMIS(32), FABRICO(2), - FAMES(2), GELUM(1), GRANUM(4), HERBA(2), HUMANUS(8), IGNIS(4), - INSTRUMENTUM(4), ITER(6), LIMUS(3), LUCRUM(32), LUX(4), MACHINA(16), - MAGNETO(24), MESSIS(3), METALLUM(8), METO(2), MORTUUS(16), MOTUS(4), - NEBRISUM(48), ORDO(8), PANNUS(6), PERDITIO(2), PERFODIO(4), - PERMUTATIO(12), POTENTIA(16), PRAECANTATIO(16), RADIO(48), - SANO(24), SENSUS(4), SPIRITUS(24), STRONTIO(64), TELUM(6), - TERRA(1), TEMPESTAS(64), TENEBRAE(24), TUTAMEN(12), VACUOS(6), - VENENUM(16), VICTUS(4), VINCULUM(16), VITIUM(48), VITREUS(3), VOLATUS(12), - - //Custom Aspects - CUSTOM_3(24), CUSTOM_4(24), CUSTOM_2(48), CUSTOM_5(48), CUSTOM_1(64); - - public Aspect mAspect; - public int mValue; - - private GTPP_Aspects(final int aValue) { - this.mValue = aValue; - } - - public static class TC_AspectStack_Ex { - public GTPP_Aspects mAspect; - public long mAmount; - - public TC_AspectStack_Ex(final GTPP_Aspects aAspect, final long aAmount) { - this.mAspect = aAspect; - this.mAmount = aAmount; - } - - public TC_AspectStack_Ex copy() { - return new TC_AspectStack_Ex(this.mAspect, this.mAmount); - } - - public TC_AspectStack_Ex copy(final long aAmount) { - return new TC_AspectStack_Ex(this.mAspect, aAmount); - } - - public List<TC_AspectStack_Ex> addToAspectList(final List<TC_AspectStack_Ex> aList) { - if (this.mAmount == 0L) { - return aList; - } - for (final TC_AspectStack_Ex tAspect : aList) { - if (tAspect.mAspect == this.mAspect) { - final TC_AspectStack_Ex tc_AspectStack = tAspect; - tc_AspectStack.mAmount += this.mAmount; - return aList; - } - } - aList.add(this.copy()); - return aList; - } - - public boolean removeFromAspectList(final List<TC_AspectStack_Ex> aList) { - for (final TC_AspectStack_Ex tAspect : aList) { - if (tAspect.mAspect == this.mAspect && tAspect.mAmount >= this.mAmount) { - final TC_AspectStack_Ex tc_AspectStack = tAspect; - tc_AspectStack.mAmount -= this.mAmount; - if (tAspect.mAmount == 0L) { - aList.remove(tAspect); - } - return true; - } - } - return false; - } - } -}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_AspectList_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_AspectList_Wrapper.java new file mode 100644 index 0000000000..0a7f2d6a3c --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_AspectList_Wrapper.java @@ -0,0 +1,40 @@ +package gtPlusPlus.xmod.thaumcraft.aspect; + +import net.minecraft.item.ItemStack; + +public class TC_AspectList_Wrapper { + + + //thaumcraft.api.aspects.Aspect; + //thaumcraft.api.aspects.AspectList; + + public TC_AspectList_Wrapper() { + + } + + public TC_AspectList_Wrapper(ItemStack stack) { + + } + + public TC_AspectList_Wrapper(Object invoke) { + // TODO Auto-generated constructor stub + } + + public int size() { + // TODO Auto-generated method stub + return 0; + } + + public Object getVanillaAspectList() { + // TODO Auto-generated method stub + return null; + } + + public void add(TC_Aspect_Wrapper mAspect, int mAmount) { + // TODO Auto-generated method stub + + } + + + +} diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_Aspect.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_Aspect_Wrapper.java index 5b84733dd1..78c2a670bb 100644 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_Aspect.java +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_Aspect_Wrapper.java @@ -7,6 +7,7 @@ import java.lang.reflect.Method; import java.util.LinkedHashMap; import java.util.Map; +import gregtech.api.enums.TC_Aspects; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.reflect.ReflectionUtils; @@ -18,19 +19,24 @@ import net.minecraft.util.ResourceLocation; * @author Alkalus * */ -public class TC_Aspect { +public class TC_Aspect_Wrapper { private static Class mClass_Aspect; private static Field mField_Aspects; private final String tag; - private final TC_Aspect[] components; + private final TC_Aspect_Wrapper[] components; private final int color; private String chatcolor; private final ResourceLocation image; private final int blend; - private final Object mAspect; + public final Object mAspect; + + /** + * May be null, but links back to the TC_Aspects class from GT for convinience. + */ + public final TC_Aspects mGtEnumField; @@ -82,8 +88,8 @@ public class TC_Aspect { * @param chatcolor * @param blend */ - public TC_Aspect(String tag, int color, String chatcolor, int blend) { - this(tag, color, (TC_Aspect[]) null, blend); + public TC_Aspect_Wrapper(String tag, int color, String chatcolor, int blend) { + this(tag, color, (TC_Aspect_Wrapper[]) null, blend); this.chatcolor = chatcolor; } @@ -94,7 +100,7 @@ public class TC_Aspect { * @param color * @param components */ - public TC_Aspect(String tag, int color, TC_Aspect[] components) { + public TC_Aspect_Wrapper(String tag, int color, TC_Aspect_Wrapper[] components) { this(tag, color, components, false, 1); } @@ -106,7 +112,7 @@ public class TC_Aspect { * @param components * @param blend */ - public TC_Aspect(String tag, int color, TC_Aspect[] components, int blend) { + public TC_Aspect_Wrapper(String tag, int color, TC_Aspect_Wrapper[] components, int blend) { this(tag, color, components, false, blend); } @@ -120,12 +126,12 @@ public class TC_Aspect { * @param image * @param blend */ - public TC_Aspect(String tag, int color, TC_Aspect[] components, boolean vanilla, int blend) { + public TC_Aspect_Wrapper(String tag, int color, TC_Aspect_Wrapper[] components, boolean vanilla, int blend) { this(tag, color, components, vanilla ? new ResourceLocation("thaumcraft", "textures/aspects/" + tag.toLowerCase() + ".png") : new ResourceLocation(CORE.MODID, "textures/aspects/" + tag.toLowerCase() + ".png"), vanilla, blend); } - public TC_Aspect(String tag, int color, TC_Aspect[] components, ResourceLocation image, boolean vanilla, int blend) { + public TC_Aspect_Wrapper(String tag, int color, TC_Aspect_Wrapper[] components, ResourceLocation image, boolean vanilla, int blend) { if (getAspectList().containsKey(tag.toLowerCase())) { throw new IllegalArgumentException(tag + " already registered!"); } else { @@ -134,7 +140,28 @@ public class TC_Aspect { this.color = color; this.image = image; this.blend = blend; - this.mAspect = vanilla ? getVanillaAspectObject(this.tag) : this.generateTcAspect(); + this.mAspect = vanilla ? getVanillaAspectObject(this.tag) : this.generateTcAspect(); + + //Set GT Type if exists + TC_Aspects y = null; + for (TC_Aspects e : TC_Aspects.values()) { + TC_Aspect_Wrapper g; + try { + g = generate(e.mAspect); + if (g != null) { + if (g.tag.equals(this.tag)) { + y = e; + break; + } + } + } catch (IllegalArgumentException e1) { + e1.printStackTrace(); + } + } + mGtEnumField = y; + + + Logger.INFO("[Thaumcraft++] Adding support for Aspect: "+tag); } } @@ -148,12 +175,21 @@ public class TC_Aspect { * @throws IllegalAccessException */ @SuppressWarnings("unused") - public static TC_Aspect generate(Object aBaseAspect) throws IllegalArgumentException, IllegalAccessException { - String aTag = ((String) ReflectionUtils.getField(mClass_Aspect, "tag").get(aBaseAspect)).toLowerCase(); + public static TC_Aspect_Wrapper generate(Object aBaseAspect) { + try { + Field aTagF = ReflectionUtils.getField(mClass_Aspect, "tag"); + if (aTagF == null) { + return null; + } + String aTafB = (String) aTagF.get(aBaseAspect); + if (aTafB == null) { + return null; + } + String aTag = aTafB.toLowerCase(); if (aTag != null && getAspectList().containsKey(aTag.toLowerCase())) { return getAspect(aTag); } else { - TC_Aspect aTemp = new TC_Aspect( + TC_Aspect_Wrapper aTemp = new TC_Aspect_Wrapper( aTag, (int) ReflectionUtils.getField(mClass_Aspect, "color").get(aBaseAspect), generateAspectArrayInternal(ReflectionUtils.getField(mClass_Aspect, "components"), (aBaseAspect)), @@ -168,52 +204,57 @@ public class TC_Aspect { else { return null; } - } + } + } + catch (Throwable t) { + t.printStackTrace(); + return null; + } } /** * Internal Map containing all the TC_Aspects. */ - private static Map<String, TC_Aspect> mInternalAspectCache = new LinkedHashMap<String, TC_Aspect>(); + private static Map<String, TC_Aspect_Wrapper> mInternalAspectCache = new LinkedHashMap<String, TC_Aspect_Wrapper>(); /** * Public getter for all TC_Aspects * @param aAspectName - Aspect Name * @return - A GT++ Aspect wrapper or null. (TC_Aspect) */ - public static TC_Aspect getAspect(String aAspectName) { + public static TC_Aspect_Wrapper getAspect(String aAspectName) { String aName = aAspectName.toLowerCase(); - TC_Aspect g = mInternalAspectCache.get(aName); + TC_Aspect_Wrapper g = mInternalAspectCache.get(aName); if (g != null) { return g; } else { try { - TC_Aspect aTemp = generate(getVanillaAspectList().get(aName)); + TC_Aspect_Wrapper aTemp = generate(getVanillaAspectList().get(aName)); if (aTemp != null) { mInternalAspectCache.put(aName, aTemp); return aTemp; } - } catch (IllegalArgumentException | IllegalAccessException e) { + } catch (IllegalArgumentException e) { e.printStackTrace(); } } return null; } - public static Map<String, TC_Aspect> getAspectList(){ + public static Map<String, TC_Aspect_Wrapper> getAspectList(){ return mInternalAspectCache; } - private static TC_Aspect[] generateAspectArrayInternal(Field aField, Object aInstance) { + private static TC_Aspect_Wrapper[] generateAspectArrayInternal(Field aField, Object aInstance) { //thaumcraft.api.aspects.Aspect.Aspect() Object[] components; - TC_Aspect[] aAspectArray; + TC_Aspect_Wrapper[] aAspectArray; try { components = (Object[]) aField.get(aInstance); - aAspectArray = new TC_Aspect[components.length]; + aAspectArray = new TC_Aspect_Wrapper[components.length]; if (components.length > 0) { int i = 0; for (Object g : components) { @@ -223,7 +264,7 @@ public class TC_Aspect { } } catch (IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); - aAspectArray = new TC_Aspect[0]; + aAspectArray = new TC_Aspect_Wrapper[0]; } return aAspectArray; } @@ -239,7 +280,7 @@ public class TC_Aspect { if (components.length > 0) { aAspectArray = (Object[]) Array.newInstance(mClass_Aspect, components.length); int i = 0; - for (TC_Aspect g : components) { + for (TC_Aspect_Wrapper g : components) { ((Object[]) aAspectArray)[i++] = g.mAspect; } } diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_PageType_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_PageType_Wrapper.java new file mode 100644 index 0000000000..5a608e290f --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_PageType_Wrapper.java @@ -0,0 +1,17 @@ +package gtPlusPlus.xmod.thaumcraft.aspect; + +public class TC_PageType_Wrapper { + + public static final TC_PageType_Wrapper TEXT = null; + public static final TC_PageType_Wrapper TEXT_CONCEALED = null; + public static final TC_PageType_Wrapper NORMAL_CRAFTING = null; + public static final TC_PageType_Wrapper ARCANE_CRAFTING = null; + public static final TC_PageType_Wrapper CRUCIBLE_CRAFTING = null; + public static final TC_PageType_Wrapper INFUSION_CRAFTING = null; + public static final TC_PageType_Wrapper COMPOUND_CRAFTING = null; + public static final TC_PageType_Wrapper SMELTING = null; + public static final TC_PageType_Wrapper INFUSION_ENCHANTMENT = null; + public static final TC_PageType_Wrapper IMAGE = null; + public static final TC_PageType_Wrapper ASPECTS = null; + +} diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchCategories_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchCategories_Wrapper.java new file mode 100644 index 0000000000..3392dbcff9 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchCategories_Wrapper.java @@ -0,0 +1,89 @@ +package gtPlusPlus.xmod.thaumcraft.aspect; + +import cpw.mods.fml.common.FMLLog; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedHashMap; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; + +import org.apache.logging.log4j.Level; + +public class TC_ResearchCategories_Wrapper { + + public static LinkedHashMap<String, TC_ResearchCategoryList_Wrapper> researchCategories = new LinkedHashMap<String, TC_ResearchCategoryList_Wrapper>(); + + public static TC_ResearchCategoryList_Wrapper getResearchList(String key) { + return (TC_ResearchCategoryList_Wrapper) researchCategories.get(key); + } + + public static String getCategoryName(String key) { + return StatCollector.translateToLocal("tc.research_category." + key); + } + + public static TC_ResearchItem_Wrapper getResearch(String key) { + Collection rc = researchCategories.values(); + Iterator i$ = rc.iterator(); + + while (i$.hasNext()) { + Object cat = i$.next(); + Collection rl = ((TC_ResearchCategoryList_Wrapper) cat).research.values(); + Iterator i$1 = rl.iterator(); + + while (i$1.hasNext()) { + Object ri = i$1.next(); + if (((TC_ResearchItem_Wrapper) ri).key.equals(key)) { + return (TC_ResearchItem_Wrapper) ri; + } + } + } + + return null; + } + + public static void registerCategory(String key, ResourceLocation icon, ResourceLocation background) { + if (getResearchList(key) == null) { + TC_ResearchCategoryList_Wrapper rl = new TC_ResearchCategoryList_Wrapper(icon, background); + researchCategories.put(key, rl); + } + + } + + public static void addResearch(TC_ResearchItem_Wrapper ri) { + TC_ResearchCategoryList_Wrapper rl = getResearchList(ri.category); + if (rl != null && !rl.research.containsKey(ri.key)) { + if (!ri.isVirtual()) { + Iterator i$ = rl.research.values().iterator(); + + while (i$.hasNext()) { + TC_ResearchItem_Wrapper rr = (TC_ResearchItem_Wrapper) i$.next(); + if (rr.displayColumn == ri.displayColumn && rr.displayRow == ri.displayRow) { + FMLLog.log(Level.FATAL, + "[Thaumcraft] Research [" + ri.getName() + + "] not added as it overlaps with existing research [" + rr.getName() + "]", + new Object[0]); + return; + } + } + } + + rl.research.put(ri.key, ri); + if (ri.displayColumn < rl.minDisplayColumn) { + rl.minDisplayColumn = ri.displayColumn; + } + + if (ri.displayRow < rl.minDisplayRow) { + rl.minDisplayRow = ri.displayRow; + } + + if (ri.displayColumn > rl.maxDisplayColumn) { + rl.maxDisplayColumn = ri.displayColumn; + } + + if (ri.displayRow > rl.maxDisplayRow) { + rl.maxDisplayRow = ri.displayRow; + } + } + + } +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchCategoryList_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchCategoryList_Wrapper.java new file mode 100644 index 0000000000..4c9102648a --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchCategoryList_Wrapper.java @@ -0,0 +1,21 @@ +package gtPlusPlus.xmod.thaumcraft.aspect; + +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.util.ResourceLocation; + +public class TC_ResearchCategoryList_Wrapper { + public int minDisplayColumn; + public int minDisplayRow; + public int maxDisplayColumn; + public int maxDisplayRow; + public ResourceLocation icon; + public ResourceLocation background; + public Map<String, TC_ResearchItem_Wrapper> research = new HashMap<String, TC_ResearchItem_Wrapper>(); + + public TC_ResearchCategoryList_Wrapper(ResourceLocation icon, ResourceLocation background) { + this.icon = icon; + this.background = background; + } +} diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchItem_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchItem_Wrapper.java new file mode 100644 index 0000000000..399ec5ad09 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchItem_Wrapper.java @@ -0,0 +1,244 @@ +package gtPlusPlus.xmod.thaumcraft.aspect; + +import gtPlusPlus.xmod.thaumcraft.util.ThaumcraftUtils; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; + +public class TC_ResearchItem_Wrapper { + + public final String key; + public final String category; + public final TC_AspectList_Wrapper tags; + public String[] parents = null; + public String[] parentsHidden = null; + public String[] siblings = null; + public final int displayColumn; + public final int displayRow; + public final ItemStack icon_item; + public final ResourceLocation icon_resource; + private int complexity; + private boolean isSpecial; + private boolean isSecondary; + private boolean isRound; + private boolean isStub; + private boolean isVirtual; + private boolean isConcealed; + private boolean isHidden; + private boolean isLost; + private boolean isAutoUnlock; + private ItemStack[] itemTriggers; + private String[] entityTriggers; + private TC_Aspect_Wrapper[] aspectTriggers; + private Object[] pages = null; + + public TC_ResearchItem_Wrapper(String key, String category) { + this.key = key; + this.category = category; + this.tags = new TC_AspectList_Wrapper(); + this.icon_resource = null; + this.icon_item = null; + this.displayColumn = 0; + this.displayRow = 0; + this.setVirtual(); + } + + public TC_ResearchItem_Wrapper(String key, String category, TC_AspectList_Wrapper tags, int col, int row, int complex, + ResourceLocation icon) { + this.key = key; + this.category = category; + this.tags = tags; + this.icon_resource = icon; + this.icon_item = null; + this.displayColumn = col; + this.displayRow = row; + this.complexity = complex; + if (this.complexity < 1) { + this.complexity = 1; + } + + if (this.complexity > 3) { + this.complexity = 3; + } + + } + + public TC_ResearchItem_Wrapper(String key, String category, TC_AspectList_Wrapper tags, int col, int row, int complex, ItemStack icon) { + this.key = key; + this.category = category; + this.tags = tags; + this.icon_item = icon; + this.icon_resource = null; + this.displayColumn = col; + this.displayRow = row; + this.complexity = complex; + if (this.complexity < 1) { + this.complexity = 1; + } + + if (this.complexity > 3) { + this.complexity = 3; + } + + } + + public TC_ResearchItem_Wrapper setSpecial() { + this.isSpecial = true; + return this; + } + + public TC_ResearchItem_Wrapper setStub() { + this.isStub = true; + return this; + } + + public TC_ResearchItem_Wrapper setLost() { + this.isLost = true; + return this; + } + + public TC_ResearchItem_Wrapper setConcealed() { + this.isConcealed = true; + return this; + } + + public TC_ResearchItem_Wrapper setHidden() { + this.isHidden = true; + return this; + } + + public TC_ResearchItem_Wrapper setVirtual() { + this.isVirtual = true; + return this; + } + + public TC_ResearchItem_Wrapper setParents(String... par) { + this.parents = par; + return this; + } + + public TC_ResearchItem_Wrapper setParentsHidden(String... par) { + this.parentsHidden = par; + return this; + } + + public TC_ResearchItem_Wrapper setSiblings(String... sib) { + this.siblings = sib; + return this; + } + + public TC_ResearchItem_Wrapper setPages(Object... par) { + this.pages = par; + return this; + } + + public Object[] getPages() { + return this.pages; + } + + public TC_ResearchItem_Wrapper setItemTriggers(ItemStack... par) { + this.itemTriggers = par; + return this; + } + + public TC_ResearchItem_Wrapper setEntityTriggers(String... par) { + this.entityTriggers = par; + return this; + } + + public TC_ResearchItem_Wrapper setAspectTriggers(TC_Aspect_Wrapper... par) { + this.aspectTriggers = par; + return this; + } + + public ItemStack[] getItemTriggers() { + return this.itemTriggers; + } + + public String[] getEntityTriggers() { + return this.entityTriggers; + } + + public TC_Aspect_Wrapper[] getAspectTriggers() { + return this.aspectTriggers; + } + + public TC_ResearchItem_Wrapper registerResearchItem() { + ThaumcraftUtils.addResearch(this); + return this; + } + + public String getName() { + return StatCollector.translateToLocal("tc.research_name." + this.key); + } + + public String getText() { + return StatCollector.translateToLocal("tc.research_text." + this.key); + } + + public boolean isSpecial() { + return this.isSpecial; + } + + public boolean isStub() { + return this.isStub; + } + + public boolean isLost() { + return this.isLost; + } + + public boolean isConcealed() { + return this.isConcealed; + } + + public boolean isHidden() { + return this.isHidden; + } + + public boolean isVirtual() { + return this.isVirtual; + } + + public boolean isAutoUnlock() { + return this.isAutoUnlock; + } + + public TC_ResearchItem_Wrapper setAutoUnlock() { + this.isAutoUnlock = true; + return this; + } + + public boolean isRound() { + return this.isRound; + } + + public TC_ResearchItem_Wrapper setRound() { + this.isRound = true; + return this; + } + + public boolean isSecondary() { + return this.isSecondary; + } + + public TC_ResearchItem_Wrapper setSecondary() { + this.isSecondary = true; + return this; + } + + public int getComplexity() { + return this.complexity; + } + + public TC_ResearchItem_Wrapper setComplexity(int complexity) { + this.complexity = complexity; + return this; + } + + public TC_Aspect_Wrapper getResearchPrimaryTag() { + //TODO + return null; + } + +} diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchNoteData_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchNoteData_Wrapper.java new file mode 100644 index 0000000000..64f1ce088a --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchNoteData_Wrapper.java @@ -0,0 +1,10 @@ +package gtPlusPlus.xmod.thaumcraft.aspect; + +public class TC_ResearchNoteData_Wrapper { + + public Object getResearchNoteData() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchPage_Wrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchPage_Wrapper.java new file mode 100644 index 0000000000..256e9c19ed --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/aspect/TC_ResearchPage_Wrapper.java @@ -0,0 +1,222 @@ +package gtPlusPlus.xmod.thaumcraft.aspect; + +import java.util.List; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.FurnaceRecipes; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; + +public class TC_ResearchPage_Wrapper { + public TC_PageType_Wrapper type; + public String text; + public String research; + public ResourceLocation image; + public TC_AspectList_Wrapper aspects; + public Object recipe; + public ItemStack recipeOutput; + + public TC_ResearchPage_Wrapper(String text) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.TEXT; + this.text = text; + } + + public TC_ResearchPage_Wrapper(String research, String text) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.TEXT_CONCEALED; + this.research = research; + this.text = text; + } + + public TC_ResearchPage_Wrapper(IRecipe recipe) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.NORMAL_CRAFTING; + this.recipe = recipe; + this.recipeOutput = recipe.getRecipeOutput(); + } + + public TC_ResearchPage_Wrapper(IRecipe[] recipe) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.NORMAL_CRAFTING; + this.recipe = recipe; + } + + public TC_ResearchPage_Wrapper(IArcaneRecipe[] recipe) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.ARCANE_CRAFTING; + this.recipe = recipe; + } + + public TC_ResearchPage_Wrapper(CrucibleRecipe[] recipe) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.CRUCIBLE_CRAFTING; + this.recipe = recipe; + } + + public TC_ResearchPage_Wrapper(InfusionRecipe[] recipe) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.INFUSION_CRAFTING; + this.recipe = recipe; + } + + public TC_ResearchPage_Wrapper(List recipe) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.COMPOUND_CRAFTING; + this.recipe = recipe; + } + + public TC_ResearchPage_Wrapper(IArcaneRecipe recipe) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.ARCANE_CRAFTING; + this.recipe = recipe; + this.recipeOutput = recipe.getRecipeOutput(); + } + + public TC_ResearchPage_Wrapper(CrucibleRecipe recipe) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.CRUCIBLE_CRAFTING; + this.recipe = recipe; + this.recipeOutput = recipe.getRecipeOutput(); + } + + public TC_ResearchPage_Wrapper(ItemStack input) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.SMELTING; + this.recipe = input; + this.recipeOutput = FurnaceRecipes.smelting().getSmeltingResult(input); + } + + public TC_ResearchPage_Wrapper(InfusionRecipe recipe) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.INFUSION_CRAFTING; + this.recipe = recipe; + if (recipe.getRecipeOutput() instanceof ItemStack) { + this.recipeOutput = (ItemStack) recipe.getRecipeOutput(); + } else { + this.recipeOutput = recipe.getRecipeInput(); + } + + } + + public TC_ResearchPage_Wrapper(InfusionEnchantmentRecipe recipe) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.INFUSION_ENCHANTMENT; + this.recipe = recipe; + } + + public TC_ResearchPage_Wrapper(ResourceLocation image, String caption) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.IMAGE; + this.image = image; + this.text = caption; + } + + public TC_ResearchPage_Wrapper(TC_AspectList_Wrapper as) { + this.type = TC_PageType_Wrapper.TEXT; + this.text = null; + this.research = null; + this.image = null; + this.aspects = null; + this.recipe = null; + this.recipeOutput = null; + this.type = TC_PageType_Wrapper.ASPECTS; + this.aspects = as; + } + + public String getTranslatedText() { + String ret = ""; + if (this.text != null) { + ret = StatCollector.translateToLocal(this.text); + if (ret.isEmpty()) { + ret = this.text; + } + } + + return ret; + } +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/objects/ResearchNoteDataWrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/objects/ResearchNoteDataWrapper.java deleted file mode 100644 index 7ca5c117f0..0000000000 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/objects/ResearchNoteDataWrapper.java +++ /dev/null @@ -1,25 +0,0 @@ -package gtPlusPlus.xmod.thaumcraft.objects; - -import thaumcraft.common.lib.research.ResearchNoteData; - -public class ResearchNoteDataWrapper extends ResearchNoteData { - - public ResearchNoteDataWrapper() { - super(); - } - - public ResearchNoteDataWrapper(ResearchNoteData data) { - key = data.key; - color = data.color; - hexEntries = data.hexEntries; - hexes = data.hexes; - complete = data.complete; - copies = data.copies; - } - - public void completeResearch() { - this.complete = true; - } - - -} diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/util/ThaumcraftUtils.java b/src/Java/gtPlusPlus/xmod/thaumcraft/util/ThaumcraftUtils.java index 2f5400e5f2..6e275e9b67 100644 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/util/ThaumcraftUtils.java +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/util/ThaumcraftUtils.java @@ -1,8 +1,10 @@ package gtPlusPlus.xmod.thaumcraft.util; import static gtPlusPlus.xmod.thaumcraft.HANDLER_Thaumcraft.sItemsToGetAspects; -import static gtPlusPlus.xmod.thaumcraft.aspect.GTPP_AspectCompat.getAspectList_Ex; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.*; import net.minecraft.block.Block; @@ -11,53 +13,50 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.world.World; - import gregtech.api.GregTech_API; import gregtech.api.enums.ConfigCategories; -import gregtech.api.enums.TC_Aspects.TC_AspectStack; +import gregtech.api.enums.TC_Aspects; import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_Utility; import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.api.objects.data.Pair; import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.thaumcraft.HANDLER_Thaumcraft; -import gtPlusPlus.xmod.thaumcraft.aspect.GTPP_Aspects; -import gtPlusPlus.xmod.thaumcraft.aspect.GTPP_Aspects.TC_AspectStack_Ex; -import gtPlusPlus.xmod.thaumcraft.objects.ResearchNoteDataWrapper; -import thaumcraft.api.ThaumcraftApi; -import thaumcraft.api.ThaumcraftApiHelper; -import thaumcraft.api.aspects.Aspect; -import thaumcraft.api.aspects.AspectList; -import thaumcraft.api.crafting.*; -import thaumcraft.api.research.*; -import thaumcraft.common.lib.research.ResearchManager; -import thaumcraft.common.lib.research.ResearchNoteData; -import thaumcraft.common.lib.utils.HexUtils; +import gtPlusPlus.xmod.thaumcraft.aspect.GTPP_AspectStack; +import gtPlusPlus.xmod.thaumcraft.aspect.TC_Aspect_Wrapper; +import gtPlusPlus.xmod.thaumcraft.aspect.TC_AspectList_Wrapper; +import gtPlusPlus.xmod.thaumcraft.aspect.TC_ResearchCategories_Wrapper; +import gtPlusPlus.xmod.thaumcraft.aspect.TC_ResearchCategoryList_Wrapper; +import gtPlusPlus.xmod.thaumcraft.aspect.TC_ResearchItem_Wrapper; +import gtPlusPlus.xmod.thaumcraft.aspect.TC_ResearchNoteData_Wrapper; +import gtPlusPlus.xmod.thaumcraft.aspect.TC_ResearchPage_Wrapper; public class ThaumcraftUtils { - public static boolean addAspectToItem(ItemStack item, Aspect aspect, int amount) { - return addAspectToItem(item, getEnumAspect(aspect.getName()), amount); - } + + private static Class mClass_Aspect; + private static Field mField_Aspects; /*public static boolean addAspectToItem(ItemStack item, Aspect[] aspects, int amount) { return addAspectToItem(item, getEnumAspect(aspect.getName()), amount); }*/ - public static boolean addAspectToItem(ItemStack item, GTPP_Aspects aspect, int amount) { - return addAspectToItem(item, new GTPP_Aspects[] {aspect}, new Integer[] {amount}); + public static boolean addAspectToItem(ItemStack item, TC_Aspect_Wrapper aspect, int amount) { + return addAspectToItem(item, new TC_Aspect_Wrapper[] {aspect}, new Integer[] {amount}); } - public static boolean addAspectToItem(ItemStack item, GTPP_Aspects[] aspect, Integer[] amounts) { - TC_AspectStack_Ex[] aspects = new TC_AspectStack_Ex[aspect.length]; + public static boolean addAspectToItem(ItemStack item, TC_Aspect_Wrapper[] aspect, Integer[] amounts) { + GTPP_AspectStack[] aspects = new GTPP_AspectStack[aspect.length]; for (int g=0;g<aspect.length;g++) { if (amounts[g] != null && amounts[g] > 0) { - aspects[g] = new TC_AspectStack_Ex(aspect[g], amounts[g]); + //aspects[g] = new GTPP_AspectStack(aspect[g], amounts[g]); } } - Pair<ItemStack, TC_AspectStack_Ex[]> k = new Pair<ItemStack, TC_AspectStack_Ex[]>(item, aspects); + Pair<ItemStack, GTPP_AspectStack[]> k = new Pair<ItemStack, GTPP_AspectStack[]>(item, aspects); int mSizeA = sItemsToGetAspects.size(); sItemsToGetAspects.put(k); if (sItemsToGetAspects.size() > mSizeA) { @@ -70,59 +69,51 @@ public class ThaumcraftUtils { } - public static Aspect getAspect(String name) { - GTPP_Aspects r = getAspectEnum(name); - return (r == null ? null : r.mAspect); + public static TC_Aspect_Wrapper getAspect(String name) { + return TC_Aspect_Wrapper.getAspect(name); } - public static GTPP_Aspects getEnumAspect(String name) { - GTPP_Aspects r = getAspectEnum(name); - return (r == null ? null : r); - } - - private static GTPP_Aspects getAspectEnum(String name) { - GTPP_Aspects h = null; - for (GTPP_Aspects f : GTPP_Aspects.values()) { - if (f.mAspect.getName().toLowerCase().contains(name.toLowerCase())) { - h = f; - } - } - return h; + public static TC_Aspects getEnumAspect(String name) { + TC_Aspect_Wrapper r = getAspect(name); + return r.mGtEnumField; } + + - public static Object addResearch(String aResearch, String aName, String aText, String[] aParentResearches, String aCategory, ItemStack aIcon, int aComplexity, int aType, int aX, int aY, List<TC_AspectStack_Ex> aAspects, ItemStack[] aResearchTriggers, Object[] aPages) { + public static Object addResearch(String aResearch, String aName, String aText, String[] aParentResearches, String aCategory, ItemStack aIcon, int aComplexity, int aType, int aX, int aY, List<GTPP_AspectStack> aAspects, ItemStack[] aResearchTriggers, Object[] aPages) { if (!GregTech_API.sRecipeFile.get(ConfigCategories.Recipes.researches, aResearch, true)) { return null; } - ResearchCategoryList tCategory = ResearchCategories.getResearchList(aCategory); + TC_ResearchCategoryList_Wrapper tCategory = TC_ResearchCategories_Wrapper.getResearchList(aCategory); if (tCategory == null) { return null; } - for (Iterator<ResearchItem> i$ = tCategory.research.values().iterator(); i$.hasNext(); ) { - ResearchItem tResearch = (ResearchItem) i$.next(); + for (Iterator<TC_ResearchItem_Wrapper> i$ = tCategory.research.values().iterator(); i$.hasNext(); ) { + TC_ResearchItem_Wrapper tResearch = (TC_ResearchItem_Wrapper) i$.next(); if ((tResearch.displayColumn == aX) && (tResearch.displayRow == aY)) { aX += (aX > 0 ? 5 : -5); aY += (aY > 0 ? 5 : -5); } } - ResearchItem rResearch = new ResearchItem(aResearch, aCategory, getAspectList_Ex(aAspects), aX, aY, aComplexity, aIcon); - ArrayList<ResearchPage> tPages = new ArrayList<ResearchPage>(aPages.length); + TC_ResearchItem_Wrapper rResearch = new TC_ResearchItem_Wrapper(aResearch, aCategory, getAspectList_Ex(aAspects), aX, aY, aComplexity, aIcon); + ArrayList<Object> tPages = new ArrayList<Object>(aPages.length); GT_LanguageManager.addStringLocalization("tc.research_name." + aResearch, aName); GT_LanguageManager.addStringLocalization("tc.research_text." + aResearch, "[GT++] " + aText); for (Object tPage : aPages) { if ((tPage instanceof String)) { - tPages.add(new ResearchPage((String) tPage)); + tPages.add(new TC_ResearchPage_Wrapper((String) tPage)); } else if ((tPage instanceof IRecipe)) { - tPages.add(new ResearchPage((IRecipe) tPage)); - } else if ((tPage instanceof IArcaneRecipe)) { - tPages.add(new ResearchPage((IArcaneRecipe) tPage)); + tPages.add(new TC_ResearchPage_Wrapper((IRecipe) tPage)); + } + /*else if ((tPage instanceof IArcaneRecipe)) { + tPages.add(new TC_ResearchPage_Wrapper((IArcaneRecipe) tPage)); } else if ((tPage instanceof CrucibleRecipe)) { - tPages.add(new ResearchPage((CrucibleRecipe) tPage)); + tPages.add(new TC_ResearchPage_Wrapper((CrucibleRecipe) tPage)); } else if ((tPage instanceof InfusionRecipe)) { - tPages.add(new ResearchPage((InfusionRecipe) tPage)); + tPages.add(new TC_ResearchPage_Wrapper((InfusionRecipe) tPage)); } else if ((tPage instanceof InfusionEnchantmentRecipe)) { - tPages.add(new ResearchPage((InfusionEnchantmentRecipe) tPage)); - } + tPages.add(new TC_ResearchPage_Wrapper((InfusionEnchantmentRecipe) tPage)); + }*/ } if ((aType & 0x40) != 0) { rResearch.setAutoUnlock(); @@ -161,58 +152,58 @@ public class ThaumcraftUtils { rResearch.setItemTriggers(aResearchTriggers); rResearch.setHidden(); } - rResearch.setPages((ResearchPage[]) tPages.toArray(new ResearchPage[tPages.size()])); + rResearch.setPages((TC_ResearchPage_Wrapper[]) tPages.toArray(new TC_ResearchPage_Wrapper[tPages.size()])); return rResearch.registerResearchItem(); } public static Object addCrucibleRecipe(final String aResearch, final Object aInput, final ItemStack aOutput, - final List<TC_AspectStack_Ex> aAspects) { + final List<GTPP_AspectStack> aAspects) { if (GT_Utility.isStringInvalid((Object) aResearch) || aInput == null || aOutput == null || aAspects == null || aAspects.isEmpty()) { return null; } - return ThaumcraftApi.addCrucibleRecipe(aResearch, GT_Utility.copy(new Object[]{aOutput}), + return addCrucibleRecipe(aResearch, GT_Utility.copy(new Object[]{aOutput}), (aInput instanceof ItemStack || aInput instanceof ArrayList) ? aInput : aInput.toString(), getAspectList_Ex(aAspects)); } public static Object addInfusionRecipe(final String aResearch, final ItemStack aMainInput, final ItemStack[] aSideInputs, - final ItemStack aOutput, final int aInstability, final List<TC_AspectStack_Ex> aAspects) { + final ItemStack aOutput, final int aInstability, final List<GTPP_AspectStack> aAspects) { if (GT_Utility.isStringInvalid((Object) aResearch) || aMainInput == null || aSideInputs == null || aOutput == null || aAspects == null || aAspects.isEmpty()) { return null; } - return ThaumcraftApi.addInfusionCraftingRecipe(aResearch, (Object) GT_Utility.copy(new Object[]{aOutput}), + return addInfusionCraftingRecipe(aResearch, (Object) GT_Utility.copy(new Object[]{aOutput}), aInstability, getAspectList_Ex(aAspects), aMainInput, aSideInputs); } public static boolean registerThaumcraftAspectsToItem(final ItemStack aExampleStack, - final List<TC_AspectStack_Ex> aAspects, final String aOreDict) { + final List<GTPP_AspectStack> aAspects, final String aOreDict) { if (aAspects.isEmpty()) { return false; } - ThaumcraftApi.registerObjectTag(aOreDict, getAspectList_Ex(aAspects)); + registerObjectTag(aOreDict, getAspectList_Ex(aAspects)); return true; } public static boolean registerThaumcraftAspectsToItem(final ItemStack aStack, - final List<TC_AspectStack_Ex> aAspects, final boolean aAdditive) { + final List<GTPP_AspectStack> aAspects, final boolean aAdditive) { try { if (aAspects.isEmpty()) { return false; } - AspectList h = getAspectList_Ex(aAspects); + TC_AspectList_Wrapper h = getAspectList_Ex(aAspects); if (aAdditive && (h != null && h.size() > 0)) { - ThaumcraftApi.registerComplexObjectTag(aStack, getAspectList_Ex(aAspects)); + registerComplexObjectTag(aStack, getAspectList_Ex(aAspects)); return true; } else { Logger.MATERIALS("[Aspect] Failed adding aspects to "+aStack.getDisplayName()+"."); } - final AspectList tAlreadyRegisteredAspects = ThaumcraftApiHelper.getObjectAspects(aStack); + final TC_AspectList_Wrapper tAlreadyRegisteredAspects = getObjectAspects(aStack); if (tAlreadyRegisteredAspects == null || tAlreadyRegisteredAspects.size() <= 0) { - ThaumcraftApi.registerObjectTag(aStack, getAspectList_Ex(aAspects)); + registerObjectTag(aStack, getAspectList_Ex(aAspects)); } return true; } @@ -222,44 +213,154 @@ public class ThaumcraftUtils { return false; } } + - public static boolean registerPortholeBlacklistedBlock(final Block aBlock) { - ThaumcraftApi.portableHoleBlackList.add(aBlock); - return true; + private static final Class mClass_ThaumcraftApi; + private static final Class mClass_ThaumcraftApiHelper; + private static final Class mClass_AspectList; + private static final Class mClass_ResearchManager; + private static final Method mMethod_registerObjectTag1; + private static final Method mMethod_registerObjectTag2; + private static final Method mMethod_registerComplexObjectTag; + private static final Method mMethod_addInfusionCraftingRecipe; + private static final Method mMethod_addCrucibleRecipe; + private static final Method mMethod_getObjectAspects; + private static final Method mMethod_updateData; + + private static final Field mField_PortholeBlacklist; + static { + /* + * Classes + */ + mClass_ThaumcraftApi = ReflectionUtils.getClass("thaumcraft.api.ThaumcraftApi"); + mClass_ThaumcraftApiHelper = ReflectionUtils.getClass("thaumcraft.api.ThaumcraftApiHelper"); + mClass_AspectList = ReflectionUtils.getClass("thaumcraft.api.aspects.AspectList"); + mClass_ResearchManager = ReflectionUtils.getClass("thaumcraft.common.lib.research.ResearchManager"); + + /* + * Methods + */ + mMethod_registerObjectTag1 = ReflectionUtils.getMethod(mClass_ThaumcraftApi, "registerObjectTag", + ItemStack.class, mClass_AspectList); + + mMethod_registerObjectTag2 = ReflectionUtils.getMethod(mClass_ThaumcraftApi, "registerObjectTag", String.class, + mClass_AspectList); + + mMethod_registerComplexObjectTag = ReflectionUtils.getMethod(mClass_ThaumcraftApi, "registerComplexObjectTag", + ItemStack.class, mClass_AspectList); + + mMethod_addInfusionCraftingRecipe = ReflectionUtils.getMethod(mClass_ThaumcraftApi, "addInfusionCraftingRecipe", + String.class, Object.class, int.class, mClass_AspectList, ItemStack.class, ItemStack[].class); + + mMethod_addCrucibleRecipe = ReflectionUtils.getMethod(mClass_ThaumcraftApi, "addCrucibleRecipe", String.class, + ItemStack.class, Object.class, mClass_AspectList); + + mMethod_getObjectAspects = ReflectionUtils.getMethod(mClass_ThaumcraftApi, "getObjectAspects", ItemStack.class); + mMethod_updateData = ReflectionUtils.getMethod(mClass_ResearchManager, "updateData", ItemStack.class, ReflectionUtils.getClass("thaumcraft.common.lib.research.ResearchNoteData")); + + /* + * Fields + */ + mField_PortholeBlacklist = ReflectionUtils.getField(mClass_ThaumcraftApi, "portableHoleBlackList"); + + } + + public static void registerObjectTag(ItemStack aStack, TC_AspectList_Wrapper aAspectList) { + try { + mMethod_registerObjectTag1.invoke(null, aStack, aAspectList.getVanillaAspectList()); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + } } - public static TC_AspectStack_Ex convertAspectStack(TC_AspectStack gtType) { - TC_AspectStack_Ex g = null; - if (gtType == null) { - return null; + public static void registerObjectTag(String aOreDict, TC_AspectList_Wrapper aAspectList) { + try { + mMethod_registerObjectTag2.invoke(null, aOreDict, aAspectList.getVanillaAspectList()); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); } - else { - String oldName = gtType.mAspect.name().toLowerCase(); - long oldAmount = gtType.mAmount; - for (GTPP_Aspects r : GTPP_Aspects.values()) { - if (r.mAspect.getName().toLowerCase().contains(oldName)) { - g = new TC_AspectStack_Ex(r, oldAmount); - break; - } - } - } - return g; } + + public static void registerComplexObjectTag(ItemStack aStack, TC_AspectList_Wrapper aAspectList) { + try { + mMethod_registerComplexObjectTag.invoke(null, aStack, aAspectList.getVanillaAspectList()); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + } + } + + + public static TC_AspectList_Wrapper getObjectAspects(ItemStack aStack) { + try { + return new TC_AspectList_Wrapper(mMethod_getObjectAspects.invoke(null, aStack)); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + } + return null; + } + + + + public static Object addCrucibleRecipe(String aResearch, ItemStack copy, Object aOutput, + TC_AspectList_Wrapper aAspectList) { + try { + return mMethod_addCrucibleRecipe.invoke(null, aResearch, copy, aOutput, aAspectList); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + } + return null; + } + + public static Object addInfusionCraftingRecipe(String aResearch, Object copy, int aInstability, + TC_AspectList_Wrapper aAspectList, ItemStack aMainInput, ItemStack[] aSideInputs) { + try { + return mMethod_addInfusionCraftingRecipe.invoke(null, aResearch, copy, aInstability, aAspectList, aMainInput, aSideInputs); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + } + return null; + } + - public static List<TC_AspectStack_Ex> convertAspectStack(List<TC_AspectStack> p5) { - List<TC_AspectStack_Ex> list = new ArrayList<TC_AspectStack_Ex>(); - for (TC_AspectStack h : p5) { - list.add(convertAspectStack(h)); + public static boolean registerPortholeBlacklistedBlock(final Block aBlock) { + try { + ((ArrayList<Block>) mField_PortholeBlacklist.get(null)).add(aBlock); + } catch (IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + return false; } - return list; + return true; } + - public static void updateResearchNote(ItemStack a, ResearchNoteData b) { - updateResearchNote(a, new ResearchNoteDataWrapper(b)); + public static String getTagFromAspectObject(Object aAspect) { + try { + Field aTagF = ReflectionUtils.getField(mClass_Aspect, "tag"); + if (aTagF == null) { + return null; + } + String aTafB = (String) aTagF.get(aAspect); + if (aTafB == null) { + return null; + } + String aTag = aTafB.toLowerCase(); + return aTag; + } catch (IllegalArgumentException | IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return "error"; + } } + - public static void updateResearchNote(ItemStack a, ResearchNoteDataWrapper b) { - ResearchManager.updateData(a, b); + public static void updateResearchNote(ItemStack a, TC_ResearchNoteData_Wrapper b) { + //updateData(a, b.getResearchNoteData()); + try { + mMethod_updateData.invoke(a, b.getResearchNoteData()); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + } + } public static boolean isItemResearchNotes(ItemStack aStack) { @@ -276,16 +377,16 @@ public class ThaumcraftUtils { return false; } - public static ResearchNoteDataWrapper gatherResults(ItemStack note) { - ResearchNoteDataWrapper research = null; + public static TC_ResearchNoteData_Wrapper gatherResults(ItemStack note) { + TC_ResearchNoteData_Wrapper research = null; if (isItemResearchNotes(note)) { - research = new ResearchNoteDataWrapper(ResearchManager.getData(note)); + research = new TC_ResearchNoteData_Wrapper(ResearchManager.getData(note)); } return research; } public static void placeAspectIntoResearchNote(ItemStack note, World aWorld, final int q, final int r, final Aspect aspect) { - ResearchNoteDataWrapper data = gatherResults(note); + TC_ResearchNoteData_Wrapper data = gatherResults(note); String mGTPP = CORE.gameProfile.getName(); EntityPlayer player = CORE.getFakePlayer(aWorld); @@ -325,4 +426,17 @@ public class ThaumcraftUtils { } } } + + public static synchronized final TC_AspectList_Wrapper getAspectList_Ex(final List<GTPP_AspectStack> aAspects) { + final TC_AspectList_Wrapper rAspects = new TC_AspectList_Wrapper(); + for (final GTPP_AspectStack tAspect : aAspects) { + rAspects.add(tAspect.mAspect, tAspect.mAmount); + } + return rAspects; + } + + public static void addResearch(TC_ResearchItem_Wrapper tc_ResearchItem_Wrapper) { + // TODO Auto-generated method stub + + } } |