• 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/ContainerScreenLabeller.java
1
package org.cyclops.integrateddynamics.client.gui.container;
2

3
import net.minecraft.client.gui.GuiGraphics;
4
import net.minecraft.core.component.DataComponents;
5
import net.minecraft.network.chat.Component;
6
import net.minecraft.resources.ResourceLocation;
7
import net.minecraft.util.ARGB;
8
import net.minecraft.world.entity.player.Inventory;
9
import net.minecraft.world.item.ItemStack;
10
import org.apache.commons.lang3.StringUtils;
11
import org.cyclops.cyclopscore.client.gui.component.button.ButtonText;
12
import org.cyclops.cyclopscore.client.gui.component.input.WidgetTextFieldExtended;
13
import org.cyclops.cyclopscore.client.gui.container.ContainerScreenExtended;
14
import org.cyclops.cyclopscore.inventory.SimpleInventory;
15
import org.cyclops.integrateddynamics.IntegratedDynamics;
16
import org.cyclops.integrateddynamics.Reference;
17
import org.cyclops.integrateddynamics.api.evaluate.variable.ValueDeseralizationContext;
18
import org.cyclops.integrateddynamics.api.item.IVariableFacade;
19
import org.cyclops.integrateddynamics.api.item.IVariableFacadeHandlerRegistry;
20
import org.cyclops.integrateddynamics.core.persist.world.LabelsWorldStorage;
21
import org.cyclops.integrateddynamics.inventory.container.ContainerLabeller;
22
import org.cyclops.integrateddynamics.network.packet.ItemStackRenamePacket;
23
import org.lwjgl.glfw.GLFW;
24

25
/**
26
 * Gui for the labeller.
27
 * @author rubensworks
28
 */
29
public class ContainerScreenLabeller extends ContainerScreenExtended<ContainerLabeller> {
30

31
    private WidgetTextFieldExtended searchField;
32

33
    public ContainerScreenLabeller(ContainerLabeller container, Inventory playerInventory, Component title) {
34
        super(container, playerInventory, title);
×
35
        SimpleInventory temporaryInputSlots = container.getTemporaryInputSlots();
×
36
        temporaryInputSlots.addDirtyMarkListener(() -> {
×
37
            ItemStack itemStack = temporaryInputSlots.getItem(0);
×
38
            IVariableFacadeHandlerRegistry registry = IntegratedDynamics._instance.getRegistryManager().getRegistry(IVariableFacadeHandlerRegistry.class);
×
39
            IVariableFacade variableFacade = registry.handle(ValueDeseralizationContext.of(container.getPlayerIInventory().player.level()), itemStack);
×
40
            String label = LabelsWorldStorage.Access.getInstance(IntegratedDynamics._instance).get().getLabel(variableFacade.getId());
×
41
            if(label == null && !itemStack.isEmpty() && itemStack.has(DataComponents.CUSTOM_NAME)) {
×
42
                label = itemStack.getHoverName().getString();
×
43
            }
44
            if(label != null) {
×
45
                this.setText(label);
×
46
            }
47
        });
×
48
    }
×
49

50
    @Override
51
    protected ResourceLocation constructGuiTexture() {
52
        return ResourceLocation.fromNamespaceAndPath(Reference.MOD_ID, "textures/gui/labeller.png");
×
53
    }
54

55
    @Override
56
    public void init() {
57
        super.init();
×
58
        addRenderableWidget(new ButtonText(this.leftPos + 133,  this.topPos + 8,
×
59
                Component.translatable("item.integrateddynamics.labeller.button.write"),
×
60
                Component.translatable("item.integrateddynamics.labeller.button.write"), button -> {
×
61
            ItemStack itemStack = getMenu().getItemStack();
×
62
            IVariableFacadeHandlerRegistry registry = IntegratedDynamics._instance.getRegistryManager().getRegistry(IVariableFacadeHandlerRegistry.class);
×
63
            IVariableFacade variableFacade = registry.handle(ValueDeseralizationContext.of(container.getPlayerIInventory().player.level()), itemStack);
×
64
            if(variableFacade.isValid()) {
×
65
                int variableId = variableFacade.getId();
×
66
                String label = StringUtils.isBlank(searchField.getValue()) ? "" : searchField.getValue();
×
67
                LabelsWorldStorage.Access.getInstance(IntegratedDynamics._instance).get().put(variableId, label);
×
68
            } else if(!itemStack.isEmpty()) {
×
69
                String name = searchField.getValue();
×
70
                IntegratedDynamics._instance.getPacketHandler().sendToServer(new ItemStackRenamePacket(name));
×
71
                getMenu().setItemStackName(name);
×
72
            }
73
        }));
×
74

75
        int searchWidth = 87;
×
76
        int searchX = 36;
×
77
        int searchY = 11;
×
78
        this.searchField = new WidgetTextFieldExtended(font, this.leftPos + searchX, this.topPos + searchY, searchWidth, font.lineHeight, Component.translatable("gui.cyclopscore.search"));
×
79
        this.searchField.setMaxLength(64);
×
80
        this.searchField.setBordered(false);
×
81
        this.searchField.setVisible(true);
×
82
        this.searchField.setFocused(true);
×
83
        this.searchField.setTextColor(ARGB.opaque(16777215));
×
84
        this.searchField.setCanLoseFocus(false);
×
85
        this.searchField.setValue("");
×
86
        this.searchField.setX(this.leftPos + (searchX + searchWidth) - this.searchField.getWidth());
×
87
    }
×
88

89
    @Override
90
    protected int getBaseYSize() {
91
        return 113;
×
92
    }
93

94
    @Override
95
    public boolean charTyped(char typedChar, int keyCode) {
96
        if (!this.searchField.charTyped(typedChar, keyCode)) {
×
97
            return super.charTyped(typedChar, keyCode);
×
98
        }
99
        return true;
×
100
    }
101

102
    @Override
103
    public boolean keyPressed(int typedChar, int keyCode, int modifiers) {
104
        if (typedChar != GLFW.GLFW_KEY_ESCAPE) {
×
105
            this.searchField.keyPressed(typedChar, keyCode, modifiers);
×
106
            return true;
×
107
        }
108
        return super.keyPressed(typedChar, keyCode, modifiers);
×
109
    }
110

111
    @Override
112
    public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
113
        return this.searchField.mouseClicked(mouseX, mouseY, mouseButton)
×
114
                || super.mouseClicked(mouseX, mouseY, mouseButton);
×
115
    }
116

117
    @Override
118
    protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
119
        // super
120
    }
×
121

122
    @Override
123
    protected void renderBg(GuiGraphics guiGraphics, float partialTicks, int mouseX, int mouseY) {
124
        super.renderBg(guiGraphics, partialTicks, mouseX, mouseY);
×
125
        this.searchField.render(guiGraphics, mouseX, mouseY, partialTicks);
×
126
    }
×
127

128
    public void setText(String text) {
129
        this.searchField.setValue(text);
×
130
    }
×
131

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