Search in sources :

Example 1 with LibraryId

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();
}
Also used : LibraryId(buildcraft.core.blueprints.LibraryId) BptBuilderBlueprint(buildcraft.core.blueprints.BptBuilderBlueprint) BptContext(buildcraft.core.blueprints.BptContext) Vec3d(net.minecraft.util.math.Vec3d)

Example 2 with LibraryId

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;
    }
}
Also used : LibraryId(buildcraft.core.blueprints.LibraryId) LibraryTypeHandlerByteArray(buildcraft.api.library.LibraryTypeHandlerByteArray) LibraryTypeHandlerNBT(buildcraft.api.library.LibraryTypeHandlerNBT) LibraryTypeHandler(buildcraft.api.library.LibraryTypeHandler) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PacketCommand(buildcraft.core.lib.network.command.PacketCommand) CommandWriter(buildcraft.core.lib.network.command.CommandWriter) ByteBuf(io.netty.buffer.ByteBuf)

Example 3 with LibraryId

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;
}
Also used : BlueprintBase(buildcraft.core.blueprints.BlueprintBase) LibraryId(buildcraft.core.blueprints.LibraryId) Blueprint(buildcraft.core.blueprints.Blueprint) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IBlueprintItem(buildcraft.api.items.IBlueprintItem) Template(buildcraft.core.blueprints.Template)

Example 4 with LibraryId

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;
}
Also used : LibraryId(buildcraft.core.blueprints.LibraryId) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 5 with LibraryId

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()]);
    }
}
Also used : LibraryId(buildcraft.core.blueprints.LibraryId)

Aggregations

LibraryId (buildcraft.core.blueprints.LibraryId)7 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 LibraryTypeHandler (buildcraft.api.library.LibraryTypeHandler)2 LibraryTypeHandlerByteArray (buildcraft.api.library.LibraryTypeHandlerByteArray)2 LibraryTypeHandlerNBT (buildcraft.api.library.LibraryTypeHandlerNBT)2 CommandWriter (buildcraft.core.lib.network.command.CommandWriter)2 PacketCommand (buildcraft.core.lib.network.command.PacketCommand)2 ByteBuf (io.netty.buffer.ByteBuf)2 IBlueprintItem (buildcraft.api.items.IBlueprintItem)1 Blueprint (buildcraft.core.blueprints.Blueprint)1 BlueprintBase (buildcraft.core.blueprints.BlueprintBase)1 BptBuilderBlueprint (buildcraft.core.blueprints.BptBuilderBlueprint)1 BptContext (buildcraft.core.blueprints.BptContext)1 Template (buildcraft.core.blueprints.Template)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ItemStack (net.minecraft.item.ItemStack)1 Vec3d (net.minecraft.util.math.Vec3d)1