use of buildcraft.core.blueprints.LibraryId in project BuildCraft by BuildCraft.
the class RealBlueprintDeployer method deployBlueprint.
public void deployBlueprint(World world, BlockPos pos, EnumFacing dir, Blueprint bpt) {
bpt.id = new LibraryId();
bpt.id.extension = "bpt";
BptContext context = bpt.getContext(world, bpt.getBoxForPos(pos));
if (bpt.rotate) {
if (dir == EnumFacing.EAST) {
// Do nothing
} else if (dir == EnumFacing.SOUTH) {
bpt.rotateLeft(context);
} else if (dir == EnumFacing.WEST) {
bpt.rotateLeft(context);
bpt.rotateLeft(context);
} else if (dir == EnumFacing.NORTH) {
bpt.rotateLeft(context);
bpt.rotateLeft(context);
bpt.rotateLeft(context);
}
}
Vec3d transform = Utils.convert(pos).subtract(Utils.convert(bpt.anchor));
bpt.translateToWorld(transform);
new BptBuilderBlueprint(bpt, world, pos).deploy();
}
use of buildcraft.core.blueprints.LibraryId in project BuildCraft by BuildCraft.
the class TileBlueprintLibrary method update.
@Override
public void update() {
super.update();
if (worldObj.isRemote) {
return;
}
if (progressIn > 0 && progressIn < PROGRESS_TIME) {
progressIn++;
}
if (progressOut > 0 && progressOut < PROGRESS_TIME) {
if (selected != -1) {
progressOut++;
} else {
progressOut = 1;
}
}
// client, and then store it to the client.
if (progressIn == 100 && getStackInSlot(1) == null) {
LibraryTypeHandler handler = findHandler(0, LibraryTypeHandler.HandlerType.STORE);
if (handler == null) {
uploadingPlayer = null;
return;
}
byte[] data = null;
if (handler instanceof LibraryTypeHandlerNBT) {
final NBTTagCompound nbt = new NBTTagCompound();
if (((LibraryTypeHandlerNBT) handler).store(getStackInSlot(0), nbt)) {
data = NBTUtilBC.save(nbt);
}
} else if (handler instanceof LibraryTypeHandlerByteArray) {
data = ((LibraryTypeHandlerByteArray) handler).store(getStackInSlot(0));
}
if (data == null) {
uploadingPlayer = null;
return;
}
setInventorySlotContents(1, getStackInSlot(0));
setInventorySlotContents(0, null);
final byte[] dataOut = data;
final LibraryId id = new LibraryId();
id.name = handler.getName(getStackInSlot(1));
id.extension = handler.getOutputExtension();
if (uploadingPlayer != null) {
BuildCraftCore.instance.sendToPlayer(uploadingPlayer, new PacketCommand(this, "downloadBlueprintToClient", new CommandWriter() {
@Override
public void write(ByteBuf data) {
id.generateUniqueId(dataOut);
id.writeData(data);
NetworkUtils.writeByteArray(data, dataOut);
}
}));
uploadingPlayer = null;
}
}
if (progressOut == 100 && getStackInSlot(3) == null) {
BuildCraftCore.instance.sendToPlayer(downloadingPlayer, new PacketCommand(this, "requestSelectedBlueprint", null));
progressOut = 0;
}
}
use of buildcraft.core.blueprints.LibraryId 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.LibraryId in project BuildCraft by BuildCraft.
the class LibraryBlueprintTypeHandler method store.
@Override
public boolean store(ItemStack stack, NBTTagCompound compound) {
LibraryId id = ItemBlueprint.getId(stack);
if (id == null) {
return false;
}
NBTTagCompound nbt = BuildCraftBuilders.serverDB.load(id);
if (nbt == null) {
return false;
}
for (Object o : nbt.getKeySet()) {
compound.setTag((String) o, nbt.getTag((String) o));
}
id.write(compound);
return true;
}
use of buildcraft.core.blueprints.LibraryId in project BuildCraft by BuildCraft.
the class LibraryDatabase method loadIndex.
private void loadIndex(File directory) {
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
int dotIndex = name.lastIndexOf('.') + 1;
String extension = name.substring(dotIndex);
return LibraryAPI.getHandlerFor(extension) != null;
}
};
if (directory.exists()) {
File[] files = directory.listFiles(filter);
if (files == null || files.length == 0) {
return;
}
for (File blueprintFile : files) {
String fileName = blueprintFile.getName();
LibraryId id = new LibraryId();
int sepIndex = fileName.lastIndexOf(LibraryId.BPT_SEP_CHARACTER);
int dotIndex = fileName.lastIndexOf('.');
if (dotIndex > 0) {
String extension = fileName.substring(dotIndex + 1);
if (sepIndex > 0) {
String prefix = fileName.substring(0, sepIndex);
String suffix = fileName.substring(sepIndex + 1);
id.name = prefix;
id.uniqueId = LibraryId.toBytes(suffix.substring(0, suffix.length() - (extension.length() + 1)));
} else {
id.name = fileName.substring(0, dotIndex);
id.uniqueId = new byte[0];
}
id.extension = extension;
if (!blueprintIds.contains(id)) {
blueprintIds.add(id);
}
} else {
BCLog.logger.warn("Found incorrectly named (no extension) blueprint file: '%s'!", fileName);
}
}
pages = blueprintIds.toArray(new LibraryId[blueprintIds.size()]);
}
}
Aggregations