use of net.minecraft.nbt.IntArrayNBT in project ChocolateQuestRepoured by TeamChocoQuest.
the class ItemUnprotectedPositionTool method addPosition.
public void addPosition(ItemStack stack, BlockPos pos) {
int[] data = new int[] { pos.getX(), pos.getY(), pos.getZ() };
this.getOrCreatePositionTagList(stack).appendTag(new IntArrayNBT(data));
}
use of net.minecraft.nbt.IntArrayNBT in project ChocolateQuestRepoured by TeamChocoQuest.
the class ItemUnprotectedPositionTool method removePosition.
public boolean removePosition(ItemStack stack, BlockPos pos) {
ListNBT tagList = this.getPositionTagList(stack);
if (tagList == null) {
return false;
}
Iterator<INBT> iterator = tagList.iterator();
while (iterator.hasNext()) {
INBT tag = iterator.next();
int[] data = ((IntArrayNBT) tag).getIntArray();
if (data[0] == pos.getX() && data[1] == pos.getY() && data[2] == pos.getZ()) {
iterator.remove();
return true;
}
}
return false;
}
use of net.minecraft.nbt.IntArrayNBT in project ChocolateQuestRepoured by TeamChocoQuest.
the class CapabilityProtectedRegionData method writeToNBT.
public CompoundNBT writeToNBT() {
CompoundNBT compound = new CompoundNBT();
int[] data = new int[this.protectedRegionUuids.size() * 4];
int i = 0;
for (UUID uuid : this.protectedRegionUuids) {
data[i * 4] = (int) (uuid.getMostSignificantBits() >> 32);
data[i * 4 + 1] = (int) uuid.getMostSignificantBits();
data[i * 4 + 2] = (int) (uuid.getLeastSignificantBits() >> 32);
data[i * 4 + 3] = (int) uuid.getLeastSignificantBits();
i++;
}
compound.put("protectedRegionUuids", new IntArrayNBT(data));
return compound;
}
use of net.minecraft.nbt.IntArrayNBT in project Mekanism by mekanism.
the class CCArgumentWrapperPropertyTest method checkSameIntArray.
// ===================
// Integer Arrays
// ===================
private boolean checkSameIntArray(List<Integer> ints, @Nullable Class<? extends INBT> targetClass) {
IntArrayNBT nbt = new IntArrayNBT(ints);
Object sanitized = CCArgumentWrapperTestHelper.wrapAndSanitize(nbt, targetClass, false);
if (ints.isEmpty()) {
if (targetClass == INBT.class) {
return sanitized instanceof CompoundNBT && ((CompoundNBT) sanitized).isEmpty();
}
// CollectionNBT
return sanitized instanceof ListNBT && ((ListNBT) sanitized).isEmpty();
} else if (ints.stream().allMatch(value -> value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE)) {
ByteArrayNBT expected = new ByteArrayNBT(ints.stream().map(Integer::byteValue).collect(Collectors.toList()));
return expected.equals(sanitized);
} else if (ints.stream().allMatch(value -> value >= Short.MIN_VALUE && value <= Short.MAX_VALUE)) {
ListNBT expected = ints.stream().map(i -> ShortNBT.valueOf(i.shortValue())).collect(Collectors.toCollection(ListNBT::new));
return expected.equals(sanitized);
}
return nbt.equals(sanitized);
}
use of net.minecraft.nbt.IntArrayNBT in project Mekanism by mekanism.
the class CCArgumentWrapperPropertyTest method testListEmptyPlusIntArray.
@Test
@DisplayName("Test serializing and deserializing lists of lists that would create the inner ones as an empty compound plus an int array")
void testListEmptyPlusIntArray() {
qt().forAll(lists().of(onlyInts()).ofSizeBetween(1, 15)).check(ints -> {
ListNBT nbt = fromArray(new ListNBT(), fromInts(ints));
ListNBT expected = fromArray(new IntArrayNBT(new int[0]), new IntArrayNBT(ints));
return expected.equals(CCArgumentWrapperTestHelper.wrapAndSanitize(nbt, null, false));
});
}
Aggregations