use of net.minecraft.nbt.IntArrayNBT in project Mekanism by mekanism.
the class CCArgumentWrapperTest method testInvalidListCompoundIntArray.
@Test
@DisplayName("Test making sure we fail to create a list out of invalid elements (non empty compound + int array)")
void testInvalidListCompoundIntArray() {
CompoundNBT nbt = new CompoundNBT();
nbt.putString("key", "value");
assertMismatchedList(nbt, new IntArrayNBT(Collections.singletonList(Integer.MAX_VALUE)));
}
use of net.minecraft.nbt.IntArrayNBT 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);
}
Aggregations