Search in sources :

Example 1 with UniqueIdentifier

use of cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier in project BluePower by Qmunity.

the class ItemStackDatabase method saveItemStack.

public void saveItemStack(ItemStack stack) {
    new File(saveLocation).mkdirs();
    File targetLocation = new File(saveLocation + stack.getDisplayName() + FILE_EXTENSION);
    NBTTagCompound tag = new NBTTagCompound();
    stack.writeToNBT(tag);
    UniqueIdentifier ui = GameRegistry.findUniqueIdentifierFor(stack.getItem());
    tag.setString("owner", ui.modId);
    tag.setString("name", ui.name);
    try {
        FileOutputStream fos = new FileOutputStream(targetLocation);
        DataOutputStream dos = new DataOutputStream(fos);
        byte[] abyte = CompressedStreamTools.compress(tag);
        dos.writeShort((short) abyte.length);
        dos.write(abyte);
        dos.close();
    } catch (IOException e) {
        BluePower.log.error("IOException when trying to save an ItemStack in the database: " + e);
    }
    cache = null;
}
Also used : UniqueIdentifier(cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier) DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOException(java.io.IOException) File(java.io.File)

Example 2 with UniqueIdentifier

use of cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier in project NewHorizonsCoreMod by GTNewHorizons.

the class ItemInHandInfoCommand method processCommand.

@Override
public void processCommand(ICommandSender pCmdSender, String[] pArgs) {
    try {
        if (!InGame(pCmdSender)) {
            PlayerChatHelper.SendPlain(pCmdSender, "You have to execute this command ingame");
            return;
        }
        EntityPlayer tEp = (EntityPlayer) pCmdSender;
        ItemStack inHand = null;
        if (tEp != null) {
            inHand = tEp.getCurrentEquippedItem();
            if (inHand == null) {
                PlayerChatHelper.SendPlain(pCmdSender, "Pickup an item first");
                return;
            }
        }
        UniqueIdentifier UID = GameRegistry.findUniqueIdentifierFor(inHand.getItem());
        PlayerChatHelper.SendPlain(pCmdSender, "== Item info");
        PlayerChatHelper.SendPlain(pCmdSender, String.format("Unloc.Name:  [%s]", inHand.getUnlocalizedName()));
        PlayerChatHelper.SendPlain(pCmdSender, String.format("ItemName:  [%s]", UID.toString()));
        PlayerChatHelper.SendPlain(pCmdSender, String.format("ItemMeta:  [%s]", inHand.getItemDamage()));
        PlayerChatHelper.SendPlain(pCmdSender, String.format("FluidContainer:  [%s]", getFluidContainerContents(inHand)));
        PlayerChatHelper.SendPlain(pCmdSender, String.format("ClassName:  [%s]", inHand.getItem().getClass().toString()));
        PlayerChatHelper.SendPlain(pCmdSender, String.format("ItemNBT:  [%s]", inHand.stackTagCompound));
    } catch (Exception e) {
        e.printStackTrace();
        PlayerChatHelper.SendError(pCmdSender, "Unknown error occoured");
    }
}
Also used : UniqueIdentifier(cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 3 with UniqueIdentifier

use of cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier in project NewHorizonsCoreMod by GTNewHorizons.

the class CustomToolTips method FindItemToolTip.

public ItemToolTip FindItemToolTip(ItemStack pItem) {
    try {
        Init();
        if (pItem == null)
            return null;
        //String tUnlocName = pItem.getUnlocalizedName();
        UniqueIdentifier UID = GameRegistry.findUniqueIdentifierFor(pItem.getItem());
        String tCompareName = UID.toString();
        if (pItem.getItemDamage() > 0)
            tCompareName = String.format("%s:%d", tCompareName, pItem.getItemDamage());
        for (ItemToolTip itt : mToolTips) {
            //if (itt.getUnlocalizedName().equalsIgnoreCase(tUnlocName)) return itt;
            if (itt.mUnlocalizedName.equalsIgnoreCase(tCompareName))
                return itt;
        }
        return null;
    } catch (Exception e) {
        return null;
    }
}
Also used : UniqueIdentifier(cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier)

Example 4 with UniqueIdentifier

use of cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier in project NewHorizonsCoreMod by GTNewHorizons.

the class HazardousItemsHandler method CheckPlayerTouchesBlock.

/**
   * Check if player actually swims in a fluid
   * 
   * @param pPlayer
   */
private void CheckPlayerTouchesBlock(EntityPlayer pPlayer) {
    if (_mRnd.nextInt(_mExecuteChance) != 0)
        return;
    try {
        int blockX = MathHelper.floor_double(pPlayer.posX);
        int blockY = MathHelper.floor_double(pPlayer.boundingBox.minY);
        int blockZ = MathHelper.floor_double(pPlayer.posZ);
        Block pBlockContact = pPlayer.worldObj.getBlock(blockX, blockY, blockZ);
        Block pBlockUnderFeet = pPlayer.worldObj.getBlock(blockX, blockY - 1, blockZ);
        UniqueIdentifier tUidContact = GameRegistry.findUniqueIdentifierFor(pBlockContact);
        UniqueIdentifier tUidFeet = GameRegistry.findUniqueIdentifierFor(pBlockUnderFeet);
        // Skip air block and null results
        if (tUidContact != null && tUidContact.toString() != "minecraft:air") {
            HazardousFluid hf = _mHazardItemsCollection.FindHazardousFluidExact(tUidContact.toString());
            if (hf != null && hf.getCheckContact())
                DoHIEffects(hf, pPlayer);
        }
        if (tUidFeet != null && tUidFeet.toString() != "minecraft:air") {
            HazardousItem hi = _mHazardItemsCollection.FindHazardousItemExact(tUidFeet.toString());
            if (hi != null && hi.getCheckContact())
                DoHIEffects(hi, pPlayer);
        }
    } catch (Exception e) {
        _mLogger.error("HazardousItemsHandler.CheckPlayerTouchesBlock.error", "Something bad happend while processing the onPlayerTick event");
        e.printStackTrace();
    }
}
Also used : UniqueIdentifier(cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier) HazardousFluid(com.dreammaster.modhazardousitems.HazardousItems.HazardousFluid) HazardousItem(com.dreammaster.modhazardousitems.HazardousItems.HazardousItem) Block(net.minecraft.block.Block)

Example 5 with UniqueIdentifier

use of cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier in project PneumaticCraft by MineMaarten.

the class PneumaticCraftUtils method areStacksEqual.

public static boolean areStacksEqual(ItemStack stack1, ItemStack stack2, boolean checkMeta, boolean checkNBT, boolean checkOreDict, boolean checkModSimilarity) {
    if (stack1 == null && stack2 == null)
        return true;
    if (stack1 == null && stack2 != null || stack1 != null && stack2 == null)
        return false;
    if (checkModSimilarity) {
        UniqueIdentifier id1 = GameRegistry.findUniqueIdentifierFor(stack1.getItem());
        if (id1 == null || id1.modId == null)
            return false;
        String modId1 = id1.modId;
        UniqueIdentifier id2 = GameRegistry.findUniqueIdentifierFor(stack2.getItem());
        if (id2 == null || id2.modId == null)
            return false;
        String modId2 = id2.modId;
        return modId1.equals(modId2);
    }
    if (checkOreDict) {
        return isSameOreDictStack(stack1, stack2);
    }
    if (stack1.getItem() != stack2.getItem())
        return false;
    boolean metaSame = stack1.getItemDamage() == stack2.getItemDamage();
    boolean nbtSame = stack1.hasTagCompound() ? stack1.getTagCompound().equals(stack2.getTagCompound()) : !stack2.hasTagCompound();
    return (!checkMeta || metaSame) && (!checkNBT || nbtSame);
}
Also used : UniqueIdentifier(cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier)

Aggregations

UniqueIdentifier (cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier)6 HazardousFluid (com.dreammaster.modhazardousitems.HazardousItems.HazardousFluid)1 HazardousItem (com.dreammaster.modhazardousitems.HazardousItems.HazardousItem)1 DataOutputStream (java.io.DataOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 Block (net.minecraft.block.Block)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1