Search in sources :

Example 6 with BlueprintBase

use of buildcraft.core.blueprints.BlueprintBase in project BuildCraft by BuildCraft.

the class TileBuilder method iterateBpt.

public void iterateBpt(boolean forceIterate) {
    if (getStackInSlot(0) == null || !(getStackInSlot(0).getItem() instanceof ItemBlueprint)) {
        if (box.isInitialized()) {
            if (currentBuilder != null) {
                currentBuilder = null;
            }
            if (box.isInitialized()) {
                box.reset();
            }
            if (currentPathIterator != null) {
                currentPathIterator = null;
            }
            scheduleRequirementUpdate();
            sendNetworkUpdate();
            return;
        }
    }
    if (currentBuilder == null || (currentBuilder.isDone(this) || forceIterate)) {
        if (path != null && path.size() > 1) {
            if (currentPathIterator == null) {
                Iterator<BlockPos> it = path.iterator();
                BlockPos start = it.next();
                EnumFacing face = worldObj.getBlockState(pos).getValue(BuildCraftProperties.BLOCK_FACING);
                currentPathIterator = new PathIterator(start, it, face);
            }
            if (currentBuilder != null && currentBuilder.isDone(this)) {
                currentBuilder.postProcessing(worldObj);
            }
            currentBuilder = currentPathIterator.next();
            if (currentBuilder != null) {
                box.reset();
                box.initialize(currentBuilder);
                sendNetworkUpdate();
            }
            if (currentBuilder == null) {
                currentPathIterator = currentPathIterator.iterate();
            }
            if (currentPathIterator == null) {
                done = true;
            } else {
                done = false;
            }
            scheduleRequirementUpdate();
        } else {
            if (currentBuilder != null && currentBuilder.isDone(this)) {
                currentBuilder.postProcessing(worldObj);
                currentBuilder = recursiveBuilder.nextBuilder();
                scheduleRequirementUpdate();
            } else {
                BlueprintBase bpt = instanciateBlueprint();
                if (bpt != null) {
                    EnumFacing face = worldObj.getBlockState(pos).getValue(BuildCraftProperties.BLOCK_FACING);
                    recursiveBuilder = new RecursiveBlueprintBuilder(bpt, worldObj, pos, face.getOpposite());
                    currentBuilder = recursiveBuilder.nextBuilder();
                    scheduleRequirementUpdate();
                }
            }
            if (currentBuilder == null) {
                done = true;
            } else {
                box.initialize(currentBuilder);
                sendNetworkUpdate();
                done = false;
            }
        }
    }
    if (done && getStackInSlot(0) != null) {
        boolean dropBlueprint = true;
        for (int i = 1; i < getSizeInventory(); ++i) {
            if (getStackInSlot(i) == null) {
                setInventorySlotContents(i, getStackInSlot(0));
                dropBlueprint = false;
                break;
            }
        }
        if (dropBlueprint) {
            InvUtils.dropItems(getWorld(), getStackInSlot(0), pos);
        }
        setInventorySlotContents(0, null);
        box.reset();
        sendNetworkUpdate();
    }
}
Also used : BlueprintBase(buildcraft.core.blueprints.BlueprintBase) RecursiveBlueprintBuilder(buildcraft.builders.blueprints.RecursiveBlueprintBuilder) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) Blueprint(buildcraft.core.blueprints.Blueprint) BptBuilderBlueprint(buildcraft.core.blueprints.BptBuilderBlueprint)

Example 7 with BlueprintBase

use of buildcraft.core.blueprints.BlueprintBase in project BuildCraft by BuildCraft.

the class RecursiveBlueprintBuilder method nextBuilder.

public BptBuilderBase nextBuilder() {
    if (!returnedThis) {
        blueprint = blueprint.adjustToWorld(world, pos, dir);
        returnedThis = true;
        BptBuilderBase builder;
        if (blueprint instanceof Blueprint) {
            builder = new BptBuilderBlueprint((Blueprint) blueprint, world, pos);
        } else if (blueprint instanceof Template) {
            builder = new BptBuilderTemplate(blueprint, world, pos);
        } else {
            return null;
        }
        box.initialize(builder);
        return builder;
    }
    // Free memory associated with this blueprint
    blueprint = null;
    if (current != null) {
        BptBuilderBase builder = current.nextBuilder();
        if (builder != null) {
            return builder;
        }
    }
    if (nextSubBlueprint >= subBlueprints.size()) {
        return null;
    }
    NBTTagCompound nbt = subBlueprints.get(nextSubBlueprint);
    BlueprintBase bpt = BlueprintBase.loadBluePrint(nbt.getCompoundTag("bpt"));
    int nx = box.min().getX() + nbt.getInteger("x");
    int ny = box.min().getY() + nbt.getInteger("y");
    int nz = box.min().getZ() + nbt.getInteger("z");
    EnumFacing nbtDir = EnumFacing.values()[nbt.getByte("dir")];
    current = new RecursiveBlueprintBuilder(bpt, world, new BlockPos(nx, ny, nz), nbtDir);
    nextSubBlueprint++;
    return current.nextBuilder();
}
Also used : BlueprintBase(buildcraft.core.blueprints.BlueprintBase) BptBuilderBase(buildcraft.core.blueprints.BptBuilderBase) Blueprint(buildcraft.core.blueprints.Blueprint) BptBuilderBlueprint(buildcraft.core.blueprints.BptBuilderBlueprint) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) BptBuilderBlueprint(buildcraft.core.blueprints.BptBuilderBlueprint) BptBuilderTemplate(buildcraft.core.blueprints.BptBuilderTemplate) Blueprint(buildcraft.core.blueprints.Blueprint) BptBuilderBlueprint(buildcraft.core.blueprints.BptBuilderBlueprint) Template(buildcraft.core.blueprints.Template) BptBuilderTemplate(buildcraft.core.blueprints.BptBuilderTemplate)

Aggregations

BlueprintBase (buildcraft.core.blueprints.BlueprintBase)7 Blueprint (buildcraft.core.blueprints.Blueprint)4 BptBuilderBlueprint (buildcraft.core.blueprints.BptBuilderBlueprint)4 EnumFacing (net.minecraft.util.EnumFacing)3 BlockPos (net.minecraft.util.math.BlockPos)3 BptBuilderTemplate (buildcraft.core.blueprints.BptBuilderTemplate)2 Template (buildcraft.core.blueprints.Template)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 Vec3d (net.minecraft.util.math.Vec3d)2 IBlueprintItem (buildcraft.api.items.IBlueprintItem)1 TileArchitect (buildcraft.builders.TileArchitect)1 TileBuilder (buildcraft.builders.TileBuilder)1 TileConstructionMarker (buildcraft.builders.TileConstructionMarker)1 RecursiveBlueprintBuilder (buildcraft.builders.blueprints.RecursiveBlueprintBuilder)1 LaserData (buildcraft.core.LaserData)1 BptBuilderBase (buildcraft.core.blueprints.BptBuilderBase)1 LibraryId (buildcraft.core.blueprints.LibraryId)1 BuildingItem (buildcraft.core.builders.BuildingItem)1 TileEntity (net.minecraft.tileentity.TileEntity)1 World (net.minecraft.world.World)1