Search in sources :

Example 1 with LongNBT

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

the class CCArgumentWrapperPropertyTest method checkSameLong.

private boolean checkSameLong(long value, @Nullable Class<? extends INBT> targetClass, boolean includeHints) {
    LongNBT nbt = LongNBT.valueOf(value);
    Object sanitized = CCArgumentWrapperTestHelper.wrapAndSanitize(nbt, targetClass, includeHints);
    return getExpected(value).equals(sanitized);
}
Also used : LongNBT(net.minecraft.nbt.LongNBT)

Example 2 with LongNBT

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

the class CCArgumentWrapperPropertyTest method testListLongArrayToList.

@Test
@DisplayName("Test serializing and deserializing lists of lists that would create the inner ones as a long array plus some arbitrary list type (strings)")
void testListLongArrayToList() {
    qt().forAll(lists().of(onlyLongs()).ofSizeBetween(1, 15), lists().of(strings().ascii().ofLengthBetween(0, 15)).ofSizeBetween(1, 15)).check((longs, strings) -> {
        ListNBT stringListNBT = fromStrings(strings);
        ListNBT nbt = fromArray(fromLongs(longs), stringListNBT);
        ListNBT expectedLongs;
        if (longs.stream().anyMatch(value -> value != (long) (double) value)) {
            expectedLongs = longs.stream().map(v -> LongNBT.valueOf((long) (double) v)).collect(Collectors.toCollection(ListNBT::new));
        } else {
            expectedLongs = longs.stream().map(LongNBT::valueOf).collect(Collectors.toCollection(ListNBT::new));
        }
        ListNBT expected = fromArray(expectedLongs, stringListNBT);
        return expected.equals(CCArgumentWrapperTestHelper.wrapAndSanitize(nbt, null, false));
    });
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) LongNBT(net.minecraft.nbt.LongNBT) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with LongNBT

use of net.minecraft.nbt.LongNBT in project MCMOD-Industria by M-Marvin.

the class ChunkLoadHandler method load.

@Override
public void load(CompoundNBT nbt) {
    this.chunkLoaderMap.clear();
    ListNBT nbtChunkLoaderMap = nbt.getList("ChunkLoaderMap", 10);
    nbtChunkLoaderMap.forEach((nbtEntry) -> {
        ListNBT nbtLoaderMap = ((CompoundNBT) nbtEntry).getList("ChunkLoaders", 4);
        List<BlockPos> loaderMap = new ArrayList<BlockPos>();
        nbtLoaderMap.forEach((nbtLoader) -> {
            loaderMap.add(BlockPos.of(((LongNBT) nbtLoader).getAsLong()));
        });
        int[] nbtChunkPos = ((CompoundNBT) nbtEntry).getIntArray("ChunkPos");
        ChunkPos chunkPos = new ChunkPos(nbtChunkPos[0], nbtChunkPos[1]);
        this.chunkLoaderMap.put(chunkPos, loaderMap);
    });
    this.loadHoldChunks.clear();
    ListNBT nbtLoadHoldChunks = nbt.getList("BlockLoadedChunks", 10);
    nbtLoadHoldChunks.forEach((nbtEntry) -> {
        int[] nbtChunkPos = ((CompoundNBT) nbtEntry).getIntArray("ChunkPos");
        ChunkPos chunkPos = new ChunkPos(nbtChunkPos[0], nbtChunkPos[1]);
        boolean vanillaState = ((CompoundNBT) nbtEntry).getBoolean("VanillaForceLoaded");
        this.loadHoldChunks.put(chunkPos, vanillaState);
    });
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) LongNBT(net.minecraft.nbt.LongNBT) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos)

Example 4 with LongNBT

use of net.minecraft.nbt.LongNBT in project ChocolateQuestRepoured by TeamChocoQuest.

the class DungeonGenUtils method readUUIDFromList.

public static UUID readUUIDFromList(ListNBT nbtTagList) {
    INBT nbtM = nbtTagList.get(0);
    INBT nbtL = nbtTagList.get(1);
    return new UUID(nbtM instanceof LongNBT ? ((LongNBT) nbtM).getAsLong() : 0, nbtM instanceof LongNBT ? ((LongNBT) nbtL).getAsLong() : 0);
}
Also used : INBT(net.minecraft.nbt.INBT) LongNBT(net.minecraft.nbt.LongNBT) UUID(java.util.UUID)

Example 5 with LongNBT

use of net.minecraft.nbt.LongNBT 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

LongNBT (net.minecraft.nbt.LongNBT)7 ListNBT (net.minecraft.nbt.ListNBT)4 ArrayList (java.util.ArrayList)3 CompoundNBT (net.minecraft.nbt.CompoundNBT)3 INBT (net.minecraft.nbt.INBT)3 HashMap (java.util.HashMap)2 ByteNBT (net.minecraft.nbt.ByteNBT)2 DoubleNBT (net.minecraft.nbt.DoubleNBT)2 FloatNBT (net.minecraft.nbt.FloatNBT)2 IntNBT (net.minecraft.nbt.IntNBT)2 ShortNBT (net.minecraft.nbt.ShortNBT)2 DynIntHashMap (org.dynmap.utils.DynIntHashMap)2 UUID (java.util.UUID)1 BlockPos (net.minecraft.util.math.BlockPos)1 ChunkPos (net.minecraft.util.math.ChunkPos)1 DisplayName (org.junit.jupiter.api.DisplayName)1 Test (org.junit.jupiter.api.Test)1