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

CyclopsMC / IntegratedDynamics / 20210191346

14 Dec 2025 03:32PM UTC coverage: 19.514% (-33.5%) from 53.061%
20210191346

push

github

rubensworks
Remove deprecations

663 of 8728 branches covered (7.6%)

Branch coverage included in aggregate %.

6786 of 29445 relevant lines covered (23.05%)

1.09 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.input.MouseButtonEvent;
9
import net.minecraft.client.renderer.texture.TextureManager;
10
import net.minecraft.network.chat.Component;
11
import net.minecraft.resources.ResourceLocation;
12
import net.minecraft.world.inventory.AbstractContainerMenu;
13
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
14
import org.cyclops.cyclopscore.client.gui.component.button.ButtonArrow;
15
import org.cyclops.cyclopscore.client.gui.component.button.ButtonText;
16
import org.cyclops.cyclopscore.client.gui.component.input.IInputListener;
17
import org.cyclops.cyclopscore.client.gui.component.input.WidgetArrowedListField;
18
import org.cyclops.cyclopscore.helper.IModHelpers;
19
import org.cyclops.integrateddynamics.IntegratedDynamics;
20
import org.cyclops.integrateddynamics.api.client.gui.subgui.ISubGuiBox;
21
import org.cyclops.integrateddynamics.api.logicprogrammer.IValueTypeLogicProgrammerElement;
22
import org.cyclops.integrateddynamics.client.gui.container.ContainerScreenLogicProgrammerBase;
23
import org.cyclops.integrateddynamics.core.ingredient.IngredientComponentHandlers;
24
import org.cyclops.integrateddynamics.core.logicprogrammer.IRenderPatternValueTypeTooltip;
25
import org.cyclops.integrateddynamics.core.logicprogrammer.ValueTypeIngredientsLPElement;
26
import org.cyclops.integrateddynamics.inventory.container.ContainerLogicProgrammerBase;
27
import org.cyclops.integrateddynamics.network.packet.LogicProgrammerSetElementInventory;
28

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

201
        @Override
202
        public boolean mouseClicked(MouseButtonEvent evt, boolean isDoubleClick) {
203
            return super.mouseClicked(evt, isDoubleClick) || valueTypeSelector.mouseClicked(evt, isDoubleClick);
×
204
        }
205

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

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

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

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

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

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

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

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

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

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

284
        @Override
285
        public void renderBg(GuiGraphics guiGraphics, int guiLeft, int guiTop, TextureManager textureManager, Font fontRenderer, float partialTicks, int mouseX, int mouseY) {
286
            super.renderBg(guiGraphics, guiLeft, guiTop, textureManager, fontRenderer, partialTicks, mouseX, mouseY);
×
287
            int x = guiLeft + getX() + (getWidth() / 2);
×
288
            int y = guiTop + getY() + 4;
×
289
            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);
×
290
        }
×
291
    }
292
}
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