Search in sources :

Example 21 with CommandWriter

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

the class TileAssemblyTable method rpcSelectRecipe.

public void rpcSelectRecipe(final String id, final boolean select) {
    BuildCraftCore.instance.sendToServer(new PacketCommand(this, "select", new CommandWriter() {

        @Override
        public void write(ByteBuf data) {
            NetworkUtils.writeUTF(data, id);
            data.writeBoolean(select);
        }
    }));
}
Also used : PacketCommand(buildcraft.core.lib.network.command.PacketCommand) CommandWriter(buildcraft.core.lib.network.command.CommandWriter) ByteBuf(io.netty.buffer.ByteBuf)

Example 22 with CommandWriter

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

the class ContainerZonePlan method saveArea.

public void saveArea(final int index) {
    BuildCraftCore.instance.sendToServer(new PacketCommand(this, "saveArea", new CommandWriter() {

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

Example 23 with CommandWriter

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

the class ContainerZonePlan method computeMap.

private void computeMap(int cx, int cz, int width, int height, float blocksPerPixel, EntityPlayer player) {
    final byte[] textureData = new byte[width * height];
    MapWorld w = BuildCraftRobotics.manager.getWorld(map.getWorld());
    int startX = Math.round(cx - width * blocksPerPixel / 2);
    int startZ = Math.round(cz - height * blocksPerPixel / 2);
    int mapStartX = map.chunkStartX << 4;
    int mapStartZ = map.chunkStartZ << 4;
    for (int j = 0; j < height; ++j) {
        for (int i = 0; i < width; ++i) {
            int x = Math.round(startX + i * blocksPerPixel);
            int z = Math.round(startZ + j * blocksPerPixel);
            int ix = x - mapStartX;
            int iz = z - mapStartZ;
            if (ix >= 0 && iz >= 0 && ix < TileZonePlan.RESOLUTION && iz < TileZonePlan.RESOLUTION) {
                textureData[i + j * width] = (byte) w.getColor(x, z);
            }
        }
    }
    final int len = MAX_PACKET_LENGTH;
    for (int i = 0; i < textureData.length; i += len) {
        final int pos = i;
        BuildCraftCore.instance.sendToPlayer(player, new PacketCommand(this, "receiveImage", new CommandWriter() {

            @Override
            public void write(ByteBuf data) {
                data.writeMedium(textureData.length);
                data.writeMedium(pos);
                data.writeBytes(textureData, pos, Math.min(textureData.length - pos, len));
            }
        }));
    }
}
Also used : MapWorld(buildcraft.robotics.map.MapWorld) PacketCommand(buildcraft.core.lib.network.command.PacketCommand) CommandWriter(buildcraft.core.lib.network.command.CommandWriter) ByteBuf(io.netty.buffer.ByteBuf)

Example 24 with CommandWriter

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

the class TileRequester method setRequest.

public void setRequest(final int index, final ItemStack stack) {
    if (worldObj.isRemote) {
        BuildCraftCore.instance.sendToServer(new PacketCommand(this, "setRequest", new CommandWriter() {

            @Override
            public void write(ByteBuf data) {
                data.writeByte(index);
                NetworkUtils.writeStack(data, stack);
            }
        }));
    } else {
        requests.setInventorySlotContents(index, stack);
    }
}
Also used : PacketCommand(buildcraft.core.lib.network.command.PacketCommand) CommandWriter(buildcraft.core.lib.network.command.CommandWriter) ByteBuf(io.netty.buffer.ByteBuf)

Example 25 with CommandWriter

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

the class ContainerRequester method receiveCommand.

@Override
public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) {
    if (side.isServer() && "getRequestList".equals(command)) {
        final ItemStack[] stacks = new ItemStack[TileRequester.NB_ITEMS];
        for (int i = 0; i < TileRequester.NB_ITEMS; ++i) {
            stacks[i] = requester.getRequestTemplate(i);
        }
        BuildCraftCore.instance.sendToPlayer((EntityPlayer) sender, new PacketCommand(this, "receiveRequestList", new CommandWriter() {

            @Override
            public void write(ByteBuf data) {
                for (ItemStack s : stacks) {
                    NetworkUtils.writeStack(data, s);
                }
            }
        }));
    } else if (side.isClient() && "receiveRequestList".equals(command)) {
        requests = new ItemStack[TileRequester.NB_ITEMS];
        for (int i = 0; i < TileRequester.NB_ITEMS; i++) {
            requests[i] = NetworkUtils.readStack(stream);
        }
    }
}
Also used : PacketCommand(buildcraft.core.lib.network.command.PacketCommand) ItemStack(net.minecraft.item.ItemStack) 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