diff options
| author | Jakub <53441451+kuba6000@users.noreply.github.com> | 2022-08-29 16:04:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-29 16:04:28 +0200 |
| commit | 7d1f51a8937e0a86486267437d444696e81e8aa0 (patch) | |
| tree | a5b145e7271998f7b4b968a2212ed487e54a92b5 /src/main/java/gtPlusPlus/xmod/thaumcraft/objects | |
| parent | 5267969156d30b4bb5f4cb2279ebb49db6bd40e2 (diff) | |
| download | GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.tar.gz GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.tar.bz2 GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.zip | |
Buildscript + Spotless (#318)
* Convert AES.java to readable class
* Buildscript
* Spotless
Diffstat (limited to 'src/main/java/gtPlusPlus/xmod/thaumcraft/objects')
14 files changed, 1054 insertions, 1076 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/thaumcraft/objects/ThreadAspectScanner.java b/src/main/java/gtPlusPlus/xmod/thaumcraft/objects/ThreadAspectScanner.java index fdcf7b8498..896c68aa3a 100644 --- a/src/main/java/gtPlusPlus/xmod/thaumcraft/objects/ThreadAspectScanner.java +++ b/src/main/java/gtPlusPlus/xmod/thaumcraft/objects/ThreadAspectScanner.java @@ -1,13 +1,5 @@ package gtPlusPlus.xmod.thaumcraft.objects; -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.api.objects.data.Pair; @@ -15,144 +7,150 @@ import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.data.FileUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.xmod.thaumcraft.commands.CommandDumpAspects; +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; public class ThreadAspectScanner extends Thread { - public static boolean mDoWeScan = false; - private static final Map<String, AutoMap<ItemStack>> mAllGameContent = new HashMap<String, AutoMap<ItemStack>>(); - public final File mAspectCacheFile; - - public ThreadAspectScanner() { - mAspectCacheFile = FileUtils.getFile("config/GTplusplus", "AspectInfo", "txt"); - mDoWeScan = true; - } + public static boolean mDoWeScan = false; + private static final Map<String, AutoMap<ItemStack>> mAllGameContent = new HashMap<String, AutoMap<ItemStack>>(); + public final File mAspectCacheFile; - private void tryCacheObject(ItemStack aStack) { - if (aStack == null) { - return; - } - String nameKey; - try { - nameKey = ItemUtils.getUnlocalizedItemName(aStack); - } catch (NullPointerException n) { - try { - nameKey = Utils.sanitizeString(aStack.getDisplayName().toLowerCase()); - } catch (NullPointerException n2) { - try { - nameKey = aStack.getItem().getUnlocalizedName(); - } catch (NullPointerException n3) { - nameKey = "BadItemsGalore"; - } - } - } - AutoMap<ItemStack> m = new AutoMap<ItemStack>(); - if (mAllGameContent.containsKey(nameKey)) { - m = mAllGameContent.get(nameKey); - } - m.put(aStack); - mAllGameContent.put(nameKey, m); - } + public ThreadAspectScanner() { + mAspectCacheFile = FileUtils.getFile("config/GTplusplus", "AspectInfo", "txt"); + mDoWeScan = true; + } - @SuppressWarnings({ "rawtypes" }) - @Override - public void run() { - if (mDoWeScan) { - Iterator iterator; - Logger.INFO("Finding Blocks and Items to scan for Aspect data."); - long mBlocksCounter = 0; - long mItemsCounter = 0; + private void tryCacheObject(ItemStack aStack) { + if (aStack == null) { + return; + } + String nameKey; + try { + nameKey = ItemUtils.getUnlocalizedItemName(aStack); + } catch (NullPointerException n) { + try { + nameKey = Utils.sanitizeString(aStack.getDisplayName().toLowerCase()); + } catch (NullPointerException n2) { + try { + nameKey = aStack.getItem().getUnlocalizedName(); + } catch (NullPointerException n3) { + nameKey = "BadItemsGalore"; + } + } + } + AutoMap<ItemStack> m = new AutoMap<ItemStack>(); + if (mAllGameContent.containsKey(nameKey)) { + m = mAllGameContent.get(nameKey); + } + m.put(aStack); + mAllGameContent.put(nameKey, m); + } - // First, find blocks - iterator = Block.blockRegistry.getKeys().iterator(); - while (iterator.hasNext()) { - String s = (String) iterator.next(); - Block block = (Block) Block.blockRegistry.getObject(s); - if (block != null) { - tryCacheObject(ItemUtils.getSimpleStack(block)); - mBlocksCounter++; - } - } - Logger.INFO("Completed Block Scan. Counted "+mBlocksCounter); + @SuppressWarnings({"rawtypes"}) + @Override + public void run() { + if (mDoWeScan) { + Iterator iterator; + Logger.INFO("Finding Blocks and Items to scan for Aspect data."); + long mBlocksCounter = 0; + long mItemsCounter = 0; - // Second Find items, Skipping things that exist. - iterator = Item.itemRegistry.getKeys().iterator(); - while (iterator.hasNext()) { - String s = (String) iterator.next(); - Item item = (Item) Item.itemRegistry.getObject(s); - if (item != null) { - if (item.getHasSubtypes()) { - List q1 = new ArrayList(); - item.getSubItems(item, item.getCreativeTab(), q1); - if (q1 != null && q1.size() > 0) { - for (int e = 0; e < q1.size(); e++) { - ItemStack check = ItemUtils.simpleMetaStack(item, e, 1); - if (check != null) { - tryCacheObject(check); - mItemsCounter++; - } - } - } else { - tryCacheObject(ItemUtils.getSimpleStack(item)); - mItemsCounter++; - } - } else { - tryCacheObject(ItemUtils.getSimpleStack(item)); - mItemsCounter++; - } - } - } - Logger.INFO("Completed Item Scan. Counted "+mItemsCounter); + // First, find blocks + iterator = Block.blockRegistry.getKeys().iterator(); + while (iterator.hasNext()) { + String s = (String) iterator.next(); + Block block = (Block) Block.blockRegistry.getObject(s); + if (block != null) { + tryCacheObject(ItemUtils.getSimpleStack(block)); + mBlocksCounter++; + } + } + Logger.INFO("Completed Block Scan. Counted " + mBlocksCounter); - Set<String> y = mAllGameContent.keySet(); - Logger.INFO("Beginning iteration of "+y.size()+" itemstacks for aspect information."); + // Second Find items, Skipping things that exist. + iterator = Item.itemRegistry.getKeys().iterator(); + while (iterator.hasNext()) { + String s = (String) iterator.next(); + Item item = (Item) Item.itemRegistry.getObject(s); + if (item != null) { + if (item.getHasSubtypes()) { + List q1 = new ArrayList(); + item.getSubItems(item, item.getCreativeTab(), q1); + if (q1 != null && q1.size() > 0) { + for (int e = 0; e < q1.size(); e++) { + ItemStack check = ItemUtils.simpleMetaStack(item, e, 1); + if (check != null) { + tryCacheObject(check); + mItemsCounter++; + } + } + } else { + tryCacheObject(ItemUtils.getSimpleStack(item)); + mItemsCounter++; + } + } else { + tryCacheObject(ItemUtils.getSimpleStack(item)); + mItemsCounter++; + } + } + } + Logger.INFO("Completed Item Scan. Counted " + mItemsCounter); - for (String key : y) { - //Logger.INFO("Looking for key: "+key); - if (mAllGameContent.containsKey(key)) { - AutoMap<ItemStack> group = mAllGameContent.get(key); - if (group == null || group.size() <= 0) { - continue; - } - for (ItemStack stack : group) { - thaumcraft.api.aspects.AspectList a = thaumcraft.common.lib.crafting.ThaumcraftCraftingManager - .getObjectTags(stack); - if (a == null) { - continue; - } else { - AutoMap<Pair<String, Integer>> aspectPairs = new AutoMap<Pair<String, Integer>>(); - for (thaumcraft.api.aspects.Aspect c : a.getAspectsSortedAmount()) { - if (c != null) { - aspectPairs.put(new Pair<String, Integer>(c.getName(), a.getAmount(c))); - } - } - try { - List<String> mList = new ArrayList<String>(); - mList.add(stack.getDisplayName() + " | Meta: " + stack.getItemDamage() - + " | Unlocal: " + stack.getUnlocalizedName()); - for (Pair<String, Integer> r : aspectPairs) { - if (r != null) { - mList.add(r.getKey() + " x" + r.getValue()); - } - } - mList.add(""); - if (mAspectCacheFile != null && mList.size() >= 3) { - FileUtils.appendListToFile(mAspectCacheFile, mList); - } - } - catch (Throwable t) { - Logger.INFO("Error while iterating one item. "+t); - } - } - } - } - } - Logger.INFO("Completed Aspect Iteration. AspectInfo.txt is now available to process in the GTplusplus configuration folder."); - CommandDumpAspects.mLastScanTime = System.currentTimeMillis(); - } - return; - } + Set<String> y = mAllGameContent.keySet(); + Logger.INFO("Beginning iteration of " + y.size() + " itemstacks for aspect information."); + for (String key : y) { + // Logger.INFO("Looking for key: "+key); + if (mAllGameContent.containsKey(key)) { + AutoMap<ItemStack> group = mAllGameContent.get(key); + if (group == null || group.size() <= 0) { + continue; + } + for (ItemStack stack : group) { + thaumcraft.api.aspects.AspectList a = + thaumcraft.common.lib.crafting.ThaumcraftCraftingManager.getObjectTags(stack); + if (a == null) { + continue; + } else { + AutoMap<Pair<String, Integer>> aspectPairs = new AutoMap<Pair<String, Integer>>(); + for (thaumcraft.api.aspects.Aspect c : a.getAspectsSortedAmount()) { + if (c != null) { + aspectPairs.put(new Pair<String, Integer>(c.getName(), a.getAmount(c))); + } + } + try { + List<String> mList = new ArrayList<String>(); + mList.add(stack.getDisplayName() + " | Meta: " + stack.getItemDamage() + " | Unlocal: " + + stack.getUnlocalizedName()); + for (Pair<String, Integer> r : aspectPairs) { + if (r != null) { + mList.add(r.getKey() + " x" + r.getValue()); + } + } + mList.add(""); + if (mAspectCacheFile != null && mList.size() >= 3) { + FileUtils.appendListToFile(mAspectCacheFile, mList); + } + } catch (Throwable t) { + Logger.INFO("Error while iterating one item. " + t); + } + } + } + } + } + Logger.INFO( + "Completed Aspect Iteration. AspectInfo.txt is now available to process in the GTplusplus configuration folder."); + CommandDumpAspects.mLastScanTime = System.currentTimeMillis(); + } + return; + } } diff --git a/src/main/java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/aspect/TC_AspectList_Wrapper.java b/src/main/java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/aspect/TC_AspectList_Wrapper.java index 9df38ca384..346d0d3c8b 100644 --- a/src/main/java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/aspect/TC_AspectList_Wrapper.java +++ b/src/main/java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/aspect/TC_AspectList_Wrapper.java @@ -4,37 +4,29 @@ import net.minecraft.item.ItemStack; public class TC_AspectList_Wrapper { + // thaumcraft.api.aspects.Aspect; + // thaumcraft.api.aspects.AspectList; - //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 - - } - - - + 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/main/java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/aspect/TC_Aspect_Wrapper.java b/src/main/java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/aspect/TC_Aspect_Wrapper.java index fda0fd27c5..6847fcfe69 100644 --- a/src/main/java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/aspect/TC_Aspect_Wrapper.java +++ b/src/main/java/gtPlusPlus/xmod/thaumcraft/objects/wrapper/aspect/TC_Aspect_Wrapper.java @@ -1,18 +1,17 @@ package gtPlusPlus.xmod.thaumcraft.objects.wrapper.aspect; -import java.lang.reflect.Array; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.LinkedHashMap; -import java.util.Map; - import gregtech.api.enums.TC_Aspects; import gregtech.api.util.GT_LanguageManager; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.thaumcraft.util.ThaumcraftUtils; +import java.lang.reflect.Array; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.LinkedHashMap; +import java.util.Map; import net.minecraft.util.ResourceLocation; /** @@ -23,305 +22,300 @@ import net.minecraft.util.ResourceLocation; */ public class TC_Aspect_Wrapper { - private static Class mClass_Aspect; - private static Field mField_Aspects; - - private final String tag; - private final TC_Aspect_Wrapper[] components; - private final int color; - private String chatcolor; - private final ResourceLocation image; - private final int blend; - - public final Object mAspect; - - /** - * May be null, but links back to the TC_Aspects class from GT for convinience. - */ - public final TC_Aspects mGtEnumField; - - - - - /** - * Statically set the Class objects - */ - static { - mClass_Aspect = ReflectionUtils.getClass("thaumcraft.api.aspects.Aspect"); - } - - /** - * Gets the total aspect list from Thaumcraft, which should contain all other registered aspects. - * @return - A LinkedHashMap(String, Aspect); - */ - public static LinkedHashMap<String, Object> getVanillaAspectList() { - try { - if (mField_Aspects == null) { - mField_Aspects = ReflectionUtils.getField(mClass_Aspect, "aspects"); - } - return (LinkedHashMap<String, Object>) mField_Aspects.get(null); - } catch (IllegalArgumentException | IllegalAccessException e) { - Logger.REFLECTION("Failed configuring TC Aspect compatibility."); - return new LinkedHashMap<String, Object>(); - } - } - - public static Object getVanillaAspectObject(String aAspectName) { - return getVanillaAspectList().get(aAspectName); - } - - - - - - - - - - - - - - - /** - * Vanilla Aspect Constructor - * @param tag - Aspect Name - * @param color - * @param chatcolor - * @param blend - */ - public TC_Aspect_Wrapper(String tag, int color, String chatcolor, int blend, String aTooltip) { - this(tag, color, (TC_Aspect_Wrapper[]) null, blend, aTooltip); - this.chatcolor = chatcolor; - } + private static Class mClass_Aspect; + private static Field mField_Aspects; + + private final String tag; + private final TC_Aspect_Wrapper[] components; + private final int color; + private String chatcolor; + private final ResourceLocation image; + private final int blend; + + public final Object mAspect; + + /** + * May be null, but links back to the TC_Aspects class from GT for convinience. + */ + public final TC_Aspects mGtEnumField; + + /** + * Statically set the Class objects + */ + static { + mClass_Aspect = ReflectionUtils.getClass("thaumcraft.api.aspects.Aspect"); + } + + /** + * Gets the total aspect list from Thaumcraft, which should contain all other registered aspects. + * @return - A LinkedHashMap(String, Aspect); + */ + public static LinkedHashMap<String, Object> getVanillaAspectList() { + try { + if (mField_Aspects == null) { + mField_Aspects = ReflectionUtils.getField(mClass_Aspect, "aspects"); + } + return (LinkedHashMap<String, Object>) mField_Aspects.get(null); + } catch (IllegalArgumentException | IllegalAccessException e) { + Logger.REFLECTION("Failed configuring TC Aspect compatibility."); + return new LinkedHashMap<String, Object>(); + } + } + + public static Object getVanillaAspectObject(String aAspectName) { + return getVanillaAspectList().get(aAspectName); + } + + /** + * Vanilla Aspect Constructor + * @param tag - Aspect Name + * @param color + * @param chatcolor + * @param blend + */ + public TC_Aspect_Wrapper(String tag, int color, String chatcolor, int blend, String aTooltip) { + this(tag, color, (TC_Aspect_Wrapper[]) null, blend, aTooltip); + this.chatcolor = chatcolor; + } + + /** + * + * Vanilla Aspect Constructor + * @param tag - Aspect Name + * @param color + * @param components + */ + public TC_Aspect_Wrapper(String tag, int color, TC_Aspect_Wrapper[] components, String aTooltip) { + this(tag, color, components, false, 1, aTooltip); + } + + /** + * + * Vanilla Aspect Constructor + * @param tag - Aspect Name + * @param color + * @param components + * @param blend + */ + public TC_Aspect_Wrapper(String tag, int color, TC_Aspect_Wrapper[] components, int blend, String aTooltip) { + this(tag, color, components, false, blend, aTooltip); + } + + /** + * + * Vanilla Aspect Constructor + * @param tag - Aspect Name + * @param color + * @param components + * @param image + * @param blend + */ + public TC_Aspect_Wrapper( + String tag, int color, TC_Aspect_Wrapper[] components, boolean vanilla, int blend, String aTooltip) { + this( + tag, + color, + components, + vanilla + ? new ResourceLocation("thaumcraft", "textures/aspects/" + tag.toLowerCase() + ".png") + : new ResourceLocation(CORE.MODID, "textures/aspects/" + tag.toLowerCase() + ".png"), + vanilla, + blend, + aTooltip); + } + + private static int aInternalAspectIDAllocation = 1; + + public TC_Aspect_Wrapper( + String tag, + int color, + TC_Aspect_Wrapper[] components, + ResourceLocation image, + boolean vanilla, + int blend, + String aTooltip) { + if (components == null) { + components = new TC_Aspect_Wrapper[] {}; + } + // String aTag = vanilla ? tag.toLowerCase() : "custom"+(aInternalAspectIDAllocation++); + String aTag = tag.toLowerCase(); + if (getAspectList().containsKey(tag.toLowerCase())) { + this.tag = aTag; + this.components = components; + this.color = color; + this.image = image; + this.blend = blend; + this.mAspect = null; + this.mGtEnumField = null; + } else { + this.tag = aTag; + this.components = components; + this.color = color; + this.image = image; + this.blend = blend; + this.mAspect = vanilla ? getVanillaAspectObject(this.tag) : this.generateTcAspect(); + + // Set GT Type if exists + TC_Aspects y = null; + for (TC_Aspects e : TC_Aspects.values()) { + try { + String gtTag = ThaumcraftUtils.getTagFromAspectObject(e.mAspect); + if (gtTag != null) { + if (gtTag.equals(this.tag)) { + y = e; + break; + } + } + } catch (IllegalArgumentException e1) { + e1.printStackTrace(); + } + } + this.mGtEnumField = y; + mInternalAspectCache.put(this.tag, this); + // Double link custom Aspects, but internalise names using custom# instead + if (!vanilla) { + mInternalAspectCache.put("custom" + (aInternalAspectIDAllocation++), this); + GT_LanguageManager.addStringLocalization("tc.aspect." + aTag, aTooltip); + } + Logger.INFO("[Thaumcraft++] Adding support for Aspect: " + tag); + } + } + + /** + * Generates a TC_Aspect from an object, presummed to be a TC Aspect. + * @param aBaseAspect - The TC Aspect to generate from. + * @return + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + @SuppressWarnings("unused") + 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_Wrapper aTemp = new TC_Aspect_Wrapper( + aTag, + (int) ReflectionUtils.getField(mClass_Aspect, "color").get(aBaseAspect), + generateAspectArrayInternal( + ReflectionUtils.getField(mClass_Aspect, "components"), (aBaseAspect)), + (ResourceLocation) + ReflectionUtils.getField(mClass_Aspect, "image").get(aBaseAspect), + true, + (int) ReflectionUtils.getField(mClass_Aspect, "blend").get(aBaseAspect), + ""); + if (aTemp != null) { + aTemp.chatcolor = (String) + ReflectionUtils.getField(mClass_Aspect, "chatcolor").get(aBaseAspect); + return aTemp; + } else { + return null; + } + } + } catch (Throwable t) { + t.printStackTrace(); + return null; + } + } + + /** + * Internal Map containing all the TC_Aspects. + */ + 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_Wrapper getAspect(String aAspectName) { + String aName = aAspectName.toLowerCase(); + TC_Aspect_Wrapper g = mInternalAspectCache.get(aName); + if (g != null) { + return g; + } else { + try { + TC_Aspect_Wrapper aTemp = generate(getVanillaAspectList().get(aName)); + if (aTemp != null) { + mInternalAspectCache.put(aName, aTemp); + return aTemp; + } + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + } + return null; + } + + public static Map<String, TC_Aspect_Wrapper> getAspectList() { + return mInternalAspectCache; + } - /** - * - * Vanilla Aspect Constructor - * @param tag - Aspect Name - * @param color - * @param components - */ - public TC_Aspect_Wrapper(String tag, int color, TC_Aspect_Wrapper[] components, String aTooltip) { - this(tag, color, components, false, 1, aTooltip); - } + private static TC_Aspect_Wrapper[] generateAspectArrayInternal(Field aField, Object aInstance) { + // thaumcraft.api.aspects.Aspect.Aspect() + Object[] components; + TC_Aspect_Wrapper[] aAspectArray; + try { + components = (Object[]) aField.get(aInstance); + aAspectArray = new TC_Aspect_Wrapper[components == null ? 0 : components.length]; + if (aAspectArray.length > 0) { + int i = 0; + for (Object g : components) { + aAspectArray[i] = getAspect((String) + ReflectionUtils.getField(mClass_Aspect, "tag").get(g)); + i++; + } + } + } catch (IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + aAspectArray = new TC_Aspect_Wrapper[0]; + } + return aAspectArray; + } - /** - * - * Vanilla Aspect Constructor - * @param tag - Aspect Name - * @param color - * @param components - * @param blend - */ - public TC_Aspect_Wrapper(String tag, int color, TC_Aspect_Wrapper[] components, int blend, String aTooltip) { - this(tag, color, components, false, blend, aTooltip); - } - - - /** - * - * Vanilla Aspect Constructor - * @param tag - Aspect Name - * @param color - * @param components - * @param image - * @param blend - */ - public TC_Aspect_Wrapper(String tag, int color, TC_Aspect_Wrapper[] components, boolean vanilla, int blend, String aTooltip) { - this(tag, color, components, vanilla ? new ResourceLocation("thaumcraft", "textures/aspects/" + tag.toLowerCase() + ".png") : new ResourceLocation(CORE.MODID, "textures/aspects/" + tag.toLowerCase() + ".png"), vanilla, blend, aTooltip); - } - - private static int aInternalAspectIDAllocation = 1; + /** + * Tasty code to generate TC Aspects reflectively. + * @return + */ + public Object generateTcAspect() { + try { + // thaumcraft.api.aspects.Aspect.Aspect() + Object aAspectArray = (Object[]) Array.newInstance(mClass_Aspect, 0); + if (components.length > 0) { + aAspectArray = (Object[]) Array.newInstance(mClass_Aspect, components.length); + int i = 0; + for (TC_Aspect_Wrapper g : components) { + if (g != null && g.mAspect != null) ((Object[]) aAspectArray)[i++] = g.mAspect; + } + } + Constructor constructor = mClass_Aspect.getConstructor( + String.class, int.class, aAspectArray.getClass(), ResourceLocation.class, int.class); + Object myObject = constructor.newInstance(tag, color, aAspectArray, image, blend); - public TC_Aspect_Wrapper(String tag, int color, TC_Aspect_Wrapper[] components, ResourceLocation image, boolean vanilla, int blend, String aTooltip) { - if (components == null) { - components = new TC_Aspect_Wrapper[] {}; - } - //String aTag = vanilla ? tag.toLowerCase() : "custom"+(aInternalAspectIDAllocation++); - String aTag = tag.toLowerCase(); - if (getAspectList().containsKey(tag.toLowerCase())) { - this.tag = aTag; - this.components = components; - this.color = color; - this.image = image; - this.blend = blend; - this.mAspect = null; - this.mGtEnumField = null; - } else { - this.tag = aTag; - this.components = components; - this.color = color; - this.image = image; - this.blend = blend; - this.mAspect = vanilla ? getVanillaAspectObject(this.tag) : this.generateTcAspect(); - - // Set GT Type if exists - TC_Aspects y = null; - for (TC_Aspects e : TC_Aspects.values()) { - try { - String gtTag = ThaumcraftUtils.getTagFromAspectObject(e.mAspect); - if (gtTag != null) { - if (gtTag.equals(this.tag)) { - y = e; - break; - } - } - } catch (IllegalArgumentException e1) { - e1.printStackTrace(); - } - } - this.mGtEnumField = y; - mInternalAspectCache.put(this.tag, this); - // Double link custom Aspects, but internalise names using custom# instead - if (!vanilla) { - mInternalAspectCache.put("custom"+(aInternalAspectIDAllocation++), this); - GT_LanguageManager.addStringLocalization("tc.aspect."+aTag, aTooltip); - } - Logger.INFO("[Thaumcraft++] Adding support for Aspect: "+tag); - } - } - - - - /** - * Generates a TC_Aspect from an object, presummed to be a TC Aspect. - * @param aBaseAspect - The TC Aspect to generate from. - * @return - * @throws IllegalArgumentException |
