Search in sources :

Example 6 with LongArrayNBT

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

the class CCArgumentWrapperPropertyTest method testListEmptyPlusLongArray.

@Test
@DisplayName("Test serializing and deserializing lists of lists that would create the inner ones as an empty compound plus a long array")
void testListEmptyPlusLongArray() {
    qt().forAll(lists().of(onlyLongs()).ofSizeBetween(1, 15)).check(longs -> {
        ListNBT nbt = fromArray(new ListNBT(), fromLongs(longs));
        ListNBT expected = fromArray(new LongArrayNBT(new long[0]), getExpected(longs));
        return expected.equals(CCArgumentWrapperTestHelper.wrapAndSanitize(nbt, null, false));
    });
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) LongArrayNBT(net.minecraft.nbt.LongArrayNBT) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 7 with LongArrayNBT

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

the class CCArgumentWrapperPropertyTest method checkSameLongArray.

// ===================
// Long Arrays
// ===================
private boolean checkSameLongArray(List<Long> longs, @Nullable Class<? extends INBT> targetClass) {
    LongArrayNBT nbt = new LongArrayNBT(longs);
    Object sanitized = CCArgumentWrapperTestHelper.wrapAndSanitize(nbt, targetClass, false);
    if (longs.isEmpty()) {
        if (targetClass == INBT.class) {
            return sanitized instanceof CompoundNBT && ((CompoundNBT) sanitized).isEmpty();
        }
        // CollectionNBT
        return sanitized instanceof ListNBT && ((ListNBT) sanitized).isEmpty();
    } else if (longs.stream().allMatch(value -> value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE)) {
        ByteArrayNBT expected = new ByteArrayNBT(longs.stream().map(Long::byteValue).collect(Collectors.toList()));
        return expected.equals(sanitized);
    } else if (longs.stream().allMatch(value -> value >= Short.MIN_VALUE && value <= Short.MAX_VALUE)) {
        ListNBT expected = longs.stream().map(i -> ShortNBT.valueOf(i.shortValue())).collect(Collectors.toCollection(ListNBT::new));
        return expected.equals(sanitized);
    } else if (longs.stream().allMatch(value -> value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE)) {
        IntArrayNBT expected = new IntArrayNBT(longs.stream().map(Long::intValue).collect(Collectors.toList()));
        return expected.equals(sanitized);
    }
    return getExpected(longs).equals(sanitized);
}
Also used : ByteArrayNBT(net.minecraft.nbt.ByteArrayNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) FloatNBT(net.minecraft.nbt.FloatNBT) Gen(org.quicktheories.core.Gen) NumberNBT(net.minecraft.nbt.NumberNBT) Nullable(javax.annotation.Nullable) INBT(net.minecraft.nbt.INBT) LongArrayNBT(net.minecraft.nbt.LongArrayNBT) ByteNBT(net.minecraft.nbt.ByteNBT) ListNBT(net.minecraft.nbt.ListNBT) StringNBT(net.minecraft.nbt.StringNBT) DoubleNBT(net.minecraft.nbt.DoubleNBT) CollectionNBT(net.minecraft.nbt.CollectionNBT) ShortNBT(net.minecraft.nbt.ShortNBT) IntArrayNBT(net.minecraft.nbt.IntArrayNBT) Collectors(java.util.stream.Collectors) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) IntNBT(net.minecraft.nbt.IntNBT) List(java.util.List) Constraint(org.quicktheories.impl.Constraint) LongNBT(net.minecraft.nbt.LongNBT) WithQuickTheories(org.quicktheories.WithQuickTheories) Collections(java.util.Collections) QuickTheory(org.quicktheories.QuickTheory) ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) IntArrayNBT(net.minecraft.nbt.IntArrayNBT) ByteArrayNBT(net.minecraft.nbt.ByteArrayNBT) LongArrayNBT(net.minecraft.nbt.LongArrayNBT)

Example 8 with LongArrayNBT

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

the class CCArgumentWrapperPropertyTest method testListByteArrayToLongArray.

@Test
@DisplayName("Test serializing and deserializing lists of lists that would create the inner ones as a byte array plus long array")
void testListByteArrayToLongArray() {
    qt().forAll(lists().of(allBytes()).ofSizeBetween(1, 15), lists().of(onlyLongs()).ofSizeBetween(1, 15)).check((bytes, longs) -> {
        ListNBT nbt = fromArray(fromBytes(bytes), fromLongs(longs));
        ListNBT expected = fromArray(new LongArrayNBT(bytes.stream().mapToLong(Number::longValue).toArray()), getExpected(longs));
        return expected.equals(CCArgumentWrapperTestHelper.wrapAndSanitize(nbt, null, false));
    });
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) LongArrayNBT(net.minecraft.nbt.LongArrayNBT) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 9 with LongArrayNBT

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

the class TileEntityItemStackGasToItemStackFactory method save.

@Nonnull
@Override
public CompoundNBT save(@Nonnull CompoundNBT nbtTags) {
    super.save(nbtTags);
    nbtTags.put(NBTConstants.USED_SO_FAR, new LongArrayNBT(Arrays.copyOf(usedSoFar, usedSoFar.length)));
    return nbtTags;
}
Also used : LongArrayNBT(net.minecraft.nbt.LongArrayNBT) Nonnull(javax.annotation.Nonnull)

Aggregations

LongArrayNBT (net.minecraft.nbt.LongArrayNBT)9 DisplayName (org.junit.jupiter.api.DisplayName)7 Test (org.junit.jupiter.api.Test)7 ListNBT (net.minecraft.nbt.ListNBT)6 CompoundNBT (net.minecraft.nbt.CompoundNBT)2 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 ByteArrayNBT (net.minecraft.nbt.ByteArrayNBT)1 ByteNBT (net.minecraft.nbt.ByteNBT)1 CollectionNBT (net.minecraft.nbt.CollectionNBT)1 DoubleNBT (net.minecraft.nbt.DoubleNBT)1 FloatNBT (net.minecraft.nbt.FloatNBT)1 INBT (net.minecraft.nbt.INBT)1 IntArrayNBT (net.minecraft.nbt.IntArrayNBT)1 IntNBT (net.minecraft.nbt.IntNBT)1 LongNBT (net.minecraft.nbt.LongNBT)1 NumberNBT (net.minecraft.nbt.NumberNBT)1