use of buildcraft.core.blueprints.BlueprintBase in project BuildCraft by BuildCraft.
the class ItemBlueprint method loadBlueprint.
public static BlueprintBase loadBlueprint(ItemStack stack) {
if (stack == null || stack.getItem() == null || !(stack.getItem() instanceof IBlueprintItem)) {
return null;
}
LibraryId id = getId(stack);
if (id == null) {
return null;
}
NBTTagCompound nbt = BuildCraftBuilders.serverDB.load(id);
BlueprintBase base;
if (((IBlueprintItem) stack.getItem()).getType(stack) == EnumBlueprintType.TEMPLATE) {
base = new Template();
} else {
base = new Blueprint();
}
base.readFromNBT(nbt);
base.id = id;
return base;
}
use of buildcraft.core.blueprints.BlueprintBase in project BuildCraft by BuildCraft.
the class LibraryBlueprintTypeHandler method load.
@Override
public ItemStack load(ItemStack stack, NBTTagCompound compound) {
BlueprintBase blueprint = BlueprintBase.loadBluePrint((NBTTagCompound) compound.copy());
blueprint.id.name = compound.getString("__filename");
blueprint.id.extension = getOutputExtension();
BuildCraftBuilders.serverDB.add(blueprint.id, compound);
return blueprint.getStack();
}
use of buildcraft.core.blueprints.BlueprintBase 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;
}
}
use of buildcraft.core.blueprints.BlueprintBase in project BuildCraft by BuildCraft.
the class TileConstructionMarker method update.
@Override
public void update() {
super.update();
BuildingItem toRemove = null;
for (BuildingItem i : buildersInAction) {
i.update();
if (i.isDone) {
toRemove = i;
}
}
if (toRemove != null) {
buildersInAction.remove(toRemove);
}
if (worldObj.isRemote) {
return;
}
if (itemBlueprint != null && ItemBlueprint.getId(itemBlueprint) != null && bluePrintBuilder == null) {
BlueprintBase bpt = ItemBlueprint.loadBlueprint(itemBlueprint);
if (bpt != null && bpt instanceof Blueprint) {
bpt = bpt.adjustToWorld(worldObj, pos, direction);
if (bpt != null) {
bluePrintBuilder = new BptBuilderBlueprint((Blueprint) bpt, worldObj, pos);
bptContext = bluePrintBuilder.getContext();
box.initialize(bluePrintBuilder);
sendNetworkUpdate();
}
} else {
return;
}
}
if (laser == null && direction != null) {
Vec3d point5 = new Vec3d(0.5, 0.5, 0.5);
laser = new LaserData();
laser.head = Utils.convert(pos).add(point5);
laser.tail = laser.head.add(Utils.convert(direction, 0.5));
laser.isVisible = true;
sendNetworkUpdate();
}
if (initNBT != null) {
if (bluePrintBuilder != null) {
bluePrintBuilder.loadBuildStateToNBT(initNBT.getCompoundTag("builderState"), this);
}
initNBT = null;
}
}
use of buildcraft.core.blueprints.BlueprintBase in project BuildCraft by BuildCraft.
the class TileBuilder method instanciateBluePrintBuilder.
@Deprecated
public BptBuilderBase instanciateBluePrintBuilder(BlockPos pos, EnumFacing o) {
BlueprintBase bpt = instanciateBlueprint();
if (bpt == null) {
return null;
}
bpt = bpt.adjustToWorld(worldObj, pos, o);
if (bpt != null) {
if (getStackInSlot(0).getItem() instanceof ItemBlueprintStandard) {
return new BptBuilderBlueprint((Blueprint) bpt, worldObj, pos);
} else if (getStackInSlot(0).getItem() instanceof ItemBlueprintTemplate) {
return new BptBuilderTemplate(bpt, worldObj, pos);
}
}
return null;
}
Aggregations