Search in sources :

Example 1 with IStatement

use of buildcraft.api.statements.IStatement in project BuildCraft by BuildCraft.

the class GuiElementStatement method onMouseClicked.

// IInteractionElement
@Override
public void onMouseClicked(int button) {
    if (!contains(gui.mouse)) {
        return;
    }
    if (ref.canInteract && button == 0) {
        if (GuiScreen.isShiftKeyDown()) {
            set(null);
            return;
        }
        S s = get();
        if (s == null) {
            return;
        }
        List<IStatement> possible = new ArrayList<>();
        Collections.addAll(possible, s.getPossible());
        if (!s.isPossibleOrdered()) {
            List<IStatement> list = new ArrayList<>();
            list.add(null);
            for (IStatement p2 : possible) {
                if (p2 != null) {
                    list.add(p2);
                }
            }
            possible = list;
        }
        if (ctx != null) {
            possible.removeIf(f -> {
                for (StatementGroup<?> group : ctx.getAllPossible()) {
                    if (group.getValues().contains(f)) {
                        return false;
                    }
                }
                return true;
            });
        }
        gui.currentMenu = GuiElementStatementVariant.create(gui, this, this, possible.toArray(new IStatement[0]));
    }
}
Also used : ArrayList(java.util.ArrayList) IStatement(buildcraft.api.statements.IStatement)

Example 2 with IStatement

use of buildcraft.api.statements.IStatement in project BuildCraft by BuildCraft.

the class GuiElementStatementParam method drawBackground.

// IGuiElement
@Override
public void drawBackground(float partialTicks) {
    if (draw) {
        IStatement slot = ref.get();
        int max = slot == null ? 0 : slot.maxParameters();
        double x = getX();
        double y = getY();
        if (paramIndex >= max) {
            GuiElementStatement.SLOT_COLOUR.drawAt(x, y);
            GuiElementStatement.ICON_SLOT_BLOCKED.drawAt(x, y);
            return;
        }
        IStatementParameter statementParameter = get();
        GuiElementStatementSource.drawGuiSlot(statementParameter, x, y);
    }
}
Also used : IStatementParameter(buildcraft.api.statements.IStatementParameter) IStatement(buildcraft.api.statements.IStatement)

Example 3 with IStatement

use of buildcraft.api.statements.IStatement in project BuildCraft by BuildCraft.

the class ActionType method readFromBuffer.

@Override
public ActionWrapper readFromBuffer(PacketBufferBC buffer) throws IOException {
    if (buffer.readBoolean()) {
        String name = buffer.readString();
        EnumPipePart part = buffer.readEnumValue(EnumPipePart.class);
        IStatement statement = StatementManager.statements.get(name);
        if (statement instanceof IAction) {
            return ActionWrapper.wrap(statement, part.face);
        } else {
            throw new InvalidInputDataException("Unknown action '" + name + "'");
        }
    } else {
        return null;
    }
}
Also used : InvalidInputDataException(buildcraft.api.core.InvalidInputDataException) IAction(buildcraft.api.statements.IAction) EnumPipePart(buildcraft.api.core.EnumPipePart) IStatement(buildcraft.api.statements.IStatement)

Example 4 with IStatement

use of buildcraft.api.statements.IStatement in project BuildCraft by BuildCraft.

the class TriggerType method readFromBuffer.

@Override
public TriggerWrapper readFromBuffer(PacketBufferBC buffer) throws IOException {
    if (buffer.readBoolean()) {
        String name = buffer.readString();
        EnumPipePart part = buffer.readEnumValue(EnumPipePart.class);
        IStatement statement = StatementManager.statements.get(name);
        if (statement instanceof ITrigger) {
            return TriggerWrapper.wrap(statement, part.face);
        } else {
            throw new InvalidInputDataException("Unknown trigger '" + name + "'");
        }
    } else {
        return null;
    }
}
Also used : InvalidInputDataException(buildcraft.api.core.InvalidInputDataException) EnumPipePart(buildcraft.api.core.EnumPipePart) IStatement(buildcraft.api.statements.IStatement) ITrigger(buildcraft.api.statements.ITrigger)

Example 5 with IStatement

use of buildcraft.api.statements.IStatement 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)

Aggregations

IStatement (buildcraft.api.statements.IStatement)20 EnumPipePart (buildcraft.api.core.EnumPipePart)6 IStatementParameter (buildcraft.api.statements.IStatementParameter)5 IAction (buildcraft.api.statements.IAction)3 ITrigger (buildcraft.api.statements.ITrigger)3 AdvancedSlot (buildcraft.core.lib.gui.AdvancedSlot)3 StatementParameterSlot (buildcraft.core.lib.gui.StatementParameterSlot)3 InvalidInputDataException (buildcraft.api.core.InvalidInputDataException)2 StatementSlot (buildcraft.core.lib.gui.StatementSlot)2 ArrayList (java.util.ArrayList)2 IGate (buildcraft.api.gates.IGate)1 ITriggerExternalOverride (buildcraft.api.statements.ITriggerExternalOverride)1 StatementManager (buildcraft.api.statements.StatementManager)1 StatementMouseClick (buildcraft.api.statements.StatementMouseClick)1 StatementSlot (buildcraft.api.statements.StatementSlot)1 CommandWriter (buildcraft.core.lib.network.command.CommandWriter)1 PacketCommand (buildcraft.core.lib.network.command.PacketCommand)1 BCLib (buildcraft.lib.BCLib)1 GuiGuide (buildcraft.lib.client.guide.GuiGuide)1 GuideManager (buildcraft.lib.client.guide.GuideManager)1