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

CyclopsMC / CyclopsCore / #479033821

15 Feb 2026 06:24AM UTC coverage: 22.618% (+0.5%) from 22.089%
#479033821

Pull #217

github

web-flow
Merge 67551548d into 21ed06935
Pull Request #217: Fix logical operator evaluation context and test syntax

77 of 92 new or added lines in 6 files covered. (83.7%)

30 existing lines in 1 file now uncovered.

2374 of 10496 relevant lines covered (22.62%)

0.23 hits per line

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

0.0
/src/main/java/org/cyclops/cyclopscore/client/gui/component/input/WidgetNumberField.java
1
package org.cyclops.cyclopscore.client.gui.component.input;
2

3
import com.mojang.blaze3d.vertex.PoseStack;
4
import net.minecraft.client.gui.Font;
5
import net.minecraft.network.chat.Component;
6
import org.cyclops.cyclopscore.client.gui.component.button.ButtonArrow;
7
import org.cyclops.cyclopscore.helper.MinecraftHelpers;
8

9
/**
10
 * A number field which by default only accepts positive numbers.
11
 * @author rubensworks
12
 */
13
public class WidgetNumberField extends WidgetTextFieldExtended {
14

15
    private final boolean arrows;
16
    private ButtonArrow arrowUp;
17
    private ButtonArrow arrowDown;
18
    private int minValue = Integer.MIN_VALUE;
×
19
    private int maxValue = Integer.MAX_VALUE;
×
20
    private boolean isEnabled = true;
×
21

22
    public WidgetNumberField(Font fontrenderer, int x, int y, int width, int height, boolean arrows,
23
                             Component narrationMessage, boolean background) {
24
        super(fontrenderer, x, y, width, height, narrationMessage, background);
×
25
        this.arrows = arrows;
×
26

27
        if(this.arrows) {
×
28
            arrowUp = new ButtonArrow(x, y + height / 2, Component.translatable("gui.cyclopscore.up"), (button) -> this.increase(), ButtonArrow.Direction.NORTH);
×
29
            arrowDown = new ButtonArrow(x, y + height / 2, Component.translatable("gui.cyclopscore.down"), (button) -> this.decrease(), ButtonArrow.Direction.SOUTH);
×
30
            arrowUp.y -= arrowUp.getHeight();
×
31
        }
32
        setBordered(true);
×
33
        setValue("0");
×
34
    }
×
35

36
    @Override
37
    public void setEditable(boolean enabled) {
38
        arrowUp.active = enabled;
×
39
        arrowDown.active = enabled;
×
40
        isEnabled = enabled;
×
41
        super.setEditable(enabled);
×
42
    }
×
43

44
    @Override
45
    public boolean isBordered() {
46
        return false; // We want the offset, but not the drawing itself.
×
47
    }
48

49
    public void setPositiveOnly(boolean positiveOnly) {
50
        setMinValue(positiveOnly ? 0 : Integer.MIN_VALUE);
×
51
    }
×
52

53
    public int getMinValue() {
54
        return minValue;
×
55
    }
56

57
    /**
58
     * @param minValue The minimal value (inclusive)
59
     */
60
    public void setMinValue(int minValue) {
61
        this.minValue = minValue;
×
62
        try {
63
            if (this.minValue > Integer.parseInt(getValue())) {
×
UNCOV
64
                setValue(Integer.toString(this.minValue));
×
65
            }
66
        } catch (NumberFormatException e) {
×
UNCOV
67
            setValue(Integer.toString(this.minValue));
×
UNCOV
68
        }
×
UNCOV
69
        updateArrowsState();
×
UNCOV
70
    }
×
71

72
    public int getMaxValue() {
73
        return maxValue;
×
74
    }
75

76
    /**
77
     * @param maxValue The maximal value (inclusive)
78
     */
79
    public void setMaxValue(int maxValue) {
UNCOV
80
        this.maxValue = maxValue;
×
81
    }
×
82

83
    public int getInt() throws NumberFormatException {
UNCOV
84
        return validateNumber(Integer.parseInt(getValue()));
×
85
    }
86

87
    public double getDouble() throws NumberFormatException {
UNCOV
88
        return validateNumber(Double.parseDouble(getValue()));
×
89
    }
90

91
    public float getFloat() throws NumberFormatException {
92
        return validateNumber(Float.parseFloat(getValue()));
×
93
    }
94

95
    @Override
96
    public void renderButton(PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) {
UNCOV
97
        int offsetX = 0;
×
98
        if(arrows) {
×
99
            arrowUp.renderButton(matrixStack, mouseX, mouseY, partialTicks);
×
100
            arrowDown.renderButton(matrixStack, mouseX, mouseY, partialTicks);
×
101
            offsetX = arrowUp.getWidth();
×
UNCOV
102
            x += offsetX;
×
103
            width -= offsetX;
×
104
        }
UNCOV
105
        super.renderButton(matrixStack, mouseX, mouseY, partialTicks);
×
106
        if(arrows) {
×
UNCOV
107
            x -= offsetX;
×
UNCOV
108
            width += offsetX;
×
109
        }
110
    }
×
111

112
    public int validateNumber(int number) {
UNCOV
113
        return Math.max(this.minValue, Math.min(this.maxValue, number));
×
114
    }
115

116
    public double validateNumber(double number) {
UNCOV
117
        return Math.max(this.minValue, Math.min(this.maxValue, number));
×
118
    }
119

120
    public float validateNumber(float number) {
UNCOV
121
        return Math.max(this.minValue, Math.min(this.maxValue, number));
×
122
    }
123

124
    protected int getDiffAmount() {
125
        return MinecraftHelpers.isShifted() ? 10 : 1;
×
126
    }
127

128
    protected void increase() {
129
        try {
UNCOV
130
            setValue(Integer.toString(validateNumber(getInt() + getDiffAmount())));
×
UNCOV
131
        } catch (NumberFormatException e) {
×
132
            setValue("0");
×
133
        }
×
134
        updateArrowsState();
×
135
    }
×
136

137
    protected void decrease() {
138
        try {
UNCOV
139
            setValue(Integer.toString(validateNumber(getInt() - getDiffAmount())));
×
UNCOV
140
        } catch (NumberFormatException e) {
×
141
            setValue("0");
×
142
        }
×
143
        updateArrowsState();
×
UNCOV
144
    }
×
145

146
    @Override
147
    public void setValue(String value) {
148
        super.setValue(value);
×
149
        updateArrowsState();
×
UNCOV
150
    }
×
151

152
    @Override
153
    public boolean charTyped(char typedChar, int keyCode) {
154
        boolean ret = super.charTyped(typedChar, keyCode);
×
155
        updateArrowsState();
×
156
        return ret;
×
157
    }
158

159
    @Override
160
    public boolean keyPressed(int typedChar, int keyCode, int modifiers) {
161
        boolean ret = super.keyPressed(typedChar, keyCode, modifiers);
×
162
        updateArrowsState();
×
163
        return ret;
×
164
    }
165

166
    @Override
167
    public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
UNCOV
168
        boolean ret = arrowUp.mouseClicked(mouseX, mouseY, mouseButton)
×
169
                || arrowDown.mouseClicked(mouseX, mouseY, mouseButton)
×
170
                || super.mouseClicked(mouseX, mouseY, mouseButton);
×
171
        updateArrowsState();
×
UNCOV
172
        return ret;
×
173
    }
174

175
    protected void updateArrowsState() {
176
        if (this.arrows) {
×
177
            arrowDown.active = true;
×
UNCOV
178
            arrowUp.active = true;
×
179
            try {
UNCOV
180
                if (getInt() <= this.minValue) {
×
181
                    arrowDown.active = false;
×
182
                }
183
                if (getInt() >= this.maxValue) {
×
UNCOV
184
                    arrowUp.active = false;
×
185
                }
UNCOV
186
            } catch (NumberFormatException e) {
×
187

UNCOV
188
            }
×
189
        }
UNCOV
190
    }
×
191

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