Search in sources :

Example 6 with IntArrayNBT

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));
}
Also used : IntArrayNBT(net.minecraft.nbt.IntArrayNBT)

Example 7 with IntArrayNBT

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;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) IntArrayNBT(net.minecraft.nbt.IntArrayNBT) INBT(net.minecraft.nbt.INBT)

Example 8 with IntArrayNBT

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;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) IntArrayNBT(net.minecraft.nbt.IntArrayNBT) UUID(java.util.UUID)

Example 9 with IntArrayNBT

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);
}
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) IntArrayNBT(net.minecraft.nbt.IntArrayNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) ByteArrayNBT(net.minecraft.nbt.ByteArrayNBT)

Example 10 with IntArrayNBT

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));
    });
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) IntArrayNBT(net.minecraft.nbt.IntArrayNBT) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

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