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

CyclopsMC / IntegratedDynamics / 22186773560

19 Feb 2026 02:52PM UTC coverage: 52.603% (+0.2%) from 52.363%
22186773560

push

github

web-flow
Remove Lombok dependency (#1604)

2911 of 8664 branches covered (33.6%)

Branch coverage included in aggregate %.

17683 of 30486 relevant lines covered (58.0%)

3.01 hits per line

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

12.79
/src/main/java/org/cyclops/integrateddynamics/core/evaluate/variable/ValueTypeOperator.java
1
package org.cyclops.integrateddynamics.core.evaluate.variable;
2

3
import com.google.common.collect.Lists;
4
import net.minecraft.ChatFormatting;
5
import net.minecraft.network.chat.Component;
6
import net.minecraft.network.chat.MutableComponent;
7
import net.minecraft.world.level.storage.ValueInput;
8
import net.minecraft.world.level.storage.ValueOutput;
9
import org.cyclops.cyclopscore.helper.IModHelpers;
10
import org.cyclops.integrateddynamics.api.advancement.criterion.ValuePredicate;
11
import org.cyclops.integrateddynamics.api.evaluate.EvaluationException;
12
import org.cyclops.integrateddynamics.api.evaluate.operator.IOperator;
13
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueType;
14
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueTypeNamed;
15
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueTypeUniquelyNamed;
16
import org.cyclops.integrateddynamics.core.evaluate.operator.Operators;
17
import org.cyclops.integrateddynamics.core.helper.L10NValues;
18
import org.cyclops.integrateddynamics.core.logicprogrammer.ValueTypeLPElementBase;
19
import org.cyclops.integrateddynamics.core.logicprogrammer.ValueTypeOperatorLPElement;
20

21
import javax.annotation.Nullable;
22
import java.util.List;
23
import java.util.Optional;
24
import java.util.function.Consumer;
25

26
/**
27
 * Value type with operator values.
28
 * @author rubensworks
29
 */
30
public class ValueTypeOperator extends ValueTypeBase<ValueTypeOperator.ValueOperator> implements
31
        IValueTypeNamed<ValueTypeOperator.ValueOperator>, IValueTypeUniquelyNamed<ValueTypeOperator.ValueOperator> {
32

33
    private static final String SIGNATURE_LINK = "->";
34

35
    public ValueTypeOperator() {
36
        super("operator", IModHelpers.get().getBaseHelpers().RGBToInt(43, 231, 47), ChatFormatting.DARK_GREEN, ValueTypeOperator.ValueOperator.class);
11✔
37
    }
1✔
38

39
    @Override
40
    public ValueOperator getDefault() {
41
        return ValueOperator.of(Operators.GENERAL_IDENTITY);
×
42
    }
43

44
    @Override
45
    public MutableComponent toCompactString(ValueOperator value) {
46
        return value.getRawValue().getLocalizedNameFull();
×
47
    }
48

49
    @Override
50
    public void serialize(ValueOutput valueOutput, ValueOperator value) {
51
        Operators.REGISTRY.serialize(valueOutput.child("v"), value.getRawValue());
×
52
    }
×
53

54
    @Override
55
    public ValueOperator deserialize(ValueInput valueInput) {
56
        IOperator operator;
57
        try {
58
            operator = Operators.REGISTRY.deserialize(valueInput.child("v").orElseThrow());
×
59
        } catch (EvaluationException e) {
×
60
            throw new IllegalArgumentException(e.getMessage());
×
61
        }
×
62
        if (operator != null) {
×
63
            return ValueOperator.of(operator);
×
64
        }
65
        throw new IllegalArgumentException(String.format("Value \"%s\" could not be parsed to an operator.", valueInput));
×
66
    }
67

68
    @Override
69
    public void loadTooltip(Consumer<Component> tooltipAdder, boolean appendOptionalInfo, @Nullable ValueOperator value) {
70
        super.loadTooltip(tooltipAdder, appendOptionalInfo, value);
×
71
        if (value != null) {
×
72
            tooltipAdder.accept(Component.translatable(L10NValues.VALUETYPEOPERATOR_TOOLTIP_SIGNATURE)
×
73
                    .append(getSignature(value.getRawValue())));
×
74
        }
75
    }
×
76

77
    @Override
78
    public ValueTypeLPElementBase createLogicProgrammerElement() {
79
        return new ValueTypeOperatorLPElement();
×
80
    }
81

82
    @Override
83
    public ValueOperator materialize(ValueOperator value) throws EvaluationException {
84
        return ValueOperator.of(value.getRawValue().materialize());
×
85
    }
86

87
    /**
88
     * Pretty formatted signature of an operator.
89
     * @param operator The operator.
90
     * @return The signature.
91
     */
92
    public static MutableComponent getSignature(IOperator operator) {
93
        return getSignatureLines(operator, false)
×
94
                .stream()
×
95
                .reduce(Component.literal(""), (a, b) -> a.append(" ").append(b));
×
96
    }
97

98
    /**
99
     * Pretty formatted signature of an operator.
100
     * @param inputTypes The input types.
101
     * @param outputType The output types.
102
     * @return The signature.
103
     */
104
    public static Component getSignature(IValueType[] inputTypes, IValueType outputType) {
105
        return getSignatureLines(inputTypes, outputType, false)
×
106
                .stream()
×
107
                .reduce((prev, next) -> prev.append(" ").append(next))
×
108
                .orElseGet(() -> Component.literal(""));
×
109
    }
110

111
    protected static MutableComponent switchSignatureLineContext(List<MutableComponent> lines, MutableComponent sb) {
112
        lines.add(sb);
×
113
        return Component.literal("");
×
114
    }
115

116
    /**
117
     * Pretty formatted signature of an operator.
118
     * @param inputTypes The input types.
119
     * @param outputType The output types.
120
     * @param indent If the lines should be indented.
121
     * @return The signature.
122
     */
123
    public static List<MutableComponent> getSignatureLines(IValueType[] inputTypes, IValueType outputType, boolean indent) {
124
        List<MutableComponent> lines = Lists.newArrayList();
×
125
        MutableComponent sb = Component.literal("");
×
126
        boolean first = true;
×
127
        for (IValueType inputType : inputTypes) {
×
128
            if (first) {
×
129
                first = false;
×
130
            } else {
131
                sb = switchSignatureLineContext(lines, sb);
×
132
                sb.append((indent ? "  " : "") + SIGNATURE_LINK + " ");
×
133
            }
134
            sb = sb.append(Component.translatable(inputType.getTranslationKey())
×
135
                    .withStyle(inputType.getDisplayColorFormat()));
×
136
        }
137

138
        sb = switchSignatureLineContext(lines, sb);
×
139
        sb = sb.append((indent ? "  " : "") + SIGNATURE_LINK + " ")
×
140
                .append(Component.translatable(outputType.getTranslationKey())
×
141
                        .withStyle(outputType.getDisplayColorFormat()));
×
142
        switchSignatureLineContext(lines, sb);
×
143
        return lines;
×
144
    }
145

146
    /**
147
     * Pretty formatted signature of an operator.
148
     * @param operator The operator.
149
     * @param indent If the lines should be indented.
150
     * @return The signature.
151
     */
152
    public static List<MutableComponent> getSignatureLines(IOperator operator, boolean indent) {
153
        return getSignatureLines(operator.getInputTypes(), operator.getOutputType(), indent);
×
154
    }
155

156
    @Override
157
    public String getName(ValueTypeOperator.ValueOperator a) {
158
        return a.getRawValue().getLocalizedNameFull().getString();
×
159
    }
160

161
    @Override
162
    public String getUniqueName(ValueOperator a) {
163
        return a.getRawValue().getUniqueName().toString();
×
164
    }
165

166
    public static class ValueOperator extends ValueBase {
167

168
        private final IOperator value;
169

170
        private ValueOperator(IOperator value) {
171
            super(ValueTypes.OPERATOR);
3✔
172
            this.value = value;
3✔
173
        }
1✔
174

175
        public static ValueOperator of(IOperator value) {
176
            return new ValueOperator(value);
5✔
177
        }
178

179
        public IOperator getRawValue() {
180
            return value;
3✔
181
        }
182

183
        @Override
184
        public boolean equals(Object o) {
185
            return o == this || (o instanceof ValueOperator && value.equals(((ValueOperator) o).value));
16!
186
        }
187

188
        @Override
189
        public int hashCode() {
190
            return 37 + value.hashCode();
×
191
        }
192

193
        @Override
194
        public String toString() {
195
            return "ValueOperator(value=" + this.value + ")";
×
196
        }
197
    }
198

199
    public static class ValueOperatorPredicate extends ValuePredicate<ValueOperator> {
200

201
        private final Optional<IOperator> operator;
202

203
        public ValueOperatorPredicate(Optional<IOperator> operator) {
204
            super(Optional.of(ValueTypes.OPERATOR), Optional.empty(), Optional.empty());
×
205
            this.operator = operator;
×
206
        }
×
207

208
        public Optional<IOperator> getOperator() {
209
            return operator;
×
210
        }
211

212
        @Override
213
        protected boolean testTyped(ValueOperator value) {
214
            return super.testTyped(value)
×
215
                    && (operator.isEmpty() || (value.getRawValue() == operator.get()));
×
216
        }
217
    }
218

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