Search in sources :

Example 11 with IStatement

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

the class DockingStationPipe method getRequest.

@Override
public ItemStack getRequest(int slot) {
    int facing = (slot & 0x70) >> 4;
    int action = (slot & 0xc) >> 2;
    int param = slot & 0x3;
    if (facing >= 6) {
        return null;
    }
    EnumFacing side = EnumFacing.getFront(facing);
    IGate gate = getPipe().getPipe().getGate(side);
    if (gate == null) {
        return null;
    }
    List<IStatement> actions = gate.getActions();
    if (actions.size() <= action) {
        return null;
    }
    if (actions.get(action) != BuildCraftRobotics.actionStationRequestItems) {
        return null;
    }
    List<StatementSlot> activeActions = gate.getActiveActions();
    StatementSlot slotStmt = null;
    for (StatementSlot stmt : activeActions) {
        if (stmt.statement == actions.get(action)) {
            slotStmt = stmt;
            break;
        }
    }
    if (slotStmt == null) {
        return null;
    }
    if (slotStmt.parameters.length <= param) {
        return null;
    }
    if (slotStmt.parameters[param] == null) {
        return null;
    }
    return slotStmt.parameters[param].getItemStack();
}
Also used : StatementSlot(buildcraft.api.statements.StatementSlot) IGate(buildcraft.api.gates.IGate) EnumFacing(net.minecraft.util.EnumFacing) IStatement(buildcraft.api.statements.IStatement)

Example 12 with IStatement

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

the class TriggerWrapper method getPossible.

@Override
public TriggerWrapper[] getPossible() {
    IStatement[] possible = delegate.getPossible();
    boolean andSides = sourcePart != EnumPipePart.CENTER;
    TriggerWrapper[] real = new TriggerWrapper[possible.length + (andSides ? 5 : 0)];
    for (int i = 0; i < possible.length; i++) {
        real[i] = wrap(possible[i], sourcePart.face);
    }
    if (andSides) {
        EnumPipePart part = sourcePart;
        for (int j = 0; j < 5; j++) {
            int i = j + possible.length;
            part = part.next();
            real[i] = wrap(delegate, part.face);
        }
    }
    return real;
}
Also used : EnumPipePart(buildcraft.api.core.EnumPipePart) IStatement(buildcraft.api.statements.IStatement) ITriggerExternalOverride(buildcraft.api.statements.ITriggerExternalOverride)

Example 13 with IStatement

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

the class GuidePageContents method loadMainGui.

public void loadMainGui() {
    TypeOrder order = GuiGuide.SORTING_TYPES[gui.sortingOrderIndex];
    contents.clear();
    quickSearcher = new SuffixArray<>();
    lastSearchText = "";
    Set<Item> itemsAdded = new HashSet<>();
    final String underline = TextFormatting.UNDERLINE.toString();
    for (PageEntry<?> entry : GuideManager.INSTANCE.getAllEntries()) {
        GuidePageFactory entryFactory = GuideManager.INSTANCE.getFactoryFor(entry);
        String[] ordered = entry.typeTags.getOrdered(order);
        String header = underline + LocaleUtil.localize(ordered[0]);
        String subHeader = underline + LocaleUtil.localize(ordered[1]);
        String translatedTitle = LocaleUtil.localize(entry.title);
        ISimpleDrawable icon = entry.createDrawable();
        PageLine line = new PageLine(icon, icon, 2, translatedTitle, true);
        GuideText text = new GuideText(gui, line);
        SubHeader pageHolder = contents.getOrAddSubHeader(header, subHeader);
        if (entryFactory == null) {
            if (entry.value instanceof ItemStackValueFilter) {
                ItemStack stack = ((ItemStackValueFilter) entry.value).stack.baseStack;
                itemsAdded.add(stack.getItem());
                PageLinkGenerated pageLink = pageHolder.addKnownPage(text, stack);
                if (pageLink != null) {
                    quickSearcher.add(pageLink, pageLink.joinedTooltip.toLowerCase(Locale.ROOT));
                }
            }
        } else {
            if (entry.value instanceof ItemStackValueFilter) {
                ItemStack stack = ((ItemStackValueFilter) entry.value).stack.baseStack;
                itemsAdded.add(stack.getItem());
            }
            PageLinkNormal pageLink = pageHolder.addNormalPage(text, entryFactory);
            quickSearcher.add(pageLink, pageLink.getName().toLowerCase(Locale.ROOT));
        }
    }
    String localizedGroup = underline + "\u0379" + LocaleUtil.localize("buildcraft.guide.contents.all_group");
    String localizedItems = underline + LocaleUtil.localize("buildcraft.guide.contents.item_stacks");
    Title allTitle = contents.getOrAddTitle(localizedGroup);
    SubHeader allHolder = allTitle.getOrAddSubHeader(localizedItems);
    for (Item item : ForgeRegistries.ITEMS) {
        if (itemsAdded.contains(item)) {
            continue;
        }
        NonNullList<ItemStack> stacks = NonNullList.create();
        item.getSubItems(CreativeTabs.SEARCH, stacks);
        for (int i = 0; i < stacks.size(); i++) {
            ItemStack stack = stacks.get(i);
            PageLinkGenerated pageLink = allHolder.addUnknownStack(stack);
            if (pageLink != null) {
                quickSearcher.add(pageLink, pageLink.joinedTooltip.toLowerCase(Locale.ROOT));
            }
            if (i > 50) {
                // most likely the same item
                break;
            }
        }
    }
    String localizedTriggers = underline + LocaleUtil.localize("buildcraft.guide.contents.triggers");
    String localizedActions = underline + LocaleUtil.localize("buildcraft.guide.contents.actions");
    SubHeader triggers = allTitle.getOrAddSubHeader(localizedTriggers);
    SubHeader actions = allTitle.getOrAddSubHeader(localizedActions);
    Set<IStatement> added = new HashSet<>();
    for (IStatement statement : new TreeMap<>(StatementManager.statements).values()) {
        if (!added.add(statement)) {
            continue;
        }
        if (GuideManager.INSTANCE.getEntryFor(statement) != null) {
            continue;
        }
        ISimpleDrawable icon = (x, y) -> GuiElementStatementSource.drawGuiSlot(statement, x, y);
        List<String> tooltip = statement.getTooltip();
        String title = tooltip.isEmpty() ? statement.getUniqueTag() : tooltip.get(0);
        GuideText text = new GuideText(gui, new PageLine(icon, icon, 2, title, true));
        final PageLinkNormal pageLink;
        if (statement instanceof ITrigger) {
            pageLink = triggers.addUnknownPage(text, g -> new GuidePage(gui, ImmutableList.of(), title));
        } else if (statement instanceof IAction) {
            pageLink = actions.addUnknownPage(text, g -> new GuidePage(gui, ImmutableList.of(), title));
        } else {
            pageLink = null;
        }
        if (pageLink != null) {
            String joinedTooltip = tooltip.stream().collect(Collectors.joining(" ", "", ""));
            String searchSr = statement.getUniqueTag() + " " + joinedTooltip;
            quickSearcher.add(pageLink, searchSr.toLowerCase(Locale.ROOT));
        }
    }
    quickSearcher.generate();
    contents.sortAll();
}
Also used : SuffixArray(net.minecraft.client.util.SuffixArray) GuideManager(buildcraft.lib.client.guide.GuideManager) GuidePage(buildcraft.lib.client.guide.parts.GuidePage) Title(buildcraft.lib.client.guide.parts.contents.ContentsList.Title) GuiElementStatementSource(buildcraft.lib.gui.statement.GuiElementStatementSource) Item(net.minecraft.item.Item) TypeOrder(buildcraft.lib.client.guide.TypeOrder) SubHeader(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader) HashSet(java.util.HashSet) PageLinkNormal(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader.PageLinkNormal) GuiIcon(buildcraft.lib.gui.GuiIcon) ItemStack(net.minecraft.item.ItemStack) ImmutableList(com.google.common.collect.ImmutableList) StatementManager(buildcraft.api.statements.StatementManager) Locale(java.util.Locale) IAction(buildcraft.api.statements.IAction) GuideChapter(buildcraft.lib.client.guide.parts.GuideChapter) BCLib(buildcraft.lib.BCLib) CreativeTabs(net.minecraft.creativetab.CreativeTabs) NonNullList(net.minecraft.util.NonNullList) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) PageEntry(buildcraft.lib.client.guide.PageEntry) PageLinkGenerated(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader.PageLinkGenerated) GuiTextField(net.minecraft.client.gui.GuiTextField) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) GlStateManager(net.minecraft.client.renderer.GlStateManager) TextFormatting(net.minecraft.util.text.TextFormatting) ItemStackValueFilter(buildcraft.lib.client.guide.loader.entry.ItemStackValueFilter) GuidePageFactory(buildcraft.lib.client.guide.parts.GuidePageFactory) Set(java.util.Set) IOException(java.io.IOException) LocaleUtil(buildcraft.lib.misc.LocaleUtil) PageLine(buildcraft.lib.client.guide.PageLine) XmlPageLoader(buildcraft.lib.client.guide.loader.XmlPageLoader) ConfigurableFontRenderer(buildcraft.lib.client.render.font.ConfigurableFontRenderer) Collectors(java.util.stream.Collectors) GuiGuide(buildcraft.lib.client.guide.GuiGuide) IFontRenderer(buildcraft.lib.client.guide.font.IFontRenderer) RenderUtil(buildcraft.lib.misc.RenderUtil) List(java.util.List) TreeMap(java.util.TreeMap) FontRenderer(net.minecraft.client.gui.FontRenderer) IStatement(buildcraft.api.statements.IStatement) GuidePageBase(buildcraft.lib.client.guide.parts.GuidePageBase) ForgeRegistries(net.minecraftforge.fml.common.registry.ForgeRegistries) GuideText(buildcraft.lib.client.guide.parts.GuideText) ITrigger(buildcraft.api.statements.ITrigger) PageLink(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader.PageLink) GuideText(buildcraft.lib.client.guide.parts.GuideText) TypeOrder(buildcraft.lib.client.guide.TypeOrder) Item(net.minecraft.item.Item) PageLine(buildcraft.lib.client.guide.PageLine) SubHeader(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader) HashSet(java.util.HashSet) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) IAction(buildcraft.api.statements.IAction) GuidePage(buildcraft.lib.client.guide.parts.GuidePage) Title(buildcraft.lib.client.guide.parts.contents.ContentsList.Title) ITrigger(buildcraft.api.statements.ITrigger) ItemStackValueFilter(buildcraft.lib.client.guide.loader.entry.ItemStackValueFilter) PageLinkGenerated(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader.PageLinkGenerated) GuidePageFactory(buildcraft.lib.client.guide.parts.GuidePageFactory) ItemStack(net.minecraft.item.ItemStack) IStatement(buildcraft.api.statements.IStatement) PageLinkNormal(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader.PageLinkNormal)

Example 14 with IStatement

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

the class ActionWrapper method getPossible.

@Override
public ActionWrapper[] getPossible() {
    IStatement[] possible = delegate.getPossible();
    boolean andSides = sourcePart != EnumPipePart.CENTER;
    List<ActionWrapper> list = new ArrayList<>(possible.length + 5);
    for (int i = 0; i < possible.length; i++) {
        list.add(wrap(possible[i], sourcePart.face));
    }
    if (andSides) {
        EnumPipePart part = sourcePart;
        for (int j = 0; j < 5; j++) {
            int i = j + possible.length;
            part = part.next();
            ActionWrapper action = wrap(delegate, part.face);
            if (true) {
                // TODO: Check the gui container to see if this is a valid action!
                list.add(action);
            }
        }
    }
    return list.toArray(new ActionWrapper[0]);
}
Also used : ArrayList(java.util.ArrayList) EnumPipePart(buildcraft.api.core.EnumPipePart) IStatement(buildcraft.api.statements.IStatement)

Example 15 with IStatement

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

the class SchematicPipe method rotateGateLeft.

private void rotateGateLeft(NBTTagCompound gateNBT) {
    for (int i = 0; i < Gate.MAX_STATEMENTS; ++i) {
        if (gateNBT.hasKey("trigger[" + i + "]")) {
            IStatement t = StatementManager.statements.get(gateNBT.getString("trigger[" + i + "]"));
            t = t.rotateLeft();
            gateNBT.setString("trigger[" + i + "]", t.getUniqueTag());
        }
        if (gateNBT.hasKey("action[" + i + "]")) {
            IStatement a = StatementManager.statements.get(gateNBT.getString("action[" + i + "]"));
            a = a.rotateLeft();
            gateNBT.setString("action[" + i + "]", a.getUniqueTag());
        }
        for (int j = 0; j < Gate.MAX_PARAMETERS; ++j) {
            if (gateNBT.hasKey("triggerParameters[" + i + "][" + j + "]")) {
                NBTTagCompound cpt = gateNBT.getCompoundTag("triggerParameters[" + i + "][" + j + "]");
                IStatementParameter parameter = StatementManager.createParameter(cpt.getString("kind"));
                parameter.readFromNBT(cpt);
                parameter = parameter.rotateLeft();
                parameter.writeToNBT(cpt);
                gateNBT.setTag("triggerParameters[" + i + "][" + j + "]", cpt);
            }
            if (gateNBT.hasKey("actionParameters[" + i + "][" + j + "]")) {
                NBTTagCompound cpt = gateNBT.getCompoundTag("actionParameters[" + i + "][" + j + "]");
                IStatementParameter parameter = StatementManager.createParameter(cpt.getString("kind"));
                parameter.readFromNBT(cpt);
                parameter = parameter.rotateLeft();
                parameter.writeToNBT(cpt);
                gateNBT.setTag("actionParameters[" + i + "][" + j + "]", cpt);
            }
        }
    }
    if (gateNBT.hasKey("direction")) {
        EnumFacing face = EnumFacing.VALUES[gateNBT.getInteger("direction")];
        if (face.getAxis() != Axis.Y) {
            face = face.rotateY();
        }
        gateNBT.setInteger("direction", face.ordinal());
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IStatementParameter(buildcraft.api.statements.IStatementParameter) 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