diff options
author | Draknyte1 <Draknyte1@hotmail.com> | 2016-06-18 16:55:58 +1000 |
---|---|---|
committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-06-18 16:55:58 +1000 |
commit | 2615992e7d0d4ed3ac205800be71c831029b2dc5 (patch) | |
tree | 7e98798c2fe5f06a4c2d721740ce35247995847d /src/Java/miscutil/core/util/item | |
parent | 5054f6c994018913ef19b094a28636dd7b82a58c (diff) | |
download | GT5-Unofficial-2615992e7d0d4ed3ac205800be71c831029b2dc5.tar.gz GT5-Unofficial-2615992e7d0d4ed3ac205800be71c831029b2dc5.tar.bz2 GT5-Unofficial-2615992e7d0d4ed3ac205800be71c831029b2dc5.zip |
~More Refactoring
Does it ever end?
Diffstat (limited to 'src/Java/miscutil/core/util/item')
-rw-r--r-- | src/Java/miscutil/core/util/item/UtilsItems.java | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/src/Java/miscutil/core/util/item/UtilsItems.java b/src/Java/miscutil/core/util/item/UtilsItems.java new file mode 100644 index 0000000000..590b0167be --- /dev/null +++ b/src/Java/miscutil/core/util/item/UtilsItems.java @@ -0,0 +1,179 @@ +package miscutil.core.util.item; + +import gregtech.api.util.GT_OreDictUnificator; +import miscutil.core.lib.LoadedMods; +import miscutil.core.util.Utils; +import miscutil.core.util.wrapper.var; +import net.minecraft.client.Minecraft; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import cpw.mods.fml.common.registry.GameRegistry; + +public class UtilsItems { + + public static ItemStack getItemStackOfItem(Boolean modToCheck, String mod_itemname_meta){ + if (modToCheck){ + try{ + Item em = null; + + Item em1 = getItem(mod_itemname_meta); + Utils.LOG_WARNING("Found: "+em1.toString()); + if (em1 != null){ + em = em1; + } + if (em != null ){ + ItemStack returnStack = new ItemStack(em,1); + return returnStack; + } + Utils.LOG_WARNING(mod_itemname_meta+" not found."); + return null; + } catch (NullPointerException e) { + Utils.LOG_ERROR(mod_itemname_meta+" not found. [NULL]"); + return null; + } + } + return null; + } + + public static ItemStack getSimpleStack(Item x){ + try { + ItemStack r = new ItemStack(x, 1); + return r; + } catch(Throwable e){ + return null; + } + } + + + public static void getItemForOreDict(String FQRN, String oreDictName, String itemName, int meta){ + try { + Item em = null; + Item em1 = getItem(FQRN); + Utils.LOG_WARNING("Found: "+em1.getUnlocalizedName()+":"+meta); + if (em1 != null){ + em = em1; + } + if (em != null){ + + ItemStack metaStack = new ItemStack(em,1,meta); + GT_OreDictUnificator.registerOre(oreDictName, metaStack); + + /*ItemStack itemStackWithMeta = new ItemStack(em,1,meta); + GT_OreDictUnificator.registerOre(oreDictName, new ItemStack(itemStackWithMeta.getItem()));*/ + } + } catch (NullPointerException e) { + Utils.LOG_ERROR(itemName+" not found. [NULL]"); + } + } + + @SuppressWarnings("unused") + public static ItemStack getItemStackWithMeta(boolean MOD, String FQRN, String itemName, int meta, int itemstackSize){ + if (MOD){ + try { + Item em = null; + Item em1 = getItem(FQRN); + Utils.LOG_WARNING("Found: "+em1.getUnlocalizedName()+":"+meta); + if (em1 != null){ + if (null == em){ + em = em1; + } + if (em != null){ + ItemStack metaStack = new ItemStack(em,itemstackSize,meta); + return metaStack; + } + } + return null; + } catch (NullPointerException e) { + Utils.LOG_ERROR(itemName+" not found. [NULL]"); + return null; + } + } + return null; + } + + @SuppressWarnings("unused") + public static ItemStack simpleMetaStack(String FQRN, int meta, int itemstackSize){ + try { + Item em = null; + Item em1 = getItem(FQRN); + Utils.LOG_WARNING("Found: "+em1.getUnlocalizedName()+":"+meta); + if (em1 != null){ + if (null == em){ + em = em1; + } + if (em != null){ + ItemStack metaStack = new ItemStack(em,itemstackSize,meta); + return metaStack; + } + } + return null; + } catch (NullPointerException e) { + Utils.LOG_ERROR(FQRN+" not found. [NULL]"); + return null; + } + } + + public static ItemStack getCorrectStacktype(String fqrn, int stackSize){ + String oreDict = "ore:"; + ItemStack temp; + if (fqrn.toLowerCase().contains(oreDict.toLowerCase())){ + String sanitizedName = fqrn.replace(oreDict, ""); + temp = UtilsItems.getItemStack(sanitizedName, stackSize); + return temp; + } + String[] fqrnSplit = fqrn.split(":"); + if(fqrnSplit[2] == null){fqrnSplit[2] = "0";} + temp = UtilsItems.getItemStackWithMeta(LoadedMods.MiscUtils, fqrn, fqrnSplit[1], Integer.parseInt(fqrnSplit[2]), stackSize); + return temp; + } + + public static ItemStack getCorrectStacktype(Object item_Input, int stackSize) { + if (item_Input instanceof String){ + return getCorrectStacktype(item_Input, stackSize); + } + else if (item_Input instanceof ItemStack){ + return (ItemStack) item_Input; + } + if (item_Input instanceof var){ + return ((var) item_Input).getStack(stackSize); + } + return null; + } + + public static Item getItem(String fqrn) // fqrn = fully qualified resource name + { + String[] fqrnSplit = fqrn.split(":"); + return GameRegistry.findItem(fqrnSplit[0], fqrnSplit[1]); + } + + public static ItemStack getItemStack(String fqrn, int Size) // fqrn = fully qualified resource name + { + String[] fqrnSplit = fqrn.split(":"); + return GameRegistry.findItemStack(fqrnSplit[0], fqrnSplit[1], Size); + } + + // TODO + /*public static FluidStack getFluidStack(Materials m, int Size) // fqrn = fully qualified resource name + { + String[] fqrnSplit = fqrn.split(":"); + + FluidStack x = (FluidStack) "Materials."+m+".getFluid"(Size); + + return GameRegistry.findItemStack(fqrnSplit[0], fqrnSplit[1], Size); + }*/ + + public static Item getItemInPlayersHand(){ + Minecraft mc = Minecraft.getMinecraft(); + Item heldItem = null; + + try{heldItem = mc.thePlayer.getHeldItem().getItem(); + }catch(NullPointerException e){return null;} + + if (heldItem != null){ + return heldItem; + } + + return null; + } + +} |