Search in sources :

Example 16 with CommandWriter

use of buildcraft.core.lib.network.command.CommandWriter in project BuildCraft by BuildCraft.

the class GuiFiller method actionPerformed.

@Override
protected void actionPerformed(GuiButton button) throws IOException {
    super.actionPerformed(button);
    if (button.id == 0 && !filler.isPatternLocked()) {
        filler.currentPattern = (FillerPattern) FillerManager.registry.getPreviousPattern(filler.currentPattern);
    } else if (button.id == 1 && !filler.isPatternLocked()) {
        filler.currentPattern = (FillerPattern) FillerManager.registry.getNextPattern(filler.currentPattern);
    } else if (button.id == 2) {
        filler.setExcavate(!filler.isExcavate());
        buttonList.set(2, getExcavateButton());
        BuildCraftCore.instance.sendToServer(new PacketCommand(filler, "setFlags", new CommandWriter() {

            @Override
            public void write(ByteBuf data) {
                data.writeBoolean(filler.isExcavate());
            }
        }));
    }
    filler.rpcSetPatternFromString(filler.currentPattern.getUniqueTag());
}
Also used : PacketCommand(buildcraft.core.lib.network.command.PacketCommand) CommandWriter(buildcraft.core.lib.network.command.CommandWriter) ByteBuf(io.netty.buffer.ByteBuf) FillerPattern(buildcraft.core.builders.patterns.FillerPattern)

Example 17 with CommandWriter

use of buildcraft.core.lib.network.command.CommandWriter in project BuildCraft by BuildCraft.

the class TileBlueprintLibrary method selectBlueprint.

public void selectBlueprint(int index) {
    selected = index;
    BuildCraftCore.instance.sendToServer(new PacketCommand(this, "selectBlueprint", new CommandWriter() {

        @Override
        public void write(ByteBuf data) {
            data.writeInt(selected);
        }
    }));
}
Also used : PacketCommand(buildcraft.core.lib.network.command.PacketCommand) CommandWriter(buildcraft.core.lib.network.command.CommandWriter) ByteBuf(io.netty.buffer.ByteBuf)

Example 18 with CommandWriter

use of buildcraft.core.lib.network.command.CommandWriter in project BuildCraft by BuildCraft.

the class TileBlueprintLibrary method receiveCommand.

@Override
public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) {
    if (side.isClient()) {
        if ("requestSelectedBlueprint".equals(command)) {
            if (isOutputConsistent()) {
                if (selected > -1 && selected < entries.size()) {
                    // Work around 32k max limit on client->server
                    final NBTTagCompound compound = BuildCraftBuilders.clientDB.load(entries.get(selected));
                    compound.setString("__filename", entries.get(selected).name);
                    final byte[] bptData = NBTUtilBC.save(compound);
                    final int chunks = (bptData.length + CHUNK_SIZE - 1) / CHUNK_SIZE;
                    BuildCraftCore.instance.sendToServer(new PacketCommand(this, "uploadServerBegin", new CommandWriter() {

                        @Override
                        public void write(ByteBuf data) {
                            entries.get(selected).writeData(data);
                            data.writeShort(chunks);
                        }
                    }));
                    for (int i = 0; i < chunks; i++) {
                        final int chunk = i;
                        final int start = CHUNK_SIZE * chunk;
                        final int length = Math.min(CHUNK_SIZE, bptData.length - start);
                        BuildCraftCore.instance.sendToServer(new PacketCommand(this, "uploadServerChunk", new CommandWriter() {

                            @Override
                            public void write(ByteBuf data) {
                                data.writeShort(chunk);
                                data.writeShort(length);
                                data.writeBytes(bptData, start, length);
                            }
                        }));
                    }
                    BuildCraftCore.instance.sendToServer(new PacketCommand(this, "uploadServerEnd", null));
                } else {
                    BuildCraftCore.instance.sendToServer(new PacketCommand(this, "uploadNothingToServer", null));
                }
            }
        } else if ("downloadBlueprintToClient".equals(command)) {
            LibraryId id = new LibraryId();
            id.readData(stream);
            byte[] data = NetworkUtils.readByteArray(stream);
            try {
                LibraryTypeHandler handler = LibraryAPI.getHandlerFor(id.extension);
                if (handler == null) {
                    return;
                }
                NBTTagCompound nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(data));
                BuildCraftBuilders.clientDB.add(id, nbt);
                entries = BuildCraftBuilders.clientDB.getBlueprintIds();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    } else if (side.isServer()) {
        if ("uploadNothingToServer".equals(command)) {
            setInventorySlotContents(3, getStackInSlot(2));
            setInventorySlotContents(2, null);
            downloadingPlayer = null;
        } else if ("uploadServerBegin".equals(command)) {
            blueprintDownloadId = new LibraryId();
            blueprintDownloadId.readData(stream);
            blueprintDownload = new byte[CHUNK_SIZE * stream.readUnsignedShort()];
        } else if ("uploadServerChunk".equals(command)) {
            int start = stream.readUnsignedShort() * CHUNK_SIZE;
            int length = stream.readUnsignedShort();
            if (blueprintDownload != null) {
                stream.readBytes(blueprintDownload, start, length);
            } else {
                stream.skipBytes(length);
            }
        } else if ("uploadServerEnd".equals(command)) {
            try {
                LibraryTypeHandler handler = LibraryAPI.getHandlerFor(blueprintDownloadId.extension);
                if (handler != null) {
                    ItemStack output = null;
                    if (handler instanceof LibraryTypeHandlerNBT) {
                        NBTTagCompound nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(blueprintDownload));
                        output = ((LibraryTypeHandlerNBT) handler).load(getStackInSlot(2), nbt);
                    } else if (handler instanceof LibraryTypeHandlerByteArray) {
                        output = ((LibraryTypeHandlerByteArray) handler).load(getStackInSlot(2), blueprintDownload);
                    }
                    if (output != null) {
                        setInventorySlotContents(3, output);
                        setInventorySlotContents(2, null);
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            blueprintDownloadId = null;
            blueprintDownload = null;
            downloadingPlayer = null;
        } else if ("selectBlueprint".equals(command)) {
            selected = stream.readInt();
        }
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PacketCommand(buildcraft.core.lib.network.command.PacketCommand) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf) LibraryId(buildcraft.core.blueprints.LibraryId) LibraryTypeHandlerByteArray(buildcraft.api.library.LibraryTypeHandlerByteArray) ByteArrayInputStream(java.io.ByteArrayInputStream) LibraryTypeHandlerNBT(buildcraft.api.library.LibraryTypeHandlerNBT) LibraryTypeHandler(buildcraft.api.library.LibraryTypeHandler) CommandWriter(buildcraft.core.lib.network.command.CommandWriter) ItemStack(net.minecraft.item.ItemStack)

Example 19 with CommandWriter

use of buildcraft.core.lib.network.command.CommandWriter in project BuildCraft by BuildCraft.

the class TileBuilder method getItemRequirementsPacket.

private Packet getItemRequirementsPacket(List<RequirementItemStack> itemsIn) {
    if (itemsIn != null) {
        final List<RequirementItemStack> items = new ArrayList<>();
        items.addAll(itemsIn);
        return new PacketCommand(this, "setItemRequirements", new CommandWriter() {

            @Override
            public void write(ByteBuf data) {
                data.writeMedium(items.size());
                for (RequirementItemStack rb : items) {
                    data.writeShort(Item.getIdFromItem(rb.stack.getItem()));
                    data.writeShort(rb.stack.getItemDamage());
                    data.writeMedium((rb.stack.hasTagCompound() ? 0x800000 : 0x000000) | Math.min(0x7FFFFF, rb.size));
                    if (rb.stack.hasTagCompound()) {
                        NetworkUtils.writeNBT(data, rb.stack.getTagCompound());
                    }
                }
            }
        });
    } else {
        return new PacketCommand(this, "clearItemRequirements", null);
    }
}
Also used : RequirementItemStack(buildcraft.core.blueprints.RequirementItemStack) ArrayList(java.util.ArrayList) PacketCommand(buildcraft.core.lib.network.command.PacketCommand) CommandWriter(buildcraft.core.lib.network.command.CommandWriter) ByteBuf(io.netty.buffer.ByteBuf)

Example 20 with CommandWriter

use of buildcraft.core.lib.network.command.CommandWriter in project BuildCraft by BuildCraft.

the class ContainerGateInterface method getStatementParameterPacket.

public Packet getStatementParameterPacket(final String name, final int slot, final int paramSlot, final IStatementParameter parameter) {
    final String parameterName = parameter != null ? parameter.getUniqueTag() : null;
    final NBTTagCompound parameterNBT = new NBTTagCompound();
    if (parameter != null) {
        parameter.writeToNBT(parameterNBT);
    }
    return new PacketCommand(this, name, new CommandWriter() {

        @Override
        public void write(ByteBuf data) {
            data.writeByte(slot);
            data.writeByte(paramSlot);
            NetworkUtils.writeUTF(data, parameterName);
            NetworkUtils.writeNBT(data, parameterNBT);
        }
    });
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PacketCommand(buildcraft.core.lib.network.command.PacketCommand) CommandWriter(buildcraft.core.lib.network.command.CommandWriter) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

CommandWriter (buildcraft.core.lib.network.command.CommandWriter)25 PacketCommand (buildcraft.core.lib.network.command.PacketCommand)25 ByteBuf (io.netty.buffer.ByteBuf)25 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 LibraryTypeHandler (buildcraft.api.library.LibraryTypeHandler)2 LibraryTypeHandlerByteArray (buildcraft.api.library.LibraryTypeHandlerByteArray)2 LibraryTypeHandlerNBT (buildcraft.api.library.LibraryTypeHandlerNBT)2 LibraryId (buildcraft.core.blueprints.LibraryId)2 ZonePlan (buildcraft.robotics.zone.ZonePlan)2 ItemStack (net.minecraft.item.ItemStack)2 IZone (buildcraft.api.core.IZone)1 IMapLocation (buildcraft.api.items.IMapLocation)1 IStatement (buildcraft.api.statements.IStatement)1 IStatementParameter (buildcraft.api.statements.IStatementParameter)1 RequirementItemStack (buildcraft.core.blueprints.RequirementItemStack)1 FillerPattern (buildcraft.core.builders.patterns.FillerPattern)1 Packet (buildcraft.core.lib.network.base.Packet)1 TileZonePlan (buildcraft.robotics.TileZonePlan)1 ContainerZonePlan (buildcraft.robotics.gui.ContainerZonePlan)1