Search in sources :

Example 1 with FloatNBT

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

the class CCArgumentWrapperPropertyTest method checkSameFloat.

// ===================
// Floats
// ===================
private boolean checkSameFloat(float value, @Nullable Class<? extends INBT> targetClass) {
    FloatNBT nbt = FloatNBT.valueOf(value);
    Object sanitized = CCArgumentWrapperTestHelper.wrapAndSanitize(nbt, targetClass, false);
    if (value == Math.floor(value) && value >= Long.MIN_VALUE && value <= Long.MAX_VALUE) {
        // If we are an integer float check the proper type
        if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
            return LongNBT.valueOf((long) value).equals(sanitized);
        } else if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
            return IntNBT.valueOf((int) value).equals(sanitized);
        } else if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
            return ShortNBT.valueOf((short) value).equals(sanitized);
        }
        return ByteNBT.valueOf((byte) value).equals(sanitized);
    }
    return nbt.equals(sanitized);
}
Also used : FloatNBT(net.minecraft.nbt.FloatNBT)

Example 2 with FloatNBT

use of net.minecraft.nbt.FloatNBT in project dynmap by webbukkit.

the class ForgeMapChunkCache method getNBTValue.

private Object getNBTValue(INBT v) {
    Object val = null;
    switch(v.getId()) {
        case // Byte
        1:
            val = Byte.valueOf(((ByteNBT) v).getByte());
            break;
        case // Short
        2:
            val = Short.valueOf(((ShortNBT) v).getShort());
            break;
        case // Int
        3:
            val = Integer.valueOf(((IntNBT) v).getInt());
            break;
        case // Long
        4:
            val = Long.valueOf(((LongNBT) v).getLong());
            break;
        case // Float
        5:
            val = Float.valueOf(((FloatNBT) v).getFloat());
            break;
        case // Double
        6:
            val = Double.valueOf(((DoubleNBT) v).getDouble());
            break;
        case // Byte[]
        7:
            val = ((ByteArrayNBT) v).getByteArray();
            break;
        case // String
        8:
            val = ((StringNBT) v).getString();
            break;
        case // List
        9:
            ListNBT tl = (ListNBT) v;
            ArrayList<Object> vlist = new ArrayList<Object>();
            int type = tl.getTagType();
            for (int i = 0; i < tl.size(); i++) {
                switch(type) {
                    case 5:
                        float fv = tl.getFloat(i);
                        vlist.add(fv);
                        break;
                    case 6:
                        double dv = tl.getDouble(i);
                        vlist.add(dv);
                        break;
                    case 8:
                        String sv = tl.getString(i);
                        vlist.add(sv);
                        break;
                    case 10:
                        CompoundNBT tc = tl.getCompound(i);
                        vlist.add(getNBTValue(tc));
                        break;
                    case 11:
                        int[] ia = tl.getIntArray(i);
                        vlist.add(ia);
                        break;
                }
            }
            val = vlist;
            break;
        case // Map
        10:
            CompoundNBT tc = (CompoundNBT) v;
            HashMap<String, Object> vmap = new HashMap<String, Object>();
            for (Object t : tc.keySet()) {
                String st = (String) t;
                INBT tg = tc.get(st);
                vmap.put(st, getNBTValue(tg));
            }
            val = vmap;
            break;
        case // Int[]
        11:
            val = ((IntArrayNBT) v).getIntArray();
            break;
    }
    return val;
}
Also used : IntNBT(net.minecraft.nbt.IntNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) LongNBT(net.minecraft.nbt.LongNBT) DynIntHashMap(org.dynmap.utils.DynIntHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ShortNBT(net.minecraft.nbt.ShortNBT) DoubleNBT(net.minecraft.nbt.DoubleNBT) FloatNBT(net.minecraft.nbt.FloatNBT) ListNBT(net.minecraft.nbt.ListNBT) INBT(net.minecraft.nbt.INBT) ByteNBT(net.minecraft.nbt.ByteNBT)

Example 3 with FloatNBT

use of net.minecraft.nbt.FloatNBT in project dynmap by webbukkit.

the class ForgeMapChunkCache method getNBTValue.

private Object getNBTValue(INBT v) {
    Object val = null;
    switch(v.getId()) {
        case // Byte
        1:
            val = Byte.valueOf(((ByteNBT) v).getByte());
            break;
        case // Short
        2:
            val = Short.valueOf(((ShortNBT) v).getShort());
            break;
        case // Int
        3:
            val = Integer.valueOf(((IntNBT) v).getInt());
            break;
        case // Long
        4:
            val = Long.valueOf(((LongNBT) v).getLong());
            break;
        case // Float
        5:
            val = Float.valueOf(((FloatNBT) v).getFloat());
            break;
        case // Double
        6:
            val = Double.valueOf(((DoubleNBT) v).getDouble());
            break;
        case // Byte[]
        7:
            val = ((ByteArrayNBT) v).getByteArray();
            break;
        case // String
        8:
            val = ((StringNBT) v).getString();
            break;
        case // List
        9:
            ListNBT tl = (ListNBT) v;
            ArrayList<Object> vlist = new ArrayList<Object>();
            int type = tl.getTagType();
            for (int i = 0; i < tl.size(); i++) {
                switch(type) {
                    case 5:
                        float fv = tl.getFloat(i);
                        vlist.add(fv);
                        break;
                    case 6:
                        double dv = tl.getDouble(i);
                        vlist.add(dv);
                        break;
                    case 8:
                        String sv = tl.getString(i);
                        vlist.add(sv);
                        break;
                    case 10:
                        CompoundNBT tc = tl.getCompound(i);
                        vlist.add(getNBTValue(tc));
                        break;
                    case 11:
                        int[] ia = tl.getIntArray(i);
                        vlist.add(ia);
                        break;
                }
            }
            val = vlist;
            break;
        case // Map
        10:
            CompoundNBT tc = (CompoundNBT) v;
            HashMap<String, Object> vmap = new HashMap<String, Object>();
            for (Object t : tc.keySet()) {
                String st = (String) t;
                INBT tg = tc.get(st);
                vmap.put(st, getNBTValue(tg));
            }
            val = vmap;
            break;
        case // Int[]
        11:
            val = ((IntArrayNBT) v).getIntArray();
            break;
    }
    return val;
}
Also used : IntNBT(net.minecraft.nbt.IntNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) LongNBT(net.minecraft.nbt.LongNBT) DynIntHashMap(org.dynmap.utils.DynIntHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ShortNBT(net.minecraft.nbt.ShortNBT) DoubleNBT(net.minecraft.nbt.DoubleNBT) FloatNBT(net.minecraft.nbt.FloatNBT) ListNBT(net.minecraft.nbt.ListNBT) INBT(net.minecraft.nbt.INBT) ByteNBT(net.minecraft.nbt.ByteNBT)

Aggregations

FloatNBT (net.minecraft.nbt.FloatNBT)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ByteNBT (net.minecraft.nbt.ByteNBT)2 CompoundNBT (net.minecraft.nbt.CompoundNBT)2 DoubleNBT (net.minecraft.nbt.DoubleNBT)2 INBT (net.minecraft.nbt.INBT)2 IntNBT (net.minecraft.nbt.IntNBT)2 ListNBT (net.minecraft.nbt.ListNBT)2 LongNBT (net.minecraft.nbt.LongNBT)2 ShortNBT (net.minecraft.nbt.ShortNBT)2 DynIntHashMap (org.dynmap.utils.DynIntHashMap)2