Search in sources :

Example 1 with GateLogic

use of buildcraft.transport.gate.GateLogic in project BuildCraft by BuildCraft.

the class GuiGate method preLoad.

protected void preLoad(BuildCraftJsonGui json) {
    GateLogic gate = container.gate;
    TypedKeyMap<String, Object> properties = json.properties;
    FunctionContext context = json.context;
    properties.put("statement.container", gate);
    context.putConstantBoolean("gate.two_columns", gate.isSplitInTwo());
    context.putConstantLong("gate.slots", gate.variant.numSlots);
    context.putConstantLong("gate.triggers.args", gate.variant.numTriggerArgs);
    context.putConstantLong("gate.actions.args", gate.variant.numActionArgs);
    context.put_b("gate.two_columns", () -> gate.isOn);
    context.putConstant("gate.material", String.class, gate.variant.material.tag);
    context.putConstant("gate.modifier", String.class, gate.variant.modifier.tag);
    context.putConstant("gate.logic", String.class, gate.variant.logic.tag);
    context.putConstant("gate.variant", String.class, gate.variant.getLocalizedName());
    properties.put("gate.triggers.possible", container.possibleTriggersContext);
    properties.put("gate.actions.possible", container.possibleActionsContext);
    context.put_l_b("gate.is_connected", (i) -> {
        if (i < 0 || i >= gate.connections.length) {
            return false;
        }
        return gate.connections[(int) i];
    }).setNeverInline();
    context.put_l_b("gate.trigger.is_on", (i) -> {
        if (i < 0 || i >= gate.triggerOn.length) {
            return false;
        }
        return gate.triggerOn[(int) i];
    }).setNeverInline();
    context.put_l_b("gate.set.is_on", (i) -> {
        if (i < 0 || i >= gate.triggerOn.length) {
            return false;
        }
        return gate.actionOn[(int) i];
    }).setNeverInline();
    context.put_l_b("gate.action.is_on", (i) -> {
        if (i < 0 || i >= gate.actionOn.length) {
            return false;
        }
        return gate.actionOn[(int) i] && gate.statements[(int) i].action.get() != null;
    }).setNeverInline();
    for (int s = 0; s < gate.variant.numSlots; s++) {
        final int i = s;
        String tName = "gate.trigger/" + i;
        String aName = "gate.action/" + i;
        properties.put(tName, gate.statements[i].trigger);
        properties.put(aName, gate.statements[i].action);
        properties.put(tName, container.possibleTriggersContext);
        properties.put(aName, container.possibleActionsContext);
    }
    for (int c = 0; c < gate.connections.length; c++) {
        final int connection = c;
        String name = "gate.connection/" + c;
        properties.put(name, gate.connections[c]);
        properties.put(name, IButtonBehaviour.TOGGLE);
        properties.put(name, (IButtonClickEventListener) (b, k) -> {
            container.setConnected(connection, b.isButtonActive());
        });
    }
}
Also used : GuiBC8(buildcraft.lib.gui.GuiBC8) ContainerGate(buildcraft.transport.container.ContainerGate) MessageUtil(buildcraft.lib.misc.MessageUtil) ResourceLocation(net.minecraft.util.ResourceLocation) IButtonClickEventListener(buildcraft.lib.gui.button.IButtonClickEventListener) BuildCraftJsonGui(buildcraft.lib.gui.json.BuildCraftJsonGui) GateLogic(buildcraft.transport.gate.GateLogic) FunctionContext(buildcraft.lib.expression.FunctionContext) IButtonBehaviour(buildcraft.lib.gui.button.IButtonBehaviour) TypedKeyMap(buildcraft.lib.misc.collect.TypedKeyMap) FunctionContext(buildcraft.lib.expression.FunctionContext) GateLogic(buildcraft.transport.gate.GateLogic)

Aggregations

FunctionContext (buildcraft.lib.expression.FunctionContext)1 GuiBC8 (buildcraft.lib.gui.GuiBC8)1 IButtonBehaviour (buildcraft.lib.gui.button.IButtonBehaviour)1 IButtonClickEventListener (buildcraft.lib.gui.button.IButtonClickEventListener)1 BuildCraftJsonGui (buildcraft.lib.gui.json.BuildCraftJsonGui)1 MessageUtil (buildcraft.lib.misc.MessageUtil)1 TypedKeyMap (buildcraft.lib.misc.collect.TypedKeyMap)1 ContainerGate (buildcraft.transport.container.ContainerGate)1 GateLogic (buildcraft.transport.gate.GateLogic)1 ResourceLocation (net.minecraft.util.ResourceLocation)1