Search in sources :

Example 1 with PacketCommand

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

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

the class ContainerGateInterface method receiveCommand.

@Override
public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) {
    if (side.isServer()) {
        EntityPlayer player = (EntityPlayer) sender;
        if ("initRequest".equals(command)) {
            final String[] triggerStrings = statementsToStrings(potentialTriggers);
            final String[] actionStrings = statementsToStrings(potentialActions);
            BuildCraftCore.instance.sendToPlayer(player, new PacketCommand(this, "init", new CommandWriter() {

                @Override
                public void write(ByteBuf data) {
                    data.writeByte(gate.getDirection().ordinal());
                    data.writeShort(triggerStrings.length);
                    data.writeShort(actionStrings.length);
                    for (String trigger : triggerStrings) {
                        NetworkUtils.writeUTF(data, trigger);
                    }
                    for (String action : actionStrings) {
                        NetworkUtils.writeUTF(data, action);
                    }
                }
            }));
        } else if ("selectionRequest".equals(command)) {
            for (int position = 0; position < gate.material.numSlots; position++) {
                IStatement action = gate.getAction(position);
                IStatement trigger = gate.getTrigger(position);
                BuildCraftCore.instance.sendToPlayer(player, getStatementPacket("setAction", position, action));
                BuildCraftCore.instance.sendToPlayer(player, getStatementPacket("setTrigger", position, trigger));
                for (int p = 0; p < gate.material.numActionParameters; ++p) {
                    BuildCraftCore.instance.sendToPlayer(player, getStatementParameterPacket("setActionParameter", position, p, gate.getActionParameter(position, p)));
                }
                for (int q = 0; q < gate.material.numTriggerParameters; ++q) {
                    BuildCraftCore.instance.sendToPlayer(player, getStatementParameterPacket("setTriggerParameter", position, q, gate.getTriggerParameter(position, q)));
                }
            }
        }
    } else if (side.isClient()) {
        if ("init".equals(command)) {
            setGate(stream.readByte());
            String[] triggerStrings = new String[stream.readShort()];
            String[] actionStrings = new String[stream.readShort()];
            for (int i = 0; i < triggerStrings.length; i++) {
                triggerStrings[i] = NetworkUtils.readUTF(stream);
            }
            for (int i = 0; i < actionStrings.length; i++) {
                actionStrings[i] = NetworkUtils.readUTF(stream);
            }
            stringsToStatements(this.potentialTriggers, triggerStrings);
            stringsToStatements(this.potentialActions, actionStrings);
        }
    }
    if ("setAction".equals(command)) {
        setAction(stream.readUnsignedByte(), NetworkUtils.readUTF(stream), false);
    } else if ("setTrigger".equals(command)) {
        setTrigger(stream.readUnsignedByte(), NetworkUtils.readUTF(stream), false);
    } else if ("setActionParameter".equals(command) || "setTriggerParameter".equals(command)) {
        int slot = stream.readUnsignedByte();
        int param = stream.readUnsignedByte();
        String parameterName = NetworkUtils.readUTF(stream);
        NBTTagCompound parameterData = NetworkUtils.readNBT(stream);
        IStatementParameter parameter = null;
        if (parameterName != null && parameterName.length() > 0) {
            parameter = StatementManager.createParameter(parameterName);
        }
        if (parameter != null) {
            parameter.readFromNBT(parameterData);
            if ("setActionParameter".equals(command)) {
                setActionParameter(slot, param, parameter, false);
            } else {
                setTriggerParameter(slot, param, parameter, false);
            }
        }
    }
}
Also used : PacketCommand(buildcraft.core.lib.network.command.PacketCommand) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IStatementParameter(buildcraft.api.statements.IStatementParameter) CommandWriter(buildcraft.core.lib.network.command.CommandWriter) ByteBuf(io.netty.buffer.ByteBuf) IStatement(buildcraft.api.statements.IStatement)

Example 3 with PacketCommand

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

the class EntityRobot method updateClientSlot.

public void updateClientSlot(final int slot) {
    BuildCraftCore.instance.sendToEntity(new PacketCommand(this, "clientSetInventory", new CommandWriter() {

        @Override
        public void write(ByteBuf data) {
            data.writeShort(slot);
            NetworkUtils.writeStack(data, inv[slot]);
        }
    }), this);
}
Also used : PacketCommand(buildcraft.core.lib.network.command.PacketCommand) CommandWriter(buildcraft.core.lib.network.command.CommandWriter) ByteBuf(io.netty.buffer.ByteBuf)

Example 4 with PacketCommand

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

the class TileZonePlan method importMap.

private void importMap(ItemStack stack) {
    if (stack != null && stack.getItem() instanceof IMapLocation) {
        final IZone zone = ((IMapLocation) stack.getItem()).getZone(stack);
        if (zone != null && zone instanceof ZonePlan) {
            selectedAreas[currentSelectedArea] = (ZonePlan) zone;
            for (EntityPlayerMP e : MinecraftServer.getServer().getConfigurationManager().playerEntityList) {
                if (e.openContainer != null && e.openContainer instanceof ContainerZonePlan && ((ContainerZonePlan) e.openContainer).getTile() == this) {
                    Packet p = new PacketCommand(e.openContainer, "areaLoaded", new CommandWriter() {

                        @Override
                        public void write(ByteBuf data) {
                            ((ZonePlan) zone).writeData(data);
                        }
                    });
                    BuildCraftCore.instance.sendToPlayer(e, p);
                }
            }
        }
    }
}
Also used : Packet(buildcraft.core.lib.network.base.Packet) ContainerZonePlan(buildcraft.robotics.gui.ContainerZonePlan) ZonePlan(buildcraft.robotics.zone.ZonePlan) IMapLocation(buildcraft.api.items.IMapLocation) PacketCommand(buildcraft.core.lib.network.command.PacketCommand) IZone(buildcraft.api.core.IZone) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ContainerZonePlan(buildcraft.robotics.gui.ContainerZonePlan) CommandWriter(buildcraft.core.lib.network.command.CommandWriter) ByteBuf(io.netty.buffer.ByteBuf)

Example 5 with PacketCommand

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

the class ContainerZonePlan method receiveCommand.

@Override
public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) {
    if (side.isClient()) {
        if ("areaLoaded".equals(command)) {
            currentAreaSelection = new ZonePlan();
            currentAreaSelection.readData(stream);
            gui.refreshSelectedArea();
        } else if ("receiveImage".equals(command)) {
            int size = stream.readUnsignedMedium();
            int pos = stream.readUnsignedMedium();
            for (int i = 0; i < Math.min(size - pos, MAX_PACKET_LENGTH); ++i) {
                mapTexture.colorMap[pos + i] = 0xFF000000 | MapColor.mapColorArray[stream.readUnsignedByte()].colorValue;
            }
        }
    } else if (side.isServer()) {
        if ("loadArea".equals(command)) {
            final int index = stream.readUnsignedByte();
            BuildCraftCore.instance.sendToPlayer((EntityPlayer) sender, new PacketCommand(this, "areaLoaded", new CommandWriter() {

                @Override
                public void write(ByteBuf data) {
                    map.selectArea(index).writeData(data);
                }
            }));
        } else if ("saveArea".equals(command)) {
            final int index = stream.readUnsignedByte();
            ZonePlan plan = new ZonePlan();
            plan.readData(stream);
            map.setArea(index, plan);
        } else if ("computeMap".equals(command)) {
            computeMap(stream.readInt(), stream.readInt(), stream.readUnsignedShort(), stream.readUnsignedShort(), stream.readFloat(), (EntityPlayer) sender);
        } else if ("setName".equals(command)) {
            map.mapName = NetworkUtils.readUTF(stream);
        }
    }
}
Also used : TileZonePlan(buildcraft.robotics.TileZonePlan) ZonePlan(buildcraft.robotics.zone.ZonePlan) 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)

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