Search in sources :

Example 1 with IntArrayNBT

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

the class TileEntityFactory method save.

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

Example 2 with IntArrayNBT

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

the class CCArgumentWrapperPropertyTest method testListShortListToIntArray.

@Test
@DisplayName("Test serializing and deserializing lists of lists that would create the inner ones as a short list plus int array")
void testListShortListToIntArray() {
    qt().forAll(lists().of(onlyShorts()).ofSizeBetween(1, 15), lists().of(onlyInts()).ofSizeBetween(1, 15)).check((shorts, ints) -> {
        ListNBT nbt = fromArray(fromShorts(shorts), fromInts(ints));
        ListNBT expected = fromArray(new IntArrayNBT(shorts.stream().mapToInt(Number::intValue).toArray()), 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)

Example 3 with IntArrayNBT

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

the class CCArgumentWrapperPropertyTest method testListIntArrayPlusEmpty.

@Test
@DisplayName("Test serializing and deserializing lists of lists that would create the inner ones as int arrays plus an empty list")
void testListIntArrayPlusEmpty() {
    qt().forAll(lists().of(onlyInts()).ofSizeBetween(1, 15)).check(ints -> {
        ListNBT nbt = fromArray(fromInts(ints), new ListNBT());
        ListNBT expected = fromArray(new IntArrayNBT(ints), new IntArrayNBT(new int[0]));
        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)

Example 4 with IntArrayNBT

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

the class CCArgumentWrapperPropertyTest method testListByteArrayToIntArray.

@Test
@DisplayName("Test serializing and deserializing lists of lists that would create the inner ones as a byte array plus int array")
void testListByteArrayToIntArray() {
    qt().forAll(lists().of(allBytes()).ofSizeBetween(1, 15), lists().of(onlyInts()).ofSizeBetween(1, 15)).check((bytes, ints) -> {
        ListNBT nbt = fromArray(fromBytes(bytes), fromInts(ints));
        ListNBT expected = fromArray(new IntArrayNBT(bytes.stream().mapToInt(Number::intValue).toArray()), 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)

Example 5 with IntArrayNBT

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

the class CQStructure method readFromDeprecatedNBT.

@Deprecated
private void readFromDeprecatedNBT(CompoundNBT compound) {
    String cqrFileVersion = compound.getString("cqr_file_version");
    if (!cqrFileVersion.equals("1.1.0")) {
        throw new IllegalArgumentException(String.format("Structure nbt is too old! Expected %s but got %s.", "1.1.0", cqrFileVersion));
    }
    this.author = compound.getString("author");
    this.size = NBTUtil.readBlockPos(compound.getCompound("size"));
    this.blockInfoList.clear();
    this.entityInfoList.clear();
    BlockStatePalette blockStatePalette = new BlockStatePalette();
    // Load compound tags
    ListNBT compoundTagList = compound.getList("compoundTagList", Constants.NBT.TAG_COMPOUND);
    // Load block states
    int blockStateIndex = 0;
    for (INBT nbt : compound.getList("palette", Constants.NBT.TAG_COMPOUND)) {
        blockStatePalette.addMapping(NBTUtil.readBlockState((CompoundNBT) nbt), blockStateIndex++);
    }
    // Load normal blocks
    int x = 0;
    int y = 0;
    int z = 0;
    for (INBT nbt : compound.getList("blockInfoList", Constants.NBT.TAG_INT_ARRAY)) {
        this.blockInfoList.add(PreparablePosInfo.Registry.read(x, y, z, (IntArrayNBT) nbt, blockStatePalette, compoundTagList));
        if (x < this.size.getX() - 1) {
            x++;
        } else if (y < this.size.getY() - 1) {
            x = 0;
            y++;
        } else if (z < this.size.getZ() - 1) {
            x = 0;
            y = 0;
            z++;
        }
    }
    this.blockInfoList.sort(DEFAULT_COMPARATOR);
    // Load special blocks
    for (INBT nbt : compound.getList("specialBlockInfoList", Constants.NBT.TAG_COMPOUND)) {
        CompoundNBT tag = (CompoundNBT) nbt;
        if (tag.contains("blockInfo", Constants.NBT.TAG_INT_ARRAY)) {
            ListNBT pos = tag.getList("pos", Constants.NBT.TAG_INT);
            this.blockInfoList.add(PreparablePosInfo.Registry.read(pos.getInt(0), pos.getInt(1), pos.getInt(2), (IntArrayNBT) tag.get("blockInfo"), blockStatePalette, compoundTagList));
        }
    }
    // Load entities
    for (INBT nbt : compound.getList("entityInfoList", Constants.NBT.TAG_COMPOUND)) {
        this.entityInfoList.add(new PreparableEntityInfo((CompoundNBT) nbt));
    }
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) IntArrayNBT(net.minecraft.nbt.IntArrayNBT) INBT(net.minecraft.nbt.INBT) PreparableEntityInfo(team.cqr.cqrepoured.world.structure.generation.generation.preparable.PreparableEntityInfo)

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