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

CyclopsMC / IntegratedDynamics / 16552051255

27 Jul 2025 01:58PM UTC coverage: 53.206% (+8.0%) from 45.161%
16552051255

push

github

rubensworks
Resolve minor TODOs

2888 of 8740 branches covered (33.04%)

Branch coverage included in aggregate %.

17341 of 29280 relevant lines covered (59.22%)

3.08 hits per line

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

0.0
/src/main/java/org/cyclops/integrateddynamics/client/gui/container/ContainerScreenLogicProgrammerBase.java
1
package org.cyclops.integrateddynamics.client.gui.container;
2

3
import com.google.common.collect.Lists;
4
import com.mojang.blaze3d.platform.InputConstants;
5
import net.minecraft.client.Minecraft;
6
import net.minecraft.client.gui.Font;
7
import net.minecraft.client.gui.GuiGraphics;
8
import net.minecraft.client.renderer.RenderPipelines;
9
import net.minecraft.client.renderer.texture.TextureManager;
10
import net.minecraft.network.chat.Component;
11
import net.minecraft.network.chat.MutableComponent;
12
import net.minecraft.resources.ResourceLocation;
13
import net.minecraft.util.ARGB;
14
import net.minecraft.world.entity.player.Inventory;
15
import net.minecraft.world.item.ItemStack;
16
import org.apache.commons.lang3.tuple.Triple;
17
import org.cyclops.cyclopscore.client.gui.component.button.ButtonText;
18
import org.cyclops.cyclopscore.client.gui.component.input.WidgetTextFieldExtended;
19
import org.cyclops.cyclopscore.client.gui.container.ContainerScreenScrolling;
20
import org.cyclops.cyclopscore.client.gui.image.Images;
21
import org.cyclops.cyclopscore.helper.IModHelpers;
22
import org.cyclops.integrateddynamics.IntegratedDynamics;
23
import org.cyclops.integrateddynamics.Reference;
24
import org.cyclops.integrateddynamics.RegistryEntries;
25
import org.cyclops.integrateddynamics.api.client.gui.subgui.IGuiInputElement;
26
import org.cyclops.integrateddynamics.api.logicprogrammer.ILogicProgrammerElement;
27
import org.cyclops.integrateddynamics.api.logicprogrammer.ILogicProgrammerElementType;
28
import org.cyclops.integrateddynamics.core.client.gui.subgui.SubGuiHolder;
29
import org.cyclops.integrateddynamics.core.evaluate.variable.gui.SubGuiValueTypeInfoBase;
30
import org.cyclops.integrateddynamics.core.helper.L10NValues;
31
import org.cyclops.integrateddynamics.core.logicprogrammer.LogicProgrammerElementTypes;
32
import org.cyclops.integrateddynamics.core.logicprogrammer.client.RenderPattern;
33
import org.cyclops.integrateddynamics.inventory.container.ContainerLogicProgrammerBase;
34
import org.cyclops.integrateddynamics.network.packet.LogicProgrammerActivateElementPacket;
35
import org.cyclops.integrateddynamics.network.packet.LogicProgrammerLabelPacket;
36
import org.cyclops.integrateddynamics.proxy.ClientProxy;
37
import org.lwjgl.glfw.GLFW;
38

39
import javax.annotation.Nullable;
40
import java.awt.*;
41
import java.util.List;
42

43
/**
44
 * Base gui for the logic programmer.
45
 * @author rubensworks
46
 */
47
public class ContainerScreenLogicProgrammerBase<C extends ContainerLogicProgrammerBase>
48
        extends ContainerScreenScrolling<C>
49
        implements ContainerLogicProgrammerBase.ScreenCallbackHandler {
50

51
    public static final int BOX_HEIGHT = 18;
52
    private static final Rectangle ITEM_POSITION = new Rectangle(19, 18, 56, BOX_HEIGHT - 1);
×
53

54
    protected final SubGuiHolder subGuiHolder = new SubGuiHolder();
×
55
    private final boolean hasLabeller;
56
    protected RenderPattern operatorConfigPattern = null;
×
57
    protected SubGuiOperatorInfo operatorInfoPattern = null;
×
58
    protected boolean firstInit = true;
×
59
    protected int relativeStep = -1;
×
60
    protected boolean swallowNextCharacter = false;
×
61
    private ButtonText resetButton;
62

63
    public ContainerScreenLogicProgrammerBase(C container, Inventory playerInventory, Component title) {
64
        super(container, playerInventory, title);
×
65
        container.setScreenCallbackHandler(this);
×
66
        this.titleLabelX = 87;
×
67

68
        this.hasLabeller = playerInventory.contains(new ItemStack(RegistryEntries.ITEM_LABELLER));
×
69
    }
×
70

71
    @Override
72
    protected Rectangle getScrollRegion() {
73
        return new Rectangle(this.leftPos + 19, this.topPos + 18, 57, 178);
×
74
    }
75

76
    @Override
77
    public void init() {
78
        super.init();
×
79

80
        // Button to deselect the active LP element
81
        addRenderableWidget(this.resetButton = new ButtonText(this.leftPos + 87,  this.topPos + 4,
×
82
                Component.translatable(L10NValues.GUI_LOGICPROGRAMMER_RESET),
×
83
                Component.translatable(L10NValues.GUI_LOGICPROGRAMMER_RESET), button -> {
×
84
            if (container.getActiveElement() != null) {
×
85
                container.returnWriteItemToPlayer();
×
86
                handleElementActivation(container.getActiveElement(), true);
×
87
            }
88
        }));
×
89
        this.resetButton.setHeight(12);
×
90
        resetButton.visible = false;
×
91

92
        subGuiHolder.init(this.leftPos, this.topPos);
×
93
        if (firstInit) {
×
94
            setSearchFieldFocussed(true);
×
95
            firstInit = false;
×
96
        }
97
    }
×
98

99
    @Override
100
    public void containerTick() {
101
        super.containerTick();
×
102
        subGuiHolder.tick();
×
103
    }
×
104

105
    protected int getScrollX() {
106
        return 5;
×
107
    }
108

109
    protected int getScrollY() {
110
        return 18;
×
111
    }
112

113
    protected int getScrollHeight() {
114
        return 178;
×
115
    }
116

117
    @Override
118
    protected int getBaseXSize() {
119
        return 256;
×
120
    }
121

122
    @Override
123
    protected int getBaseYSize() {
124
        return 240;
×
125
    }
126

127
    @Override
128
    protected int getSearchX() {
129
        return 6;
×
130
    }
131

132
    protected int getSearchWidth() {
133
        return 70;
×
134
    }
135

136
    @Override
137
    protected ResourceLocation constructGuiTexture() {
138
        return ResourceLocation.fromNamespaceAndPath(Reference.MOD_ID, "textures/gui/logic_programmer.png");
×
139
    }
140

141
    protected float colorSmoothener(float color, boolean hover) {
142
        return 1F - ((1F - color) / (hover ? 2F : 4F));
×
143
    }
144

145
    @Override
146
    protected void renderBg(GuiGraphics guiGraphics, float partialTicks, int mouseX, int mouseY) {
147
        super.renderBg(guiGraphics, partialTicks, mouseX, mouseY);
×
148
        subGuiHolder.renderBg(guiGraphics, this.leftPos, this.topPos, getMinecraft().getTextureManager(), font, partialTicks, mouseX, mouseY);
×
149

150
        // Draw container name
151
        guiGraphics.drawString(font, Component.translatable(L10NValues.GUI_LOGICPROGRAMMER_FILTER),
×
152
                this.leftPos + offsetX + 5, this.topPos + offsetY + 208, IModHelpers.get().getBaseHelpers().RGBAToInt(80, 80, 80, 255),
×
153
                false);
154

155
        // Draw operators
156
        ContainerLogicProgrammerBase container = (ContainerLogicProgrammerBase) getMenu();
×
157
        int boxHeight = BOX_HEIGHT;
×
158
        for(int i = 0; i < container.getPageSize(); i++) {
×
159
            if(container.isElementVisible(i)) {
×
160
                ILogicProgrammerElement element = container.getVisibleElement(i);
×
161

162
                Triple<Float, Float, Float> rgb = IModHelpers.get().getBaseHelpers().intToRGB(element.getColor());
×
163
                boolean hover = LogicProgrammerElementTypes.areEqual(container.getActiveElement(), element)
×
164
                        || isPointInRegion(getElementPosition(container, i, false), new Point(mouseX, mouseY));
×
165
                int color = ARGB.colorFromFloat(
×
166
                        1F,
167
                        colorSmoothener(rgb.getLeft(), hover),
×
168
                        colorSmoothener(rgb.getMiddle(), hover),
×
169
                        colorSmoothener(rgb.getRight(), hover)
×
170
                );
171

172
                // Background
173
                guiGraphics.blit(RenderPipelines.GUI_TEXTURED, texture, leftPos + offsetX + ITEM_POSITION.x,
×
174
                        topPos + offsetY + ITEM_POSITION.y + boxHeight * i, 19, 18, ITEM_POSITION.width, ITEM_POSITION.height, 256, 256, color);
175

176
                // Arrow
177
                if(hover) {
×
178
                    guiGraphics.blit(RenderPipelines.GUI_TEXTURED, texture, leftPos + offsetX + ITEM_POSITION.x,
×
179
                            topPos + offsetY + ITEM_POSITION.y + boxHeight * i, 0, 240, 3, 16, 256, 256, color);
180
                }
181

182
                // Operator info
183
                String aspectName = element.getSymbol();
×
184
                IModHelpers.get().getRenderHelpers().drawScaledCenteredString(guiGraphics, font, aspectName,
×
185
                        this.leftPos + offsetX + (hover ? 22 : 21),
×
186
                        this.topPos + offsetY + 26 + boxHeight * i,
187
                        53, IModHelpers.get().getBaseHelpers().RGBAToInt(40, 40, 40, 255), false, Font.DisplayMode.NORMAL);
×
188
            }
189
        }
190

191
        // Draw arrow on write slot
192
        guiGraphics.blit(RenderPipelines.GUI_TEXTURED, texture, leftPos + offsetX + ContainerLogicProgrammerBase.OUTPUT_X - 4,
×
193
                topPos + offsetY + ContainerLogicProgrammerBase.OUTPUT_Y - 4, subGuiHolder.isEmpty() ? 7 : 3, 240, 4, 4, 256, 256);
×
194
    }
×
195

196
    protected Rectangle getElementPosition(ContainerLogicProgrammerBase container, int i, boolean absolute) {
197
        return new Rectangle(ITEM_POSITION.x + offsetX + (absolute ? this.leftPos : 0),
×
198
                ITEM_POSITION.y + BOX_HEIGHT * i + offsetY + (absolute ? this.topPos : 0),
×
199
                ITEM_POSITION.width, ITEM_POSITION.height
200
        );
201
    }
202

203
    @Override
204
    protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
205
        // super.drawGuiContainerForegroundLayer(matrixStack, mouseX, mouseY);
206
        subGuiHolder.drawGuiContainerForegroundLayer(guiGraphics, this.leftPos, this.topPos, getMinecraft().getTextureManager(), font, mouseX, mouseY);
×
207

208
        // Draw usage information
209
        if (subGuiHolder.isEmpty()) {
×
210
            // Create
211
            Images.ARROW_LEFT.draw(guiGraphics, offsetX + 85, offsetY + 17);
×
212
            guiGraphics.drawString(font, Component.translatable(L10NValues.GUI_LOGICPROGRAMMER_INFO_CREATE),
×
213
                    offsetX + 100, offsetY + 23, IModHelpers.get().getBaseHelpers().RGBAToInt(80, 80, 80, 255), false);
×
214

215
            // Modify
216
            Images.ARROW_DOWN.draw(guiGraphics, offsetX + 230, offsetY + 90);
×
217
            MutableComponent modifyComponent = Component.translatable(L10NValues.GUI_LOGICPROGRAMMER_INFO_MODIFY);
×
218
            guiGraphics.drawString(font, modifyComponent,
×
219
                    offsetX + 230 - font.width(modifyComponent), offsetY + 95, IModHelpers.get().getBaseHelpers().RGBAToInt(80, 80, 80, 255), false);
×
220

221
            // Tooltip on write slot
222
            if (this.isHovering(ContainerLogicProgrammerBase.OUTPUT_X, ContainerLogicProgrammerBase.OUTPUT_Y,
×
223
                    ContainerScreenLogicProgrammerBase.BOX_HEIGHT, ContainerScreenLogicProgrammerBase.BOX_HEIGHT, mouseX, mouseY)
224
                    && Minecraft.getInstance().player.containerMenu.getCarried().isEmpty()
×
225
                    && !container.hasWriteItemInSlot()) {
×
226
                this.drawTooltip(Lists.newArrayList(Component.translatable(L10NValues.GUI_LOGICPROGRAMMER_TOOLTIP_WRITESLOT_MODIFY)), guiGraphics, mouseX, mouseY);
×
227
            }
228
        }
229

230
        // Draw operator tooltips
231
        ContainerLogicProgrammerBase container = getMenu();
×
232
        for(int i = 0; i < container.getPageSize(); i++) {
×
233
            if(container.isElementVisible(i)) {
×
234
                ILogicProgrammerElement<?, ?, ?, ?> element = container.getVisibleElement(i);
×
235
                if(isPointInRegion(getElementPosition(container, i, false), new Point(mouseX, mouseY))) {
×
236
                    List<Component> lines = Lists.newLinkedList();
×
237
                    element.loadTooltip(lines::add);
×
238
                    drawTooltip(lines, guiGraphics, mouseX, mouseY);
×
239
                }
240
            }
241
        }
242
    }
×
243

244
    protected void onActivateElement(ILogicProgrammerElement<RenderPattern, ContainerScreenLogicProgrammerBase<?>, ContainerLogicProgrammerBase, ?> element) {
245
        this.resetButton.setFocused(false);
×
246
        subGuiHolder.addSubGui(operatorInfoPattern = new SubGuiOperatorInfo(element));
×
247
        operatorInfoPattern.init(leftPos, topPos);
×
248
        subGuiHolder.addSubGui(operatorConfigPattern = element.getClient().createSubGui(ContainerLogicProgrammerBase.BASE_X, ContainerLogicProgrammerBase.BASE_Y, ContainerLogicProgrammerBase.MAX_WIDTH, ContainerLogicProgrammerBase.MAX_HEIGHT, this, (ContainerLogicProgrammerBase) getMenu()));
×
249
        operatorConfigPattern.init(leftPos, topPos);
×
250
    }
×
251

252
    protected void onDeactivateElement(ILogicProgrammerElement element) {
253
        subGuiHolder.clear();
×
254
    }
×
255

256
    @Override
257
    public boolean handleElementActivation(ILogicProgrammerElement element, boolean sendToServer) {
258
        boolean activate = false;
×
259
        boolean deselect = false;
×
260
        ContainerLogicProgrammerBase container = getMenu();
×
261
        ILogicProgrammerElement newActive = null;
×
262
        if (container.getActiveElement() == element) {
×
263
            // Only allow deselection of the current LP element if the write slot is empty
264
            if (!container.hasWriteItemInSlot()) {
×
265
                deselect = true;
×
266
                onDeactivateElement(element);
×
267
            }
268
        } else {
269
            // Swap to another LP element
270
            onDeactivateElement(element);
×
271
            activate = true;
×
272
            newActive = element;
×
273
            if(element != null) {
×
274
                onActivateElement(element);
×
275
            }
276
        }
277
        resetButton.visible = newActive != null;
×
278
        if (activate || deselect) {
×
279
            container.setActiveElement(newActive,
×
280
                    operatorConfigPattern == null ? 0 : operatorConfigPattern.getX(),
×
281
                    operatorConfigPattern == null ? 0 : operatorConfigPattern.getY());
×
282
        }
283
        if (sendToServer) {
×
284
            if (newActive != null) {
×
285
                ILogicProgrammerElementType type = newActive.getType();
×
286
                IntegratedDynamics._instance.getPacketHandler().sendToServer(
×
287
                        new LogicProgrammerActivateElementPacket(type.getUniqueName(), type.getName(newActive)));
×
288
            } else if (deselect) {
×
289
                IntegratedDynamics._instance.getPacketHandler().sendToServer(
×
290
                        new LogicProgrammerActivateElementPacket(ResourceLocation.parse(""), ResourceLocation.parse("")));
×
291
            }
292
        }
293
        return activate;
×
294
    }
295

296
    @Nullable
297
    @Override
298
    public RenderPattern getOperatorConfigPattern() {
299
        return operatorConfigPattern;
×
300
    }
301

302
    protected void setSearchFieldFocussed(boolean focused) {
303
        getSearchField().setFocused(focused);
×
304
    }
×
305

306
    protected boolean isSearchFieldFocussed() {
307
        return getSearchField().isFocused();
×
308
    }
309

310
    protected boolean selectPageElement(int elementId) {
311
        ContainerLogicProgrammerBase container = getMenu();
×
312

313
        // Deactivate current element
314
        if (elementId < 0) {
×
315
            handleElementActivation(container.getActiveElement(), true);
×
316
            return false;
×
317
        }
318

319
        // Activate a new element
320
        for(int i = 0; i < container.getPageSize(); i++) {
×
321
            if (container.isElementVisible(i)) {
×
322
                if (elementId-- == 0) {
×
323
                    ILogicProgrammerElement element = container.getVisibleElement(i);
×
324
                    if (container.getActiveElement() != element) {
×
325
                        handleElementActivation(element, true);
×
326
                    }
327
                    return true;
×
328
                }
329
            }
330
        }
331
        return false;
×
332
    }
333

334
    protected boolean handleKeyCode(int keyCode, int scanCode) {
335
        InputConstants.Key inputCode = InputConstants.getKey(keyCode, scanCode);
×
336
        if(keyCode != GLFW.GLFW_KEY_LEFT_SHIFT && keyCode != GLFW.GLFW_KEY_RIGHT_SHIFT) {
×
337
            ContainerLogicProgrammerBase container = getMenu();
×
338
            int pageSize = container.getPageSize();
×
339
            int stepModifier = IModHelpers.get().getMinecraftClientHelpers().isShifted() ? pageSize - 1 : 1;
×
340
            boolean isElementFocused = container.getActiveElement() != null && container.getActiveElement().getClient().isFocused(operatorConfigPattern);
×
341

342
            if (ClientProxy.FOCUS_LP_SEARCH.isActiveAndMatches(inputCode)) {
×
343
                // Focus search field
344
                setSearchFieldFocussed(true);
×
345
                swallowNextCharacter = true;
×
346
                return true;
×
347
            } else if (isElementFocused && ClientProxy.FOCUS_LP_RENAME.isActiveAndMatches(inputCode) && hasLabeller()) {
×
348
                // Open labeller gui
349
                operatorInfoPattern.onButtonEditClick();
×
350
                swallowNextCharacter = true;
×
351
                return true;
×
352
            } else if (GLFW.GLFW_KEY_LEFT == keyCode && (!isElementFocused && isSearchFieldFocussed())) {
×
353
                // Unfocus search field
354
                setSearchFieldFocussed(isSearchFieldFocussed());
×
355
                return true;
×
356
            } else if (!isElementFocused && GLFW.GLFW_KEY_DOWN == keyCode) {
×
357
                // Scroll down
358
                if (!selectPageElement(relativeStep += stepModifier)) {
×
359
                    relativeStep -= stepModifier;
×
360
                    if (relativeStep > 0) {
×
361
                        getScrollbar().scrollRelative(-stepModifier);
×
362
                        selectPageElement(relativeStep);
×
363
                    }
364
                }
365
                return true;
×
366
            } else if (!isElementFocused && GLFW.GLFW_KEY_UP == keyCode) {
×
367
                // Scroll up
368
                if (!(relativeStep >= 0 && selectPageElement(relativeStep -= stepModifier))) {
×
369
                    getScrollbar().scrollRelative(stepModifier);
×
370
                    selectPageElement(relativeStep = 0);
×
371
                }
372
                return true;
×
373
            } else if (!isElementFocused
×
374
                    && (GLFW.GLFW_KEY_RIGHT == keyCode || GLFW.GLFW_KEY_TAB == keyCode
375
                    || GLFW.GLFW_KEY_ENTER == keyCode || GLFW.GLFW_KEY_KP_ENTER == keyCode)) {
376
                if (container.getActiveElement() != null) {
×
377
                    container.getActiveElement().getClient().setFocused(operatorConfigPattern, true);
×
378
                    setSearchFieldFocussed(false);
×
379
                }
380
                return true;
×
381
            }
382
        }
383
        return false;
×
384
    }
385

386
    @Override
387
    public boolean charTyped(char keyCode, int scanCode) {
388
        if (swallowNextCharacter) {
×
389
            swallowNextCharacter = false;
×
390
            return true;
×
391
        }
392

393
        return subGuiHolder.charTyped(keyCode, scanCode) || handleKeyCode(keyCode, scanCode) || super.charTyped(keyCode, scanCode);
×
394
    }
395

396
    @Override
397
    public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
398
        if (keyCode != GLFW.GLFW_KEY_ESCAPE) {
×
399
            if (this.subGuiHolder.keyPressed(keyCode, scanCode, modifiers) || handleKeyCode(keyCode, scanCode)) {
×
400
                return true;
×
401
            }
402
        }
403
        return super.keyPressed(keyCode, scanCode, modifiers);
×
404
    }
405

406
    @Override
407
    public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
408
        if (subGuiHolder.mouseClicked(mouseX, mouseY, mouseButton)) {
×
409
            if (isSearchFieldFocussed()) {
×
410
                setSearchFieldFocussed(false);
×
411
            }
412
            return true;
×
413
        }
414

415
        ContainerLogicProgrammerBase container = getMenu();
×
416
        for(int i = 0; i < container.getPageSize(); i++) {
×
417
            if (container.isElementVisible(i)) {
×
418
                ILogicProgrammerElement element = container.getVisibleElement(i);
×
419
                if (isPointInRegion(getElementPosition(container, i, false), new Point((int) mouseX, (int) mouseY))) {
×
420
                    boolean activated = handleElementActivation(element, true);
×
421
                    relativeStep = activated ? i : -1;
×
422
                    if (activated) {
×
423
                        container.getActiveElement().getClient().setFocused(operatorConfigPattern, true);
×
424
                        setSearchFieldFocussed(false);
×
425
                        return true;
×
426
                    }
427
                }
428
            }
429
        }
430
        boolean superRet = super.mouseClicked(mouseX, mouseY, mouseButton);
×
431

432
        // If the search box has been selected, de-active the current element.
433
        if(isSearchFieldFocussed() &&
×
434
                container.getActiveElement() != null && container.getActiveElement().getClient().isFocused(operatorConfigPattern)) {
×
435
            container.getActiveElement().getClient().setFocused(operatorConfigPattern, false);
×
436
            return true;
×
437
        }
438

439
        return superRet;
×
440
    }
441

442
    protected void label(String label) {
443
        IntegratedDynamics._instance.getPacketHandler().sendToServer(new LogicProgrammerLabelPacket(label));
×
444
    }
×
445

446
    protected boolean hasLabeller() {
447
        return this.hasLabeller;
×
448
    }
449

450
    public class SubGuiOperatorInfo extends SubGuiValueTypeInfoBase<RenderPattern, ContainerScreenLogicProgrammerBase<?>, ContainerLogicProgrammerBase> {
451

452
        private WidgetTextFieldExtended searchField;
453
        private ButtonText button = null;
×
454

455
        public SubGuiOperatorInfo(IGuiInputElement<RenderPattern, ContainerScreenLogicProgrammerBase<?>, ContainerLogicProgrammerBase, ?> element) {
×
456
            super(ContainerScreenLogicProgrammerBase.this, getMenu(), element, 88, 106, 139, 20);
×
457

458
            if(hasLabeller()) {
×
459
                buttonList.add(button = new ButtonText(0, 0, 6, 10, Component.translatable("gui.integrateddynamics.button.edit"), Component.literal("E"),
×
460
                        (button) -> onButtonEditClick(), true));
×
461
            }
462

463
            int searchWidth = 113;
×
464
            this.searchField = new WidgetTextFieldExtended(ContainerScreenLogicProgrammerBase.this.font, 0, 0, searchWidth, 11,
×
465
                    Component.translatable("gui.cyclopscore.search"));
×
466
            this.searchField.setMaxLength(64);
×
467
            this.searchField.setBordered(true);
×
468
            this.searchField.setVisible(false);
×
469
            this.searchField.setTextColor(ARGB.opaque(16777215));
×
470
            this.searchField.setCanLoseFocus(true);
×
471
            this.searchField.setValue("");
×
472
            this.searchField.setWidth(searchWidth);
×
473
        }
×
474

475
        @Override
476
        public void init(int guiLeft, int guiTop) {
477
            super.init(guiLeft, guiTop);
×
478
            int searchX = 90;
×
479
            int searchY = 110;
×
480
            this.searchField.setX(guiLeft + searchX);
×
481
            this.searchField.setY(guiTop + searchY);
×
482

483
            if (hasLabeller()) {
×
484
                button.setX(guiLeft + 220);
×
485
                button.setY(guiTop + 111);
×
486
            }
487
        }
×
488

489
        @Override
490
        protected boolean showError() {
491
            return container.canWriteActiveElementPre();
×
492
        }
493

494
        @Override
495
        protected Component getLastError() {
496
            return container.getLastError();
×
497
        }
498

499
        @Override
500
        protected ResourceLocation getTexture() {
501
            return texture;
×
502
        }
503

504
        @Override
505
        public boolean charTyped(char typedChar, int keyCode) {
506
            if (!this.searchField.isFocused() || !this.searchField.charTyped(typedChar, keyCode)) {
×
507
                return super.charTyped(typedChar, keyCode);
×
508
            } else {
509
                label(this.searchField.getValue());
×
510
                return true;
×
511
            }
512
        }
513

514
        @Override
515
        public boolean keyPressed(int typedChar, int keyCode, int modifiers) {
516
            if (this.searchField.isFocused() && typedChar != GLFW.GLFW_KEY_ESCAPE) {
×
517
                this.searchField.keyPressed(typedChar, keyCode, modifiers);
×
518
                label(this.searchField.getValue());
×
519
                return true;
×
520
            }
521
            return super.keyPressed(typedChar, keyCode, modifiers);
×
522
        }
523

524
        @Override
525
        public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
526
            if(this.searchField.isVisible() && this.searchField.mouseClicked(mouseX, mouseY, mouseButton)) {
×
527
                return true;
×
528
            }
529
            return super.mouseClicked(mouseX, mouseY, mouseButton);
×
530
        }
531

532
        @Override
533
        public void renderBg(GuiGraphics guiGraphics, int guiLeft, int guiTop, TextureManager textureManager, Font font, float partialTicks, int mouseX, int mouseY) {
534
            super.renderBg(guiGraphics, guiLeft, guiTop, textureManager, font, partialTicks, mouseX, mouseY);
×
535
            this.searchField.render(guiGraphics, mouseX, mouseY, partialTicks);
×
536
        }
×
537

538
        @Override
539
        public boolean shouldRenderElementName() {
540
            return !this.searchField.isVisible();
×
541
        }
542

543
        public void onButtonEditClick() {
544
            this.searchField.setVisible(!this.searchField.isVisible());
×
545
            if(this.searchField.isVisible()) {
×
546
                this.searchField.setFocused(true);
×
547
                label(this.searchField.getValue());
×
548
            } else {
549
                label("");
×
550
            }
551
        }
×
552
    }
553

554
}
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