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;
}
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));
});
}
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));
});
}
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));
});
}
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));
}
}
Aggregations