Search in sources :

Example 1 with FinalNBTTagCompound

use of logisticspipes.utils.FinalNBTTagCompound in project LogisticsPipes by RS485.

the class ItemIdentifier method getOrCreateTag.

private static ItemIdentifier getOrCreateTag(Item item, int damage, FinalNBTTagCompound tag) {
    ItemKey k = new ItemKey(item, damage, tag);
    ItemIdentifier.keyRefRlock.lock();
    IDReference r = ItemIdentifier.keyRefMap.get(k);
    if (r != null) {
        ItemIdentifier ret = r.get();
        if (ret != null) {
            ItemIdentifier.keyRefRlock.unlock();
            return ret;
        }
    }
    ItemIdentifier.keyRefRlock.unlock();
    ItemIdentifier.keyRefWlock.lock();
    r = ItemIdentifier.keyRefMap.get(k);
    if (r != null) {
        ItemIdentifier ret = r.get();
        if (ret != null) {
            ItemIdentifier.keyRefWlock.unlock();
            return ret;
        }
    }
    if (ItemIdentifier.tagIDsets.get(item) == null) {
        ItemIdentifier.tagIDsets.put(item, new BitSet(16));
    }
    int nextUniqueID;
    if (r == null) {
        nextUniqueID = ItemIdentifier.tagIDsets.get(item).nextClearBit(1);
        ItemIdentifier.tagIDsets.get(item).set(nextUniqueID);
    } else {
        nextUniqueID = r.uniqueID;
    }
    FinalNBTTagCompound finaltag = new FinalNBTTagCompound((NBTTagCompound) tag.copy());
    ItemKey realKey = new ItemKey(item, damage, finaltag);
    ItemIdentifier ret = new ItemIdentifier(item, damage, finaltag, nextUniqueID);
    ItemIdentifier.keyRefMap.put(realKey, new IDReference(realKey, nextUniqueID, ret));
    ItemIdentifier.keyRefWlock.unlock();
    return ret;
}
Also used : FinalNBTTagCompound(logisticspipes.utils.FinalNBTTagCompound) BitSet(java.util.BitSet)

Aggregations

BitSet (java.util.BitSet)1 FinalNBTTagCompound (logisticspipes.utils.FinalNBTTagCompound)1