Search in sources :

Example 1 with TileBuilder

use of buildcraft.builders.TileBuilder in project BuildCraft by BuildCraft.

the class RecursiveBlueprintReader method iterate.

public void iterate() {
    if (done) {
        return;
    } else if (currentSubReader == null && subIndex < architect.subBlueprints.size()) {
        BlockPos subBlock = architect.subBlueprints.get(subIndex);
        TileEntity subTile = architect.getWorld().getTileEntity(subBlock);
        if (subTile instanceof TileArchitect) {
            TileArchitect subArchitect = (TileArchitect) subTile;
            currentSubReader = new RecursiveBlueprintReader(subArchitect, writingBlueprint);
        } else if (subTile instanceof TileConstructionMarker || subTile instanceof TileBuilder) {
            BlueprintBase blueprint = null;
            EnumFacing orientation = EnumFacing.EAST;
            if (subTile instanceof TileConstructionMarker) {
                TileConstructionMarker marker = (TileConstructionMarker) subTile;
                blueprint = ItemBlueprint.loadBlueprint(marker.itemBlueprint);
                orientation = marker.direction;
            } else if (subTile instanceof TileBuilder) {
                TileBuilder builder = (TileBuilder) subTile;
                blueprint = ItemBlueprint.loadBlueprint(builder.getStackInSlot(0));
                orientation = architect.getWorld().getBlockState(subBlock).getValue(BuildCraftProperties.BLOCK_FACING).getOpposite();
            }
            if (blueprint != null) {
                BlockPos nPos = subTile.getPos().subtract(architect.getBox().min());
                writingBlueprint.addSubBlueprint(blueprint, nPos, orientation);
            }
            subIndex++;
        } else {
            subIndex++;
        }
    } else if (currentSubReader != null) {
        currentSubReader.iterate();
        World world = currentSubReader.architect.getWorld();
        EnumFacing facing = world.getBlockState(currentSubReader.architect.getPos()).getValue(BuildCraftProperties.BLOCK_FACING).getOpposite();
        BlockPos pos = currentSubReader.architect.getPos().subtract(architect.getBox().min());
        if (currentSubReader.isDone()) {
            writingBlueprint.addSubBlueprint(currentSubReader.getBlueprint(), pos, facing);
            currentSubReader = null;
            subIndex++;
        }
    } else if (blockScanner != null && blockScanner.blocksLeft() != 0) {
        for (BlockPos index : blockScanner) {
            writingBlueprint.readFromWorld(writingContext, architect, index);
        }
        computingTime = 1 - (float) blockScanner.blocksLeft() / (float) blockScanner.totalBlocks();
        if (blockScanner.blocksLeft() == 0) {
            writingBlueprint.readEntitiesFromWorld(writingContext, architect);
            Vec3d transform = Utils.VEC_ZERO.subtract(Utils.convert(writingContext.surroundingBox().min()));
            writingBlueprint.translateToBlueprint(transform);
            EnumFacing o = architect.getWorld().getBlockState(architect.getPos()).getValue(BuildCraftProperties.BLOCK_FACING).getOpposite();
            writingBlueprint.rotate = architect.readConfiguration.rotate;
            writingBlueprint.excavate = architect.readConfiguration.excavate;
            if (writingBlueprint.rotate) {
                if (o == EnumFacing.EAST) {
                // Do nothing
                } else if (o == EnumFacing.SOUTH) {
                    writingBlueprint.rotateLeft(writingContext);
                    writingBlueprint.rotateLeft(writingContext);
                    writingBlueprint.rotateLeft(writingContext);
                } else if (o == EnumFacing.WEST) {
                    writingBlueprint.rotateLeft(writingContext);
                    writingBlueprint.rotateLeft(writingContext);
                } else if (o == EnumFacing.NORTH) {
                    writingBlueprint.rotateLeft(writingContext);
                }
            }
        }
    } else if (blockScanner != null) {
        createBlueprint();
        done = true;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlueprintBase(buildcraft.core.blueprints.BlueprintBase) TileBuilder(buildcraft.builders.TileBuilder) TileArchitect(buildcraft.builders.TileArchitect) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) TileConstructionMarker(buildcraft.builders.TileConstructionMarker) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

TileArchitect (buildcraft.builders.TileArchitect)1 TileBuilder (buildcraft.builders.TileBuilder)1 TileConstructionMarker (buildcraft.builders.TileConstructionMarker)1 BlueprintBase (buildcraft.core.blueprints.BlueprintBase)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vec3d (net.minecraft.util.math.Vec3d)1 World (net.minecraft.world.World)1