Search in sources :

Example 1 with PreparableEntityInfo

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

Example 2 with PreparableEntityInfo

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;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) PreparableEntityInfo(team.cqr.cqrepoured.world.structure.generation.generation.preparable.PreparableEntityInfo) ByteBuf(io.netty.buffer.ByteBuf)

Example 3 with PreparableEntityInfo

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);
}
Also used : Arrays(java.util.Arrays) Constants(net.minecraftforge.common.util.Constants) CompoundNBT(net.minecraft.nbt.CompoundNBT) Unpooled(io.netty.buffer.Unpooled) Block(net.minecraft.block.Block) Map(java.util.Map) BlockState(net.minecraft.block.BlockState) BlockExporterChest(team.cqr.cqrepoured.block.BlockExporterChest) ListNBT(net.minecraft.nbt.ListNBT) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Collection(java.util.Collection) EntityList(net.minecraft.entity.EntityList) Set(java.util.Set) PreparableEntityInfo(team.cqr.cqrepoured.world.structure.generation.generation.preparable.PreparableEntityInfo) CQRBlocks(team.cqr.cqrepoured.init.CQRBlocks) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) CompressedStreamTools(net.minecraft.nbt.CompressedStreamTools) DungeonPlacement(team.cqr.cqrepoured.world.structure.generation.generation.DungeonPlacement) NBTUtil(net.minecraft.nbt.NBTUtil) IntStream(java.util.stream.IntStream) EntityDungeonPart(team.cqr.cqrepoured.world.structure.generation.generation.part.EntityDungeonPart) DungeonInhabitant(team.cqr.cqrepoured.world.structure.generation.inhabitants.DungeonInhabitant) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) HashMap(java.util.HashMap) Mirror(net.minecraft.util.Mirror) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ByteBuf(io.netty.buffer.ByteBuf) GeneratableDungeon(team.cqr.cqrepoured.world.structure.generation.generation.GeneratableDungeon) NBTCollectors(team.cqr.cqrepoured.util.NBTCollectors) PreparablePosInfo(team.cqr.cqrepoured.world.structure.generation.generation.preparable.PreparablePosInfo) CQRMain(team.cqr.cqrepoured.CQRMain) INBT(net.minecraft.nbt.INBT) OutputStream(java.io.OutputStream) Entity(net.minecraft.entity.Entity) BlockDungeonPart(team.cqr.cqrepoured.world.structure.generation.generation.part.BlockDungeonPart) World(net.minecraft.world.World) FileOutputStream(java.io.FileOutputStream) FileUtils(org.apache.commons.io.FileUtils) BlockPos(net.minecraft.util.math.BlockPos) FileInputStream(java.io.FileInputStream) IntArrayNBT(net.minecraft.nbt.IntArrayNBT) File(java.io.File) Blocks(net.minecraft.block.Blocks) Rotation(net.minecraft.util.Rotation) ResourceLocation(net.minecraft.util.ResourceLocation) Comparator(java.util.Comparator) Collections(java.util.Collections) CQRConfig(team.cqr.cqrepoured.config.CQRConfig) InputStream(java.io.InputStream) DungeonGenUtils(team.cqr.cqrepoured.util.DungeonGenUtils) NBTHelper(team.cqr.cqrepoured.util.NBTHelper) ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) INBT(net.minecraft.nbt.INBT) BlockPos(net.minecraft.util.math.BlockPos) PreparableEntityInfo(team.cqr.cqrepoured.world.structure.generation.generation.preparable.PreparableEntityInfo) ByteBuf(io.netty.buffer.ByteBuf)

Example 4 with PreparableEntityInfo

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));
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Entity(net.minecraft.entity.Entity) PreparableEntityInfo(team.cqr.cqrepoured.world.structure.generation.generation.preparable.PreparableEntityInfo) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

PreparableEntityInfo (team.cqr.cqrepoured.world.structure.generation.generation.preparable.PreparableEntityInfo)4 CompoundNBT (net.minecraft.nbt.CompoundNBT)3 ListNBT (net.minecraft.nbt.ListNBT)3 ByteBuf (io.netty.buffer.ByteBuf)2 Entity (net.minecraft.entity.Entity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 INBT (net.minecraft.nbt.INBT)2 IntArrayNBT (net.minecraft.nbt.IntArrayNBT)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 Unpooled (io.netty.buffer.Unpooled)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1