diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2018-05-25 12:16:57 +1000 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2018-05-25 12:16:57 +1000 |
commit | 2b73e75c4de865c05c5cb48bc9e91b1754a37c0c (patch) | |
tree | 99bb61b1857500a3d313417fd948acc7ce4cedd4 /src/Java/gtPlusPlus/xmod | |
parent | 83a72ed129bafdf25ab87e45521a1a22a3afc23e (diff) | |
download | GT5-Unofficial-2b73e75c4de865c05c5cb48bc9e91b1754a37c0c.tar.gz GT5-Unofficial-2b73e75c4de865c05c5cb48bc9e91b1754a37c0c.tar.bz2 GT5-Unofficial-2b73e75c4de865c05c5cb48bc9e91b1754a37c0c.zip |
+ Added a WeakRef type Automap.
+ Added getClassByName(String) to ReflectionUtils.java.
+ Added lots of handlers to ThaumcraftUtils.java.
$ Improved Fake Player handling to only now be held by weak references. Should prevent worlds staying loaded.
Diffstat (limited to 'src/Java/gtPlusPlus/xmod')
5 files changed, 227 insertions, 207 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/CraftingHelper.java b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/CraftingHelper.java index 4fb2cd1aa4..e06636e168 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/CraftingHelper.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/CraftingHelper.java @@ -32,7 +32,8 @@ public class CraftingHelper{ mPosY = AC.getBaseMetaTileEntity().getYCoord(); mPosZ = AC.getBaseMetaTileEntity().getZCoord(); //Create Fake player to handle crating. - player = FakePlayerFactory.get((WorldServer) world, CORE.gameProfile); + + player = CORE.getFakePlayer(world); //Set storage container inventory = new AC_Helper_Container(player.inventory, world, mPosX, mPosY, mPosZ); mInventoryName = inventory.getMatrix().getInventoryName(); diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityThaumcraftResearcher.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityThaumcraftResearcher.java index 43c3ff7542..0d5d9f2738 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityThaumcraftResearcher.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityThaumcraftResearcher.java @@ -3,8 +3,6 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; - import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -12,23 +10,13 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Utility; -import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.util.Utils; -import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMetaTileEntity; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; public class GregtechMetaTileEntityThaumcraftResearcher extends GregtechMetaTileEntity { - int mCurrentPollution; - int mAveragePollution; - int mAveragePollutionArray[] = new int[10]; - private int mArrayPos = 0; - private int mTickTimer = 0; - private int mSecondTimer = 0; - public GregtechMetaTileEntityThaumcraftResearcher(final int aID, final String aName, final String aNameRegional, final int aTier, final String aDescription, final int aSlotCount) { super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); } @@ -39,7 +27,7 @@ public class GregtechMetaTileEntityThaumcraftResearcher extends GregtechMetaTile @Override public String[] getDescription() { - return new String[] {this.mDescription, "A useful debug machine to create pollution.", CORE.GT_Tooltip}; + return new String[] {this.mDescription, "Generates Thaumcraft research notes, because it's magic.", CORE.GT_Tooltip}; } @Override @@ -117,13 +105,6 @@ public class GregtechMetaTileEntityThaumcraftResearcher extends GregtechMetaTile @Override public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (pollutionMultiplier >= 9){ - pollutionMultiplier = 1; - } - else { - pollutionMultiplier++; - } - PlayerUtils.messagePlayer(aPlayer, "Pollution Mutliplier is now "+pollutionMultiplier+"."); super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); } @@ -182,25 +163,6 @@ public class GregtechMetaTileEntityThaumcraftResearcher extends GregtechMetaTile { return true; } - this.showPollution(aPlayer.getEntityWorld(), aPlayer); - return true; - } - - public int pollutionMultiplier = 1; - - private void showPollution(final World worldIn, final EntityPlayer playerIn){ - if(!PollutionUtils.mPollution()){ - PlayerUtils.messagePlayer(playerIn, "This block is useless, Pollution is disabled."); - } - else { - addPollution(); - PlayerUtils.messagePlayer(playerIn, "This chunk now contains "+getCurrentChunkPollution()+" pollution."); - //PlayerUtils.messagePlayer(playerIn, "Average over last ten minutes: "+getAveragePollutionOverLastTen()+" pollution."); - } - } - - private boolean addPollution(){ - PollutionUtils.addPollution(getBaseMetaTileEntity(), 100000*pollutionMultiplier); return true; } @@ -227,8 +189,7 @@ public class GregtechMetaTileEntityThaumcraftResearcher extends GregtechMetaTile public String[] getInfoData() { return new String[] { this.getLocalName(), - "Current Pollution: "+this.mCurrentPollution, - "Average/10 minutes:"+getAveragePollutionOverLastTen()}; + }; } @Override @@ -318,87 +279,28 @@ public class GregtechMetaTileEntityThaumcraftResearcher extends GregtechMetaTile return false; } - //int mCurrentPollution; - //int mAveragePollution; - //int mAveragePollutionArray[] = new int[10]; - @Override public void saveNBTData(final NBTTagCompound aNBT) { - aNBT.setInteger("mCurrentPollution", this.mCurrentPollution); - aNBT.setInteger("mAveragePollution", this.mAveragePollution); + //aNBT.setInteger("mCurrentPollution", this.mCurrentPollution); + //aNBT.setInteger("mAveragePollution", this.mAveragePollution); } @Override public void loadNBTData(final NBTTagCompound aNBT) { - this.mCurrentPollution = aNBT.getInteger("mCurrentPollution"); - this.mAveragePollution = aNBT.getInteger("mAveragePollution"); + //this.mCurrentPollution = aNBT.getInteger("mCurrentPollution"); + //this.mAveragePollution = aNBT.getInteger("mAveragePollution"); } @Override public void onFirstTick(final IGregTechTileEntity aBaseMetaTileEntity) { - if (this.getBaseMetaTileEntity().isServerSide()) { - if (this.mCurrentPollution == 0) { - this.mCurrentPollution = getCurrentChunkPollution(); - } - if (this.mArrayPos < 0 || this.mArrayPos > 9) { - this.mArrayPos = 0; - } - this.mTickTimer = 0; - } + super.onFirstTick(aBaseMetaTileEntity); } @Override public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - if (this.getBaseMetaTileEntity().isServerSide()) { - //TickTimer - 20 times a second - if (this.mTickTimer >= 0 || this.mTickTimer <= 19){ - this.mTickTimer++; - } - else { - this.mTickTimer = 0; - //Perform pollution update once a second - this.mCurrentPollution = getCurrentChunkPollution(); - this.mSecondTimer++; - } - //Update Pollution array once a minute - if (this.mSecondTimer >= 60){ - Utils.sendServerMessage("Udating Average of pollution array. Using Array slot"+this.mArrayPos); - this.mSecondTimer = 0; - if (this.mArrayPos<this.mAveragePollutionArray.length){ - this.mAveragePollutionArray[this.mArrayPos] = this.mCurrentPollution; - this.mArrayPos++; - } - else if (this.mArrayPos==this.mAveragePollutionArray.length){ - this.mAveragePollutionArray[this.mArrayPos] = this.mCurrentPollution; - this.mArrayPos = 0; - } - } - } - } - - public int getAveragePollutionOverLastTen(){ - int counter = 0; - int total = 0; - - for (int i=0;i<this.mAveragePollutionArray.length;i++){ - if (this.mAveragePollutionArray[i] != 0){ - total += this.mAveragePollutionArray[i]; - counter++; - } - } - int returnValue = 0; - if (total > 0 && counter > 0){ - returnValue = (total/counter); - this.mAveragePollution = returnValue; - } - else { - returnValue = getCurrentChunkPollution(); - } - Logger.INFO("| DEBUG: "+returnValue +" | ArrayPos:"+this.mArrayPos+" | Counter:"+counter+" | Total:"+total+" |"); - return returnValue; + super.onPostTick(aBaseMetaTileEntity, aTick); } }
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/HANDLER_Thaumcraft.java b/src/Java/gtPlusPlus/xmod/thaumcraft/HANDLER_Thaumcraft.java index 77a9054c8f..06ae8a48bb 100644 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/HANDLER_Thaumcraft.java +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/HANDLER_Thaumcraft.java @@ -3,6 +3,8 @@ 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; @@ -13,12 +15,14 @@ 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.util.ThaumcraftUtils; public class HANDLER_Thaumcraft { public static IThaumcraftCompat sThaumcraftCompat; + public static Item mResearchNotes; public static final AutoMap<Pair<ItemStack, TC_AspectStack_Ex[]>> sItemsToGetAspects = new AutoMap<Pair<ItemStack, TC_AspectStack_Ex[]>>(); static { @@ -32,7 +36,13 @@ public class HANDLER_Thaumcraft { public static void init(){ if (LoadedMods.Thaumcraft){ - + try { + mResearchNotes = (Item) ReflectionUtils.getField(Class.forName("thaumcraft.common.config.ConfigItems"), "itemResearchNotes").get(null); + } + catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException + | ClassNotFoundException e) { + mResearchNotes = Items.paper; + } } } diff --git a/src/Java/gtPlusPlus/xmod/thaumcraft/objects/ResearchNoteDataWrapper.java b/src/Java/gtPlusPlus/xmod/thaumcraft/objects/ResearchNoteDataWrapper.java new file mode 100644 index 0000000000..7ca5c117f0 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/objects/ResearchNoteDataWrapper.java @@ -0,0 +1,25 @@ +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 87cad3614b..399604b93b 100644 --- a/src/Java/gtPlusPlus/xmod/thaumcraft/util/ThaumcraftUtils.java +++ b/src/Java/gtPlusPlus/xmod/thaumcraft/util/ThaumcraftUtils.java @@ -6,8 +6,11 @@ import static gtPlusPlus.xmod.thaumcraft.aspect.GTPP_AspectCompat.getAspectList_ import java.util.*; import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +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; @@ -17,30 +20,38 @@ import gregtech.api.util.GT_Utility; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.Pair; +import gtPlusPlus.core.lib.CORE; +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.Thaumcraft; +import thaumcraft.common.items.ItemResearchNotes; +import thaumcraft.common.lib.research.ResearchManager; +import thaumcraft.common.lib.research.ResearchNoteData; +import thaumcraft.common.lib.utils.HexUtils; public class ThaumcraftUtils { public static boolean addAspectToItem(ItemStack item, Aspect aspect, int amount) { return addAspectToItem(item, getEnumAspect(aspect.getName()), amount); } - + /*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, GTPP_Aspects[] aspect, Integer[] amounts) { TC_AspectStack_Ex[] aspects = new TC_AspectStack_Ex[aspect.length]; for (int g=0;g<aspect.length;g++) { @@ -59,18 +70,18 @@ public class ThaumcraftUtils { //Logger.INFO("[Aspect] "); return false; } - - + + public static Aspect getAspect(String name) { GTPP_Aspects r = getAspectEnum(name); return (r == null ? null : r.mAspect); } - + 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()) { @@ -80,82 +91,82 @@ public class ThaumcraftUtils { } return h; } - + 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) { - if (!GregTech_API.sRecipeFile.get(ConfigCategories.Recipes.researches, aResearch, true)) { - return null; - } - ResearchCategoryList tCategory = ResearchCategories.getResearchList(aCategory); - if (tCategory == null) { - return null; - } - for (Iterator<ResearchItem> i$ = tCategory.research.values().iterator(); i$.hasNext(); ) { - ResearchItem tResearch = (ResearchItem) 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); - 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)); - } else if ((tPage instanceof IRecipe)) { - tPages.add(new ResearchPage((IRecipe) tPage)); - } else if ((tPage instanceof IArcaneRecipe)) { - tPages.add(new ResearchPage((IArcaneRecipe) tPage)); - } else if ((tPage instanceof CrucibleRecipe)) { - tPages.add(new ResearchPage((CrucibleRecipe) tPage)); - } else if ((tPage instanceof InfusionRecipe)) { - tPages.add(new ResearchPage((InfusionRecipe) tPage)); - } else if ((tPage instanceof InfusionEnchantmentRecipe)) { - tPages.add(new ResearchPage((InfusionEnchantmentRecipe) tPage)); - } - } - if ((aType & 0x40) != 0) { - rResearch.setAutoUnlock(); - } - if ((aType & 0x1) != 0) { - rResearch.setSecondary(); - } - if ((aType & 0x20) != 0) { - rResearch.setSpecial(); - } - if ((aType & 0x8) != 0) { - rResearch.setVirtual(); - } - if ((aType & 0x4) != 0) { - rResearch.setHidden(); - } - if ((aType & 0x10) != 0) { - rResearch.setRound(); - } - if ((aType & 0x2) != 0) { - rResearch.setStub(); - } - if (aParentResearches != null) { - ArrayList<String> tParentResearches = new ArrayList<String>(); - for (String tParent : aParentResearches) { - if (GregTech_API.sRecipeFile.get(ConfigCategories.Recipes.researches, aResearch, true)) { - tParentResearches.add(tParent); - } - } - if (tParentResearches.size() > 0) { - rResearch.setParents((String[]) tParentResearches.toArray(new String[tParentResearches.size()])); - rResearch.setConcealed(); - } - } - if (aResearchTriggers != null) { - rResearch.setItemTriggers(aResearchTriggers); - rResearch.setHidden(); - } - rResearch.setPages((ResearchPage[]) tPages.toArray(new ResearchPage[tPages.size()])); - return rResearch.registerResearchItem(); -} - + if (!GregTech_API.sRecipeFile.get(ConfigCategories.Recipes.researches, aResearch, true)) { + return null; + } + ResearchCategoryList tCategory = ResearchCategories.getResearchList(aCategory); + if (tCategory == null) { + return null; + } + for (Iterator<ResearchItem> i$ = tCategory.research.values().iterator(); i$.hasNext(); ) { + ResearchItem tResearch = (ResearchItem) 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); + 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)); + } else if ((tPage instanceof IRecipe)) { + tPages.add(new ResearchPage((IRecipe) tPage)); + } else if ((tPage instanceof IArcaneRecipe)) { + tPages.add(new ResearchPage((IArcaneRecipe) tPage)); + } else if ((tPage instanceof CrucibleRecipe)) { + tPages.add(new ResearchPage((CrucibleRecipe) tPage)); + } else if ((tPage instanceof InfusionRecipe)) { + tPages.add(new ResearchPage((InfusionRecipe) tPage)); + } else if ((tPage instanceof InfusionEnchantmentRecipe)) { + tPages.add(new ResearchPage((InfusionEnchantmentRecipe) tPage)); + } + } + if ((aType & 0x40) != 0) { + rResearch.setAutoUnlock(); + } + if ((aType & 0x1) != 0) { + rResearch.setSecondary(); + } + if ((aType & 0x20) != 0) { + rResearch.setSpecial(); + } + if ((aType & 0x8) != 0) { + rResearch.setVirtual(); + } + if ((aType & 0x4) != 0) { + rResearch.setHidden(); + } + if ((aType & 0x10) != 0) { + rResearch.setRound(); + } + if ((aType & 0x2) != 0) { + rResearch.setStub(); + } + if (aParentResearches != null) { + ArrayList<String> tParentResearches = new ArrayList<String>(); + for (String tParent : aParentResearches) { + if (GregTech_API.sRecipeFile.get(ConfigCategories.Recipes.researches, aResearch, true)) { + tParentResearches.add(tParent); + } + } + if (tParentResearches.size() > 0) { + rResearch.setParents((String[]) tParentResearches.toArray(new String[tParentResearches.size()])); + rResearch.setConcealed(); + } + } + if (aResearchTriggers != null) { + rResearch.setItemTriggers(aResearchTriggers); + rResearch.setHidden(); + } + rResearch.setPages((ResearchPage[]) tPages.toArray(new ResearchPage[tPages.size()])); + return rResearch.registerResearchItem(); + } + public static Object addCrucibleRecipe(final String aResearch, final Object aInput, final ItemStack aOutput, final List<TC_AspectStack_Ex> aAspects) { @@ -190,23 +201,23 @@ public class ThaumcraftUtils { public static boolean registerThaumcraftAspectsToItem(final ItemStack aStack, final List<TC_AspectStack_Ex> aAspects, final boolean aAdditive) { try { - if (aAspects.isEmpty()) { - return false; - } - AspectList h = getAspectList_Ex(aAspects); - if (aAdditive && (h != null && h.size() > 0)) { - ThaumcraftApi.registerComplexObjectTag(aStack, getAspectList_Ex(aAspects)); + if (aAspects.isEmpty()) { + return false; + } + AspectList h = getAspectList_Ex(aAspects); + if (aAdditive && (h != null && h.size() > 0)) { + ThaumcraftApi.registerComplexObjectTag(aStack, getAspectList_Ex(aAspects)); + return true; + } + else { + Logger.MATERIALS("[Aspect] Failed adding aspects to "+aStack.getDisplayName()+"."); + } + final AspectList tAlreadyRegisteredAspects = ThaumcraftApiHelper.getObjectAspects(aStack); + if (tAlreadyRegisteredAspects == null || tAlreadyRegisteredAspects.size() <= 0) { + ThaumcraftApi.registerObjectTag(aStack, getAspectList_Ex(aAspects)); + } return true; } - else { - Logger.MATERIALS("[Aspect] Failed adding aspects to "+aStack.getDisplayName()+"."); - } - final AspectList tAlreadyRegisteredAspects = ThaumcraftApiHelper.getObjectAspects(aStack); - if (tAlreadyRegisteredAspects == null || tAlreadyRegisteredAspects.size() <= 0) { - ThaumcraftApi.registerObjectTag(aStack, getAspectList_Ex(aAspects)); - } - return true; - } catch (Throwable t) { Logger.MATERIALS("[Aspect] Failed adding aspects to "+aStack.getDisplayName()+"."); t.printStackTrace(); @@ -218,7 +229,7 @@ public class ThaumcraftUtils { ThaumcraftApi.portableHoleBlackList.add(aBlock); return true; } - + public static TC_AspectStack_Ex convertAspectStack(TC_AspectStack gtType) { TC_AspectStack_Ex g = null; if (gtType == null) { @@ -245,4 +256,75 @@ public class ThaumcraftUtils { return list; } + public static void updateResearchNote(ItemStack a, ResearchNoteData b) { + updateResearchNote(a, new ResearchNoteDataWrapper(b)); + } + + public static void updateResearchNote(ItemStack a, ResearchNoteDataWrapper b) { + ResearchManager.updateData(a, b); + } + + public static boolean isItemResearchNotes(ItemStack aStack) { + if (aStack != null && aStack.getItem() == HANDLER_Thaumcraft.mResearchNotes && HANDLER_Thaumcraft.mResearchNotes.getClass().isInstance(aStack.getItem())) { + return true; + } + return false; + } + + public static boolean isItemStackValidResearchNotes(ItemStack aStack) { + if (isItemResearchNotes(aStack) && aStack.getItemDamage() < 64) { + return true; + } + return false; + } + + public static ResearchNoteDataWrapper gatherResults(ItemStack note) { + ResearchNoteDataWrapper research = null; + if (isItemResearchNotes(note)) { + research = new ResearchNoteDataWrapper(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); + String mGTPP = CORE.gameProfile.getName(); + EntityPlayer player = CORE.getFakePlayer(aWorld); + + if (isItemResearchNotes(note) && data != null && note.getItemDamage() < 64) { + final boolean r2 = ResearchManager.isResearchComplete(mGTPP, "RESEARCHER1"); + final boolean r3 = ResearchManager.isResearchComplete(mGTPP, "RESEARCHER2"); + final HexUtils.Hex hex = new HexUtils.Hex(q, r); + ResearchManager.HexEntry he = null; + if (aspect != null) { + he = new ResearchManager.HexEntry(aspect, 2); + if (r3 && aWorld.rand.nextFloat() < 0.1f) { + aWorld.playSoundAtEntity((Entity) player, "random.orb", 0.2f, 0.9f + player.worldObj.rand.nextFloat() * 0.2f); + } + } else { + final float f = aWorld.rand.nextFloat(); + if (data.hexEntries.get(hex.toString()).aspect != null + && ((r2 && f < 0.25f) || (r3 && f < 0.5f))) { + aWorld.playSoundAtEntity((Entity) player, "random.orb", 0.2f, + 0.9f + player.worldObj.rand.nextFloat() * 0.2f); + ResearchManager.scheduleSave(player); + } + he = new ResearchManager.HexEntry((Aspect) null, 0); + } + data.hexEntries.put(hex.toString(), he); + data.hexes.put(hex.toString(), hex); + updateResearchNote(note, data); + if (!aWorld.isRemote && ResearchManager.checkResearchCompletion(note, data, player.getCommandSenderName())) { + note.setItemDamage(64); + } + } + } + + public static void completeResearchNote(World aWorld, ItemStack aStack) { + if (!aWorld.isRemote) { + if (isItemResearchNotes(aStack)) { + aStack.setItemDamage(64); + } + } + } } |