Search in sources :

Example 1 with SchematicBlockBase

use of buildcraft.api.blueprints.SchematicBlockBase in project BuildCraft by BuildCraft.

the class Blueprint method saveContents.

@Override
public void saveContents(NBTTagCompound nbt) {
    NBTTagCompound nbtContents = new NBTTagCompound();
    for (BlockPos pos : BlockPos.getAllInBox(BlockPos.ORIGIN, size.subtract(Utils.POS_ONE))) {
        SchematicBlockBase schematic = null;
        NBTTagCompound cpt = new NBTTagCompound();
        try {
            schematic = get(pos);
            if (schematic != null) {
                schematic.idsToBlueprint(mapping);
                schematic.writeSchematicToNBT(cpt, mapping);
                /* We don't use the index of the current for loop because we shouldn't rely on the behaviour of
                     * BlockPos.getAllInBox */
                nbtContents.setTag(StringUtilBC.blockPosToShortString(pos), cpt);
            }
        } catch (Throwable t) {
            CrashReport crash;
            if (t instanceof ReportedException) {
                crash = ((ReportedException) t).getCrashReport();
            } else {
                crash = new CrashReport("Failed to save the contents of a blueprint!", t);
            }
            CrashReportCategory cat = crash.makeCategory("Block Being Saved");
            cat.addCrashSection("Block Position (In schematic)", pos);
            cat.addCrashSection("Schematic type", schematic == null ? "~~NULL~~" : schematic.getClass());
            mapping.addToCrashReport(crash.makeCategory("Mapping Registry"));
            throw new ReportedException(crash);
        }
    }
    nbt.setTag("contents", nbtContents);
    NBTTagList entitiesNBT = new NBTTagList();
    for (SchematicEntity s : entities) {
        NBTTagCompound subNBT = new NBTTagCompound();
        s.idsToBlueprint(mapping);
        s.writeSchematicToNBT(subNBT, mapping);
        entitiesNBT.appendTag(subNBT);
    }
    nbt.setTag("entities", entitiesNBT);
    NBTTagCompound contextNBT = new NBTTagCompound();
    mapping.write(contextNBT);
    nbt.setTag("idMapping", contextNBT);
}
Also used : SchematicBlockBase(buildcraft.api.blueprints.SchematicBlockBase) NBTTagList(net.minecraft.nbt.NBTTagList) CrashReport(net.minecraft.crash.CrashReport) SchematicEntity(buildcraft.api.blueprints.SchematicEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) CrashReportCategory(net.minecraft.crash.CrashReportCategory) ReportedException(net.minecraft.util.ReportedException)

Example 2 with SchematicBlockBase

use of buildcraft.api.blueprints.SchematicBlockBase in project BuildCraft by BuildCraft.

the class BptBuilderTemplate method internalInit.

@Override
protected void internalInit() {
    BlockPos worldOffset = pos.subtract(blueprint.anchor);
    BlockPos bptMin = BlockPos.ORIGIN;
    if (worldOffset.getY() < 0)
        bptMin = VecUtil.replaceValue(bptMin, Axis.Y, -worldOffset.getY());
    BlockPos bptMax = blueprint.size.subtract(Utils.POS_ONE);
    if (worldOffset.add(bptMax).getY() >= context.world().getHeight()) {
        bptMax = VecUtil.replaceValue(bptMax, Axis.Y, context.world().getHeight() - worldOffset.getY());
    }
    /* Check to make sure the max is bigger than the min- if its not it means that the size was 0 for one of the
         * axis */
    if (Utils.min(bptMin, bptMax).equals(bptMin) && Utils.max(bptMin, bptMax).equals(bptMax)) {
        if (blueprint.excavate) {
            for (BlockPos bptOffset : BlockPos.getAllInBox(bptMin, bptMax)) {
                BlockPos pointWorldOffset = worldOffset.add(bptOffset);
                SchematicBlockBase slot = blueprint.get(bptOffset);
                if (slot == null && !isLocationUsed(pointWorldOffset)) {
                    BuildingSlotBlock b = new BuildingSlotBlock();
                    b.schematic = null;
                    b.pos = pointWorldOffset;
                    b.mode = Mode.ClearIfInvalid;
                    b.buildStage = 0;
                    clearList.add(b);
                }
            }
        }
        for (BlockPos bptOffset : BlockPos.getAllInBox(bptMin, bptMax)) {
            BlockPos pointWorldOffset = worldOffset.add(bptOffset);
            SchematicBlockBase slot = blueprint.get(bptOffset);
            if (slot != null && !isLocationUsed(pointWorldOffset)) {
                BuildingSlotBlock b = new BuildingSlotBlock();
                b.schematic = slot;
                b.pos = pointWorldOffset;
                b.mode = Mode.Build;
                b.buildStage = 1;
                buildList.add(b);
            }
        }
    }
    iteratorBuild = new BuildingSlotIterator(buildList);
    iteratorClear = new BuildingSlotIterator(clearList);
}
Also used : SchematicBlockBase(buildcraft.api.blueprints.SchematicBlockBase) BuildingSlotBlock(buildcraft.core.builders.BuildingSlotBlock) BuildingSlotIterator(buildcraft.core.builders.BuildingSlotIterator) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with SchematicBlockBase

use of buildcraft.api.blueprints.SchematicBlockBase in project BuildCraft by BuildCraft.

the class Blueprint method loadSingleSchematicFromNBT.

private void loadSingleSchematicFromNBT(BlockPos pos, NBTTagCompound cpt) {
    if (cpt.hasKey("blockId")) {
        Block block;
        try {
            block = mapping.getBlockForId(cpt.getInteger("blockId"));
        } catch (MappingNotFoundException e) {
            block = null;
            isComplete = false;
        }
        if (block != null) {
            int meta = cpt.getInteger("blockMeta");
            SchematicBlockBase schematic = SchematicRegistry.INSTANCE.createSchematicBlock(block.getStateFromMeta(meta));
            if (schematic != null) {
                schematic.readSchematicFromNBT(cpt, mapping);
                if (!schematic.doNotUse()) {
                    schematic.idsToWorld(mapping);
                    switch(schematic.getBuildingPermission()) {
                        case ALL:
                            break;
                        case CREATIVE_ONLY:
                            if (buildingPermission == BuildingPermission.ALL) {
                                buildingPermission = BuildingPermission.CREATIVE_ONLY;
                            }
                            break;
                        case NONE:
                            buildingPermission = BuildingPermission.NONE;
                            break;
                    }
                } else {
                    schematic = null;
                    isComplete = false;
                }
            }
            set(pos, schematic);
        } else {
            set(pos, null);
            isComplete = false;
        }
    } else {
        set(pos, null);
    }
}
Also used : MappingNotFoundException(buildcraft.api.blueprints.MappingNotFoundException) SchematicBlockBase(buildcraft.api.blueprints.SchematicBlockBase) SchematicBlock(buildcraft.api.blueprints.SchematicBlock) Block(net.minecraft.block.Block)

Aggregations

SchematicBlockBase (buildcraft.api.blueprints.SchematicBlockBase)3 BlockPos (net.minecraft.util.math.BlockPos)2 MappingNotFoundException (buildcraft.api.blueprints.MappingNotFoundException)1 SchematicBlock (buildcraft.api.blueprints.SchematicBlock)1 SchematicEntity (buildcraft.api.blueprints.SchematicEntity)1 BuildingSlotBlock (buildcraft.core.builders.BuildingSlotBlock)1 BuildingSlotIterator (buildcraft.core.builders.BuildingSlotIterator)1 Block (net.minecraft.block.Block)1 CrashReport (net.minecraft.crash.CrashReport)1 CrashReportCategory (net.minecraft.crash.CrashReportCategory)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 ReportedException (net.minecraft.util.ReportedException)1