Search in sources :

Example 26 with PacketCommand

use of buildcraft.core.lib.network.command.PacketCommand 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 27 with PacketCommand

use of buildcraft.core.lib.network.command.PacketCommand 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 28 with PacketCommand

use of buildcraft.core.lib.network.command.PacketCommand 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

PacketCommand (buildcraft.core.lib.network.command.PacketCommand)28 CommandWriter (buildcraft.core.lib.network.command.CommandWriter)25 ByteBuf (io.netty.buffer.ByteBuf)25 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 ItemStack (net.minecraft.item.ItemStack)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 RequirementItemStack (buildcraft.core.blueprints.RequirementItemStack)2 ZonePlan (buildcraft.robotics.zone.ZonePlan)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 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