Search in sources :

Example 11 with CommandWriter

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

the class EntityRobot method setSteamDirection.

private void setSteamDirection(final Vec3d direction) {
    if (!worldObj.isRemote) {
        BuildCraftCore.instance.sendToEntity(new PacketCommand(this, "setSteamDirection", new CommandWriter() {

            @Override
            public void write(ByteBuf data) {
                data.writeDouble(direction.xCoord);
                data.writeDouble(direction.yCoord);
                data.writeDouble(direction.zCoord);
            }
        }), this);
    } else {
        steamDirection = direction.normalize();
    }
}
Also used : PacketCommand(buildcraft.core.lib.network.command.PacketCommand) CommandWriter(buildcraft.core.lib.network.command.CommandWriter) ByteBuf(io.netty.buffer.ByteBuf)

Example 12 with CommandWriter

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

the class EntityRobot method setItemActive.

@Override
public void setItemActive(final boolean isActive) {
    if (isActive != itemActive) {
        itemActive = isActive;
        BuildCraftCore.instance.sendToEntity(new PacketCommand(this, "setItemActive", new CommandWriter() {

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

Example 13 with CommandWriter

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

the class EntityRobot method receiveCommand.

@Override
public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) {
    if (side.isClient()) {
        if ("clientSetItemInUse".equals(command)) {
            itemInUse = NetworkUtils.readStack(stream);
        } else if ("clientSetInventory".equals(command)) {
            int slot = stream.readUnsignedShort();
            inv[slot] = NetworkUtils.readStack(stream);
        } else if ("initialize".equals(command)) {
            itemInUse = NetworkUtils.readStack(stream);
            itemActive = stream.readBoolean();
        } else if ("setItemActive".equals(command)) {
            itemActive = stream.readBoolean();
            itemActiveStage = 0;
            lastUpdateTime = new Date().getTime();
            if (!itemActive) {
                setSteamDirection(new Vec3d(0, -1, 0));
            }
        } else if ("setSteamDirection".equals(command)) {
            setSteamDirection(new Vec3d(stream.readDouble(), stream.readDouble(), stream.readDouble()));
        } else if ("syncWearables".equals(command)) {
            wearables.clear();
            int amount = stream.readUnsignedByte();
            while (amount > 0) {
                wearables.add(NetworkUtils.readStack(stream));
                amount--;
            }
        }
    } else if (side.isServer()) {
        EntityPlayer p = (EntityPlayer) sender;
        if ("requestInitialization".equals(command)) {
            BuildCraftCore.instance.sendToPlayer(p, new PacketCommand(this, "initialize", new CommandWriter() {

                @Override
                public void write(ByteBuf data) {
                    NetworkUtils.writeStack(data, itemInUse);
                    data.writeBoolean(itemActive);
                }
            }));
            for (int i = 0; i < inv.length; ++i) {
                final int j = i;
                BuildCraftCore.instance.sendToPlayer(p, new PacketCommand(this, "clientSetInventory", new CommandWriter() {

                    @Override
                    public void write(ByteBuf data) {
                        data.writeShort(j);
                        NetworkUtils.writeStack(data, inv[j]);
                    }
                }));
            }
            if (currentDockingStation != null) {
                setSteamDirection(Utils.convert(currentDockingStation.side()));
            } else {
                setSteamDirection(new Vec3d(0, -1, 0));
            }
        }
    }
}
Also used : PacketCommand(buildcraft.core.lib.network.command.PacketCommand) EntityPlayer(net.minecraft.entity.player.EntityPlayer) CommandWriter(buildcraft.core.lib.network.command.CommandWriter) ByteBuf(io.netty.buffer.ByteBuf) Date(java.util.Date) Vec3d(net.minecraft.util.math.Vec3d)

Example 14 with CommandWriter

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

the class ContainerRefinery method setFilter.

/* SETTING AND GETTING FILTERS */
public void setFilter(final int slot, final Fluid filter) {
    refinery.setFilter(slot, filter);
    if (refinery.getWorld().isRemote) {
        CommandWriter payload = new CommandWriter() {

            @Override
            public void write(ByteBuf data) {
                data.writeByte(slot);
                data.writeShort(filter != null ? filter.getID() : -1);
            }
        };
        BuildCraftFactory.instance.sendToServer(new PacketCommand(refinery, "setFilter", payload));
    }
}
Also used : PacketCommand(buildcraft.core.lib.network.command.PacketCommand) CommandWriter(buildcraft.core.lib.network.command.CommandWriter) ByteBuf(io.netty.buffer.ByteBuf)

Example 15 with CommandWriter

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

the class GuiArchitectOld method keyTyped.

@Override
protected void keyTyped(char c, int i) throws IOException {
    if (textField.isFocused()) {
        if (c == 13 || c == 27) {
            textField.setFocused(false);
        } else {
            textField.textboxKeyTyped(c, i);
            final String text = textField.getText();
            BuildCraftCore.instance.sendToServer(new PacketCommand(architect, "setName", new CommandWriter() {

                @Override
                public void write(ByteBuf data) {
                    NetworkUtils.writeUTF(data, text);
                }
            }));
        }
    } else {
        super.keyTyped(c, i);
    }
}
Also used : 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