Search in sources :

Example 1 with NumberNBT

use of net.minecraft.nbt.NumberNBT in project Mekanism by mekanism.

the class CCArgumentWrapper method wrapNBT.

@Nullable
private static Object wrapNBT(@Nullable INBT nbt) {
    if (nbt == null) {
        return null;
    }
    switch(nbt.getId()) {
        case Constants.NBT.TAG_BYTE:
        case Constants.NBT.TAG_SHORT:
        case Constants.NBT.TAG_INT:
        case Constants.NBT.TAG_LONG:
        case Constants.NBT.TAG_FLOAT:
        case Constants.NBT.TAG_DOUBLE:
        case Constants.NBT.TAG_ANY_NUMERIC:
            return ((NumberNBT) nbt).getAsNumber();
        case Constants.NBT.TAG_STRING:
        case // Tag End is highly unlikely to ever be used outside of networking but handle it anyway
        Constants.NBT.TAG_END:
            return nbt.getAsString();
        case Constants.NBT.TAG_BYTE_ARRAY:
        case Constants.NBT.TAG_INT_ARRAY:
        case Constants.NBT.TAG_LONG_ARRAY:
        case Constants.NBT.TAG_LIST:
            CollectionNBT<?> collectionNBT = (CollectionNBT<?>) nbt;
            int size = collectionNBT.size();
            Map<Integer, Object> wrappedCollection = new HashMap<>(size);
            for (int i = 0; i < size; i++) {
                wrappedCollection.put(i, wrapNBT(collectionNBT.get(i)));
            }
            return wrappedCollection;
        case Constants.NBT.TAG_COMPOUND:
            CompoundNBT compound = (CompoundNBT) nbt;
            Map<String, Object> wrappedCompound = new HashMap<>(compound.size());
            for (String key : compound.getAllKeys()) {
                Object value = wrapNBT(compound.get(key));
                if (value != null) {
                    wrappedCompound.put(key, value);
                }
            }
            return wrappedCompound;
    }
    return null;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) HashMap(java.util.HashMap) CollectionNBT(net.minecraft.nbt.CollectionNBT) NumberNBT(net.minecraft.nbt.NumberNBT) Nullable(javax.annotation.Nullable)

Aggregations

HashMap (java.util.HashMap)1 Nullable (javax.annotation.Nullable)1 CollectionNBT (net.minecraft.nbt.CollectionNBT)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1 NumberNBT (net.minecraft.nbt.NumberNBT)1