• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CyclopsMC / IntegratedDynamics / 19267223570

11 Nov 2025 01:30PM UTC coverage: 53.046% (+0.04%) from 53.006%
19267223570

push

github

rubensworks
Merge remote-tracking branch 'origin/master-1.21-lts' into master-1.21

2875 of 8772 branches covered (32.77%)

Branch coverage included in aggregate %.

17354 of 29363 relevant lines covered (59.1%)

3.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/org/cyclops/integrateddynamics/core/logicprogrammer/client/ValueTypeIngredientsLPElementClient.java
1
package org.cyclops.integrateddynamics.core.logicprogrammer.client;
2

3
import com.google.common.collect.Maps;
4
import net.minecraft.client.Minecraft;
5
import net.minecraft.client.gui.Font;
6
import net.minecraft.client.gui.GuiGraphics;
7
import net.minecraft.client.gui.components.Button;
8
import net.minecraft.client.renderer.texture.TextureManager;
9
import net.minecraft.network.chat.Component;
10
import net.minecraft.resources.ResourceLocation;
11
import net.minecraft.world.inventory.AbstractContainerMenu;
12
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
13
import org.cyclops.cyclopscore.client.gui.component.button.ButtonArrow;
14
import org.cyclops.cyclopscore.client.gui.component.button.ButtonText;
15
import org.cyclops.cyclopscore.client.gui.component.input.IInputListener;
16
import org.cyclops.cyclopscore.client.gui.component.input.WidgetArrowedListField;
17
import org.cyclops.cyclopscore.helper.IModHelpers;
18
import org.cyclops.integrateddynamics.IntegratedDynamics;
19
import org.cyclops.integrateddynamics.api.client.gui.subgui.ISubGuiBox;
20
import org.cyclops.integrateddynamics.api.logicprogrammer.IValueTypeLogicProgrammerElement;
21
import org.cyclops.integrateddynamics.client.gui.container.ContainerScreenLogicProgrammerBase;
22
import org.cyclops.integrateddynamics.core.ingredient.IngredientComponentHandlers;
23
import org.cyclops.integrateddynamics.core.logicprogrammer.IRenderPatternValueTypeTooltip;
24
import org.cyclops.integrateddynamics.core.logicprogrammer.ValueTypeIngredientsLPElement;
25
import org.cyclops.integrateddynamics.inventory.container.ContainerLogicProgrammerBase;
26
import org.cyclops.integrateddynamics.network.packet.LogicProgrammerSetElementInventory;
27

28
import java.util.Comparator;
29
import java.util.List;
30
import java.util.Map;
31

32
/**
33
 * @author rubensworks
34
 */
35
public class ValueTypeIngredientsLPElementClient extends ValueTypeLPElementBaseClient<ValueTypeIngredientsLPElement> {
36

37
    private ValueTypeIngredientsLPElementClient.MasterSubGuiRenderPattern masterGui;
38
    private Map<IngredientComponent, Map<Integer, RenderPattern>> subElementGuis = Maps.newHashMap();
×
39

40
    public ValueTypeIngredientsLPElementClient(ValueTypeIngredientsLPElement element) {
41
        super(element);
×
42
    }
×
43

44
    @Override
45
    public void setValueInGui(ISubGuiBox subGui) {
46
        if (!getElement().getSubElements().get(getElement().getCurrentType()).isEmpty()) {
×
47
            getElement().setActiveElement(0);
×
48
        }
49
    }
×
50

51
    @Override
52
    public ISubGuiBox createSubGui(int baseX, int baseY, int maxWidth, int maxHeight,
53
                                   ContainerScreenLogicProgrammerBase gui, ContainerLogicProgrammerBase container) {
54
        return masterGui = new ValueTypeIngredientsLPElementClient.MasterSubGuiRenderPattern(this.getElement(), baseX, baseY, maxWidth, maxHeight, gui, container);
×
55
    }
56

57
    public void setActiveElement(int activeElement) {
58
        if (masterGui != null) {
×
59
            masterGui.setActiveElement(activeElement);
×
60
            masterGui.container.onDirty();
×
61
        }
62
    }
×
63

64
    public void removeElement(int index) {
65
        IngredientComponent currentType = getElement().getCurrentType();
×
66
        Map<Integer, RenderPattern> oldSubElementGuis = subElementGuis.get(currentType);
×
67
        subElementGuis.put(currentType, Maps.newHashMap());
×
68
        for (Map.Entry<Integer, RenderPattern> entry : oldSubElementGuis.entrySet()) {
×
69
            int i = entry.getKey();
×
70
            if (i < index) {
×
71
                subElementGuis.get(currentType).put(i, entry.getValue());
×
72
            } else if (i > index) {
×
73
                subElementGuis.get(currentType).put(i - 1, entry.getValue());
×
74
            }
75
        }
×
76
    }
×
77

78
    public void activate() {
79
        for (IngredientComponent recipeComponent : IngredientComponentHandlers.REGISTRY.getComponents()) {
×
80
            subElementGuis.put(recipeComponent, Maps.newHashMap());
×
81
        }
×
82
    }
×
83

84
    /**
85
     * Sub gui that holds the list element value type panel and the panel for browsing through the elements.
86
     */
87
    protected static class MasterSubGuiRenderPattern extends RenderPattern<ValueTypeIngredientsLPElement, ContainerScreenLogicProgrammerBase, ContainerLogicProgrammerBase>
88
            implements IRenderPatternValueTypeTooltip {
89

90
        private final int baseX;
91
        private final int baseY;
92
        private final int maxWidth;
93
        private final int maxHeight;
94
        private final ContainerScreenLogicProgrammerBase gui;
95
        private final ContainerLogicProgrammerBase container;
96

97
        protected ListElementSubGui elementSubGui = null;
×
98
        protected int lastGuiLeft;
99
        protected int lastGuiTop;
100
        private boolean renderTooltip = true;
×
101

102
        public MasterSubGuiRenderPattern(ValueTypeIngredientsLPElement element, int baseX, int baseY, int maxWidth, int maxHeight,
103
                                         ContainerScreenLogicProgrammerBase gui, ContainerLogicProgrammerBase container) {
104
            super(element, baseX, baseY, maxWidth, maxHeight, gui, container);
×
105
            subGuiHolder.addSubGui(new SelectionSubGui(element, baseX, baseY, maxWidth, maxHeight, gui, container));
×
106
            this.baseX = baseX;
×
107
            this.baseY = baseY;
×
108
            this.maxWidth = maxWidth;
×
109
            this.maxHeight = maxHeight;
×
110
            this.gui = gui;
×
111
            this.container = container;
×
112
        }
×
113

114
        public void setActiveElement(int index) {
115
            if (elementSubGui != null) {
×
116
                subGuiHolder.removeSubGui(elementSubGui);
×
117
                ((ContainerLogicProgrammerBase) gui.getMenu()).setElementInventory(null, 0, 0);
×
118
            }
119
            if (index >= 0) {
×
120
                subGuiHolder.addSubGui(elementSubGui = new ListElementSubGui(element, baseX, baseY + (getHeight() / 4),
×
121
                        maxWidth, maxHeight, gui, container));
122
                elementSubGui.init(lastGuiLeft, lastGuiTop);
×
123
            }
124
        }
×
125

126
        @Override
127
        public void init(int guiLeft, int guiTop) {
128
            super.init(guiLeft, guiTop);
×
129
            lastGuiLeft = guiLeft;
×
130
            lastGuiTop = guiTop;
×
131
        }
×
132

133
        @Override
134
        public void drawGuiContainerForegroundLayer(GuiGraphics guiGraphics, int guiLeft, int guiTop, TextureManager textureManager, Font fontRenderer, int mouseX, int mouseY) {
135
            super.drawGuiContainerForegroundLayer(guiGraphics, guiLeft, guiTop, textureManager, fontRenderer, mouseX, mouseY);
×
136

137
            // Output type tooltip
138
            this.drawTooltipForeground(gui, guiGraphics, container, guiLeft, guiTop, mouseX, mouseY, element.getValueType());
×
139
        }
×
140

141
        @Override
142
        public boolean isRenderTooltip() {
143
            return this.renderTooltip;
×
144
        }
145

146
        @Override
147
        public void setRenderTooltip(boolean renderTooltip) {
148
            this.renderTooltip = renderTooltip;
×
149
        }
×
150
    }
151

152
    /**
153
     * Selection panel for the type.
154
     */
155
    protected static class SelectionSubGui extends RenderPattern<ValueTypeIngredientsLPElement, ContainerScreenLogicProgrammerBase, ContainerLogicProgrammerBase> implements IInputListener {
156

157
        private WidgetArrowedListField<IngredientComponent<?, ?>> valueTypeSelector = null;
×
158
        private Button arrowAdd;
159

160
        public SelectionSubGui(ValueTypeIngredientsLPElement element, int baseX, int baseY, int maxWidth, int maxHeight,
161
                               ContainerScreenLogicProgrammerBase gui, ContainerLogicProgrammerBase container) {
162
            super(element, baseX, baseY, maxWidth, maxHeight, gui, container);
×
163
        }
×
164

165
        @Override
166
        public int getHeight() {
167
            return super.getHeight() / 4;
×
168
        }
169

170
        protected static List<IngredientComponent<?, ?>> getValueTypes() {
171
            // By coincidence, sorting by name (in reverse) is sufficient to achieve the order we want,
172
            // for the following known ingredient components:
173
            // - minecraft:itemstack
174
            // - minecraft:fluidstack
175
            // - minecraft:energy
176
            // - mekanism:chemicalstack
177
            return IngredientComponentHandlers.REGISTRY.getComponents().stream()
×
178
                    .sorted(Comparator.<IngredientComponent<?, ?>, ResourceLocation>comparing(IngredientComponent::getName).reversed())
×
179
                    .toList();
×
180
        }
181

182
        @Override
183
        public void init(int guiLeft, int guiTop) {
184
            super.init(guiLeft, guiTop);
×
185
            valueTypeSelector = new WidgetArrowedListField<>(Minecraft.getInstance().font,
×
186
                    getX() + guiLeft + getWidth() / 2 - 50, getY() + guiTop + 2, 100, 15, true, Component.translatable("valuetype.integrateddynamics.value_type"), true, getValueTypes()) {
×
187
                @Override
188
                protected String activeElementToString(IngredientComponent element) {
189
                    return IModHelpers.get().getL10NHelpers().localize(element.getTranslationKey());
×
190
                }
191
            };
192
            valueTypeSelector.setListener(this);
×
193
            //onChanged();
194
            int x = guiLeft + getX();
×
195
            int y = guiTop + getY();
×
196
            buttonList.add(arrowAdd = new ButtonText(x + getWidth() - 13, y + getHeight() - 13, 12, 12, Component.translatable("gui.integrateddynamics.button.add"), Component.literal("+"), (b) -> {
×
197
            }, true));
×
198
        }
×
199

200
        @Override
201
        public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
202
            return super.mouseClicked(mouseX, mouseY, mouseButton) || valueTypeSelector.mouseClicked(mouseX, mouseY, mouseButton);
×
203
        }
204

205
        @Override
206
        protected void actionPerformed(Button guibutton) {
207
            super.actionPerformed(guibutton);
×
208
            if (guibutton == arrowAdd) {
×
209
                element.setLength(element.getLength() + 1);
×
210
            }
211
        }
×
212

213
        @Override
214
        public void renderBg(GuiGraphics guiGraphics, int guiLeft, int guiTop, TextureManager textureManager, Font fontRenderer, float partialTicks, int mouseX, int mouseY) {
215
            super.renderBg(guiGraphics, guiLeft, guiTop, textureManager, fontRenderer, partialTicks, mouseX, mouseY);
×
216
            valueTypeSelector.renderWidget(guiGraphics, mouseX, mouseY, partialTicks);
×
217
        }
×
218

219
        @Override
220
        public void onChanged() {
221
            element.setCurrentType(valueTypeSelector.getActiveElement());
×
222
        }
×
223
    }
224

225
    /**
226
     * Panel for browsing through the list elements and updating them.
227
     */
228
    protected static class ListElementSubGui extends RenderPattern<ValueTypeIngredientsLPElement, ContainerScreenLogicProgrammerBase<?>, ContainerLogicProgrammerBase> {
229

230
        private ButtonArrow arrowLeft;
231
        private ButtonArrow arrowRight;
232
        private Button arrowRemove;
233

234
        private RenderPattern subGui;
235
        private IValueTypeLogicProgrammerElement<RenderPattern, ContainerScreenLogicProgrammerBase<?>, AbstractContainerMenu, ?> subElement;
236

237
        public ListElementSubGui(ValueTypeIngredientsLPElement element, int baseX, int baseY, int maxWidth, int maxHeight,
238
                                 ContainerScreenLogicProgrammerBase<?> gui, ContainerLogicProgrammerBase container) {
239
            super(element, baseX, baseY, maxWidth, maxHeight, gui, container);
×
240
            this.subGui = element.getClient().subElementGuis.get(element.getCurrentType()).get(element.getActiveElement());
×
241
            this.subElement = element.getSubElements().get(element.getCurrentType()).get(element.getActiveElement());
×
242
            if(subGui == null) {
×
243
                subGui = (RenderPattern) subElement.getClient().createSubGui(baseX, baseY, maxWidth,
×
244
                        maxHeight / 3 * 2, gui, container);
245
                element.getClient().subElementGuis.get(element.getCurrentType()).put(
×
246
                        element.getActiveElement(),
×
247
                        subGui);
248
            }
249
            int x = getX() + baseX - ValueTypeIngredientsLPElement.OFFSET_X;
×
250
            int y = getY() + baseY - ValueTypeIngredientsLPElement.OFFSET_Y;
×
251
            gui.getMenu().setElementInventory(subElement, x, y);
×
252
            subGuiHolder.addSubGui(subGui);
×
253

254
            // Do the same thing server-side
255
            IntegratedDynamics._instance.getPacketHandler().sendToServer(
×
256
                    new LogicProgrammerSetElementInventory(
257
                            IngredientComponentHandlers.REGISTRY.getComponentHandler(element.getCurrentType()).getValueType(), x, y));
×
258
        }
×
259

260
        @Override
261
        public int getHeight() {
262
            return (super.getHeight() / 4) * 3;
×
263
        }
264

265
        @Override
266
        public void init(int guiLeft, int guiTop) {
267
            super.init(guiLeft, guiTop);
×
268
            int x = guiLeft + getX();
×
269
            int y = guiTop + getY();
×
270
            buttonList.add(arrowLeft = new ButtonArrow(x, y, Component.translatable("gui.cyclopscore.left"),
×
271
                    b -> element.setActiveElement(element.getActiveElement() - 1), ButtonArrow.Direction.WEST));
×
272
            buttonList.add(arrowRight = new ButtonArrow(x + getWidth() - arrowLeft.getWidth() - 1, y, Component.translatable("gui.cyclopscore.right"),
×
273
                    b -> element.setActiveElement(element.getActiveElement() + 1), ButtonArrow.Direction.EAST));
×
274
            buttonList.add(arrowRemove = new ButtonText(x + (getWidth() / 2) - (arrowLeft.getWidth() / 2), y + getHeight() - 13, 12, 12, Component.translatable("gui.integrateddynamics.button.remove"), Component.literal("-"),
×
275
                    b -> element.removeElement(element.getActiveElement()), true));
×
276
            arrowLeft.active = element.getActiveElement() > 0;
×
277
            arrowRight.active = element.getActiveElement() < element.getLength() - 1;
×
278
            arrowRemove.active = element.getLength() > 0;
×
279
            subElement.getClient().setValueInGui(subGui);
×
280
            subElement.setValueInContainer(subGui.container);
×
281
        }
×
282

283
        @Override
284
        public void renderBg(GuiGraphics guiGraphics, int guiLeft, int guiTop, TextureManager textureManager, Font fontRenderer, float partialTicks, int mouseX, int mouseY) {
285
            super.renderBg(guiGraphics, guiLeft, guiTop, textureManager, fontRenderer, partialTicks, mouseX, mouseY);
×
286
            int x = guiLeft + getX() + (getWidth() / 2);
×
287
            int y = guiTop + getY() + 4;
×
288
            IModHelpers.get().getRenderHelpers().drawScaledCenteredString(guiGraphics, fontRenderer, String.valueOf(element.getActiveElement()), x - 4, y + 2, 10, IModHelpers.get().getBaseHelpers().RGBAToInt(20, 20, 20, 255), false, Font.DisplayMode.NORMAL);
×
289
        }
×
290
    }
291
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc