use of team.cqr.cqrepoured.world.structure.generation.generation.preparable.PreparableEntityInfo 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));
}
}
use of team.cqr.cqrepoured.world.structure.generation.generation.preparable.PreparableEntityInfo in project ChocolateQuestRepoured by TeamChocoQuest.
the class CQStructure method writeToNBT.
private CompoundNBT writeToNBT() {
CompoundNBT compound = new CompoundNBT();
compound.putString("cqr_file_version", CQStructure.CQR_FILE_VERSION);
compound.putString("author", this.author);
compound.put("size", NBTUtil.writeBlockPos(this.size));
BlockStatePalette palette = new BlockStatePalette();
ListNBT compoundList = new ListNBT();
// Save normal blocks
ByteBuf buf = Unpooled.buffer(this.blockInfoList.size() * 2);
this.blockInfoList.forEach(preparable -> PreparablePosInfo.Registry.write(preparable, buf, palette, compoundList));
compound.putByteArray("blockInfoList", Arrays.copyOf(buf.array(), buf.writerIndex()));
// Save entities
compound.put("entityInfoList", this.entityInfoList.stream().map(PreparableEntityInfo::getEntityData).collect(NBTCollectors.toList()));
// Save block states
compound.put("palette", palette.writeToNBT());
// Save compound tags
compound.put("compoundTagList", compoundList);
compound.putIntArray("unprotectedBlockList", this.unprotectedBlockList.stream().flatMapToInt(pos -> IntStream.of(pos.getX(), pos.getY(), pos.getZ())).toArray());
return compound;
}
use of team.cqr.cqrepoured.world.structure.generation.generation.preparable.PreparableEntityInfo in project ChocolateQuestRepoured by TeamChocoQuest.
the class CQStructure method readFromNBT.
private void readFromNBT(CompoundNBT compound) {
String cqrFileVersion = compound.getString("cqr_file_version");
if (!cqrFileVersion.equals(CQR_FILE_VERSION)) {
if (cqrFileVersion.equals("1.1.0")) {
CQRMain.logger.warn("Structure nbt is deprecated! Expected {} but got {}.", CQR_FILE_VERSION, cqrFileVersion);
this.readFromDeprecatedNBT(compound);
return;
} else {
throw new IllegalArgumentException(String.format("Structure nbt is too old! Expected %s but got %s.", CQR_FILE_VERSION, 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
ByteBuf buf = Unpooled.wrappedBuffer(compound.getByteArray("blockInfoList"));
for (int x = 0; x < this.size.getX(); x++) {
for (int y = 0; y < this.size.getY(); y++) {
for (int z = 0; z < this.size.getZ(); z++) {
this.blockInfoList.add(PreparablePosInfo.Registry.read(x, y, z, buf, blockStatePalette, compoundTagList));
}
}
}
// Load special blocks
if (compound.contains("specialBlockInfoList", Constants.NBT.TAG_BYTE_ARRAY)) {
buf = Unpooled.wrappedBuffer(compound.getByteArray("specialBlockInfoList"));
int specialBlockCount = buf.readInt();
for (int i = 0; i < specialBlockCount; i++) {
int x = buf.readShort();
int y = buf.readShort();
int z = buf.readShort();
int index = ((x * this.size.getY()) + y) * this.size.getZ() + z;
this.blockInfoList.set(index, PreparablePosInfo.Registry.read(x, y, z, buf, blockStatePalette, compoundTagList));
}
}
// Load entities
for (INBT nbt : compound.getList("entityInfoList", Constants.NBT.TAG_COMPOUND)) {
this.entityInfoList.add(new PreparableEntityInfo((CompoundNBT) nbt));
}
this.unprotectedBlockList.clear();
int[] intArray = compound.getIntArray("unprotectedBlockList");
IntStream.range(0, intArray.length / 3).mapToObj(i -> new BlockPos(intArray[i * 3], intArray[i * 3 + 1], intArray[i * 3 + 2])).forEach(this.unprotectedBlockList::add);
}
use of team.cqr.cqrepoured.world.structure.generation.generation.preparable.PreparableEntityInfo in project ChocolateQuestRepoured by TeamChocoQuest.
the class CQStructure method takeEntitiesFromWorld.
private void takeEntitiesFromWorld(World world, BlockPos minPos, BlockPos maxPos, boolean ignoreBasicEntities) {
this.entityInfoList.clear();
AxisAlignedBB aabb = new AxisAlignedBB(minPos, maxPos.offset(1, 1, 1));
for (Entity entity : world.getEntitiesOfClass(Entity.class, aabb, input -> !(input instanceof PlayerEntity))) {
if (ignoreBasicEntities && !SPECIAL_ENTITIES.contains(EntityList.getKey(entity))) {
CQRMain.logger.info("Skipping entity: {}", entity);
continue;
}
this.entityInfoList.add(new PreparableEntityInfo(minPos, entity));
}
}
Aggregations