• 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/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.input.CharacterEvent;
9
import net.minecraft.client.input.KeyEvent;
10
import net.minecraft.client.input.MouseButtonEvent;
11
import net.minecraft.client.renderer.RenderPipelines;
12
import net.minecraft.client.renderer.texture.TextureManager;
13
import net.minecraft.network.chat.Component;
14
import net.minecraft.network.chat.MutableComponent;
15
import net.minecraft.resources.ResourceLocation;
16
import net.minecraft.util.ARGB;
17
import net.minecraft.world.entity.player.Inventory;
18
import net.minecraft.world.item.ItemStack;
19
import org.apache.commons.lang3.tuple.Triple;
20
import org.cyclops.cyclopscore.client.gui.component.button.ButtonText;
21
import org.cyclops.cyclopscore.client.gui.component.input.WidgetTextFieldExtended;
22
import org.cyclops.cyclopscore.client.gui.container.ContainerScreenScrolling;
23
import org.cyclops.cyclopscore.client.gui.image.Images;
24
import org.cyclops.cyclopscore.helper.IModHelpers;
25
import org.cyclops.integrateddynamics.IntegratedDynamics;
26
import org.cyclops.integrateddynamics.Reference;
27
import org.cyclops.integrateddynamics.RegistryEntries;
28
import org.cyclops.integrateddynamics.api.client.gui.subgui.IGuiInputElement;
29
import org.cyclops.integrateddynamics.api.logicprogrammer.ILogicProgrammerElement;
30
import org.cyclops.integrateddynamics.api.logicprogrammer.ILogicProgrammerElementType;
31
import org.cyclops.integrateddynamics.core.client.gui.subgui.SubGuiHolder;
32
import org.cyclops.integrateddynamics.core.evaluate.variable.gui.SubGuiValueTypeInfoBase;
33
import org.cyclops.integrateddynamics.core.helper.L10NValues;
34
import org.cyclops.integrateddynamics.core.logicprogrammer.LogicProgrammerElementTypes;
35
import org.cyclops.integrateddynamics.core.logicprogrammer.client.RenderPattern;
36
import org.cyclops.integrateddynamics.inventory.container.ContainerLogicProgrammerBase;
37
import org.cyclops.integrateddynamics.network.packet.LogicProgrammerActivateElementPacket;
38
import org.cyclops.integrateddynamics.network.packet.LogicProgrammerLabelPacket;
39
import org.cyclops.integrateddynamics.proxy.ClientProxy;
40
import org.lwjgl.glfw.GLFW;
41

42
import javax.annotation.Nullable;
43
import java.awt.*;
44
import java.util.List;
45

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

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

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

66
    public ContainerScreenLogicProgrammerBase(C container, Inventory playerInventory, Component title) {
67
        super(container, playerInventory, title);
×
68
        container.setScreenCallbackHandler(this);
×
69
        this.titleLabelX = 87;
×
70

71
        this.hasLabeller = playerInventory.contains(new ItemStack(RegistryEntries.ITEM_LABELLER));
×
72
    }
×
73

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

79
    @Override
80
    public void init() {
81
        super.init();
×
82

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

95
        subGuiHolder.init(this.leftPos, this.topPos);
×
96
        if (firstInit) {
×
97
            setSearchFieldFocussed(true);
×
98
            firstInit = false;
×
99
        }
100
    }
×
101

102
    @Override
103
    public void containerTick() {
104
        super.containerTick();
×
105
        subGuiHolder.tick();
×
106
    }
×
107

108
    protected int getScrollX() {
109
        return 5;
×
110
    }
111

112
    protected int getScrollY() {
113
        return 18;
×
114
    }
115

116
    protected int getScrollHeight() {
117
        return 178;
×
118
    }
119

120
    @Override
121
    protected int getBaseXSize() {
122
        return 256;
×
123
    }
124

125
    @Override
126
    protected int getBaseYSize() {
127
        return 240;
×
128
    }
129

130
    @Override
131
    protected int getSearchX() {
132
        return 6;
×
133
    }
134

135
    protected int getSearchWidth() {
136
        return 70;
×
137
    }
138

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

144
    protected float colorSmoothener(float color, boolean hover) {
145
        return 1F - ((1F - color) / (hover ? 2F : 4F));
×
146
    }
147

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

255
    protected void onDeactivateElement(ILogicProgrammerElement element) {
256
        subGuiHolder.clear();
×
257
    }
×
258

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

299
    @Nullable
300
    @Override
301
    public RenderPattern getOperatorConfigPattern() {
302
        return operatorConfigPattern;
×
303
    }
304

305
    protected void setSearchFieldFocussed(boolean focused) {
306
        getSearchField().setFocused(focused);
×
307
    }
×
308

309
    protected boolean isSearchFieldFocussed() {
310
        return getSearchField().isFocused();
×
311
    }
312

313
    protected boolean selectPageElement(int elementId) {
314
        ContainerLogicProgrammerBase container = getMenu();
×
315

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

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

337
    protected boolean handleKeyCode(KeyEvent evt) {
338
        InputConstants.Key inputCode = InputConstants.getKey(evt);
×
339
        if(evt.key() != GLFW.GLFW_KEY_LEFT_SHIFT && evt.key() != GLFW.GLFW_KEY_RIGHT_SHIFT) {
×
340
            ContainerLogicProgrammerBase container = getMenu();
×
341
            int pageSize = container.getPageSize();
×
342
            int stepModifier = IModHelpers.get().getMinecraftClientHelpers().isShifted() ? pageSize - 1 : 1;
×
343
            boolean isElementFocused = container.getActiveElement() != null && container.getActiveElement().getClient().isFocused(operatorConfigPattern);
×
344

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

389
    @Override
390
    public boolean charTyped(CharacterEvent evt) {
391
        if (swallowNextCharacter) {
×
392
            swallowNextCharacter = false;
×
393
            return true;
×
394
        }
395

396
        return subGuiHolder.charTyped(evt) || handleKeyCode(new KeyEvent(evt.codepoint(), evt.modifiers(), 0)) || super.charTyped(evt);
×
397
    }
398

399
    @Override
400
    public boolean keyPressed(KeyEvent evt) {
401
        if (evt.key() != GLFW.GLFW_KEY_ESCAPE) {
×
402
            if (this.subGuiHolder.keyPressed(evt) || handleKeyCode(evt)) {
×
403
                return true;
×
404
            }
405
        }
406
        return super.keyPressed(evt);
×
407
    }
408

409
    @Override
410
    public boolean mouseClicked(MouseButtonEvent evt, boolean isDoubleClick) {
411
        if (subGuiHolder.mouseClicked(evt, isDoubleClick)) {
×
412
            if (isSearchFieldFocussed()) {
×
413
                setSearchFieldFocussed(false);
×
414
            }
415
            return true;
×
416
        }
417

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

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

442
        return superRet;
×
443
    }
444

445
    protected void label(String label) {
446
        IntegratedDynamics._instance.getPacketHandler().sendToServer(new LogicProgrammerLabelPacket(label));
×
447
    }
×
448

449
    protected boolean hasLabeller() {
450
        return this.hasLabeller;
×
451
    }
452

453
    public class SubGuiOperatorInfo extends SubGuiValueTypeInfoBase<RenderPattern, ContainerScreenLogicProgrammerBase<?>, ContainerLogicProgrammerBase> {
454

455
        private WidgetTextFieldExtended searchField;
456
        private ButtonText button = null;
×
457

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

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

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

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

486
            if (hasLabeller()) {
×
487
                button.setX(guiLeft + 220);
×
488
                button.setY(guiTop + 111);
×
489
            }
490
        }
×
491

492
        @Override
493
        protected boolean showError() {
494
            return container.canWriteActiveElementPre();
×
495
        }
496

497
        @Override
498
        protected Component getLastError() {
499
            return container.getLastError();
×
500
        }
501

502
        @Override
503
        protected ResourceLocation getTexture() {
504
            return texture;
×
505
        }
506

507
        @Override
508
        public boolean charTyped(CharacterEvent evt) {
509
            if (!this.searchField.isFocused() || !this.searchField.charTyped(evt)) {
×
510
                return super.charTyped(evt);
×
511
            } else {
512
                label(this.searchField.getValue());
×
513
                return true;
×
514
            }
515
        }
516

517
        @Override
518
        public boolean keyPressed(KeyEvent evt) {
519
            if (this.searchField.isFocused() && evt.key() != GLFW.GLFW_KEY_ESCAPE) {
×
520
                this.searchField.keyPressed(evt);
×
521
                label(this.searchField.getValue());
×
522
                return true;
×
523
            }
524
            return super.keyPressed(evt);
×
525
        }
526

527
        @Override
528
        public boolean mouseClicked(MouseButtonEvent evt, boolean isDoubleClick) {
529
            if(this.searchField.isVisible() && this.searchField.mouseClicked(evt, isDoubleClick)) {
×
530
                return true;
×
531
            }
532
            return super.mouseClicked(evt, isDoubleClick);
×
533
        }
534

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

541
        @Override
542
        public boolean shouldRenderElementName() {
543
            return !this.searchField.isVisible();
×
544
        }
545

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

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