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

CyclopsMC / IntegratedDynamics / 20551126965

28 Dec 2025 08:18AM UTC coverage: 53.079% (-0.03%) from 53.11%
20551126965

push

github

rubensworks
Merge remote-tracking branch 'origin/master-1.21-lts' into master-1.21

2861 of 8754 branches covered (32.68%)

Branch coverage included in aggregate %.

17432 of 29478 relevant lines covered (59.14%)

3.07 hits per line

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

85.17
/src/main/java/org/cyclops/integrateddynamics/core/evaluate/operator/Operators.java
1
package org.cyclops.integrateddynamics.core.evaluate.operator;
2

3
import com.google.common.collect.*;
4
import com.google.re2j.Matcher;
5
import com.google.re2j.Pattern;
6
import com.google.re2j.PatternSyntaxException;
7
import com.mojang.brigadier.exceptions.CommandSyntaxException;
8
import com.mojang.logging.LogUtils;
9
import lombok.Lombok;
10
import net.minecraft.IdentifierException;
11
import net.minecraft.core.component.DataComponentPatch;
12
import net.minecraft.core.component.DataComponentType;
13
import net.minecraft.core.component.DataComponents;
14
import net.minecraft.core.component.TypedDataComponent;
15
import net.minecraft.core.registries.BuiltInRegistries;
16
import net.minecraft.nbt.*;
17
import net.minecraft.network.chat.Component;
18
import net.minecraft.network.chat.MutableComponent;
19
import net.minecraft.resources.Identifier;
20
import net.minecraft.util.ProblemReporter;
21
import net.minecraft.util.StringUtil;
22
import net.minecraft.world.entity.AgeableMob;
23
import net.minecraft.world.entity.Entity;
24
import net.minecraft.world.entity.LivingEntity;
25
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
26
import net.minecraft.world.entity.ai.attributes.Attributes;
27
import net.minecraft.world.entity.animal.Animal;
28
import net.minecraft.world.entity.decoration.ItemFrame;
29
import net.minecraft.world.entity.item.ItemEntity;
30
import net.minecraft.world.entity.monster.Enemy;
31
import net.minecraft.world.entity.player.Player;
32
import net.minecraft.world.entity.projectile.ProjectileUtil;
33
import net.minecraft.world.entity.vehicle.minecart.AbstractMinecart;
34
import net.minecraft.world.item.BlockItem;
35
import net.minecraft.world.item.Item;
36
import net.minecraft.world.item.ItemStack;
37
import net.minecraft.world.item.TooltipFlag;
38
import net.minecraft.world.item.crafting.RecipeType;
39
import net.minecraft.world.level.ClipContext;
40
import net.minecraft.world.level.block.Block;
41
import net.minecraft.world.level.block.SoundType;
42
import net.minecraft.world.level.block.state.BlockState;
43
import net.minecraft.world.level.block.state.properties.Property;
44
import net.minecraft.world.level.material.Fluid;
45
import net.minecraft.world.level.storage.TagValueOutput;
46
import net.minecraft.world.phys.*;
47
import net.neoforged.neoforge.capabilities.Capabilities;
48
import net.neoforged.neoforge.common.IShearable;
49
import net.neoforged.neoforge.common.SoundActions;
50
import net.neoforged.neoforge.event.EventHooks;
51
import net.neoforged.neoforge.fluids.FluidStack;
52
import net.neoforged.neoforge.server.ServerLifecycleHooks;
53
import net.neoforged.neoforge.transfer.ResourceHandler;
54
import net.neoforged.neoforge.transfer.access.ItemAccess;
55
import net.neoforged.neoforge.transfer.energy.EnergyHandler;
56
import net.neoforged.neoforge.transfer.item.ItemResource;
57
import org.apache.commons.lang3.tuple.Pair;
58
import org.apache.commons.lang3.tuple.Triple;
59
import org.cyclops.commoncapabilities.api.capability.itemhandler.ItemMatch;
60
import org.cyclops.commoncapabilities.api.capability.recipehandler.IPrototypedIngredientAlternatives;
61
import org.cyclops.commoncapabilities.api.capability.recipehandler.IRecipeDefinition;
62
import org.cyclops.commoncapabilities.api.capability.recipehandler.PrototypedIngredientAlternativesList;
63
import org.cyclops.commoncapabilities.api.capability.recipehandler.RecipeDefinition;
64
import org.cyclops.commoncapabilities.api.ingredient.*;
65
import org.cyclops.cyclopscore.helper.IModHelpers;
66
import org.cyclops.cyclopscore.helper.IModHelpersNeoForge;
67
import org.cyclops.cyclopscore.nbt.path.INbtPathExpression;
68
import org.cyclops.cyclopscore.nbt.path.NbtParseException;
69
import org.cyclops.cyclopscore.nbt.path.NbtPath;
70
import org.cyclops.integrateddynamics.IntegratedDynamics;
71
import org.cyclops.integrateddynamics.api.evaluate.EvaluationException;
72
import org.cyclops.integrateddynamics.api.evaluate.operator.IOperator;
73
import org.cyclops.integrateddynamics.api.evaluate.operator.IOperatorRegistry;
74
import org.cyclops.integrateddynamics.api.evaluate.variable.*;
75
import org.cyclops.integrateddynamics.api.logicprogrammer.IConfigRenderPattern;
76
import org.cyclops.integrateddynamics.core.evaluate.IOperatorValuePropagator;
77
import org.cyclops.integrateddynamics.core.evaluate.OperatorBuilders;
78
import org.cyclops.integrateddynamics.core.evaluate.variable.*;
79
import org.cyclops.integrateddynamics.core.helper.Helpers;
80
import org.cyclops.integrateddynamics.core.helper.L10NValues;
81
import org.cyclops.integrateddynamics.core.helper.NbtHelpers;
82
import org.cyclops.integrateddynamics.core.ingredient.ExtendedIngredientsList;
83
import org.cyclops.integrateddynamics.core.ingredient.ExtendedIngredientsSingle;
84
import org.slf4j.Logger;
85

86
import java.util.*;
87
import java.util.stream.Collectors;
88

89
/**
90
 * Collection of available operators.
91
 *
92
 * @author rubensworks
93
 */
94
public final class Operators {
×
95

96
    private static final Logger LOGGER = LogUtils.getLogger();
2✔
97
    public static final IOperatorRegistry REGISTRY = constructRegistry();
2✔
98

99
    private static IOperatorRegistry constructRegistry() {
100
        // This also allows this registry to be used outside of a minecraft environment.
101
        if(IModHelpers.get().getMinecraftHelpers().isModdedEnvironment()) {
4!
102
            return IntegratedDynamics._instance.getRegistryManager().getRegistry(IOperatorRegistry.class);
6✔
103
        } else {
104
            return OperatorRegistry.getInstance();
×
105
        }
106
    }
107

108
    public static void load() {}
1✔
109

110
    /**
111
     * ----------------------------------- LOGICAL OPERATORS -----------------------------------
112
     */
113

114
    /**
115
     * Short-circuit logical AND operator with two input booleans and one output boolean.
116
     */
117
    public static final IOperator LOGICAL_AND = REGISTRY.register(OperatorBuilders.LOGICAL_2.symbol("&&").operatorInteract("and")
9✔
118
            .function(variables -> {
1✔
119
                ValueTypeBoolean.ValueBoolean a = variables.getValue(0, ValueTypes.BOOLEAN);
6✔
120
                if (!a.getRawValue()) {
3✔
121
                    return ValueTypeBoolean.ValueBoolean.of(false);
3✔
122
                } else {
123
                    return variables.getValue(1, ValueTypes.BOOLEAN);
5✔
124
                }
125
            }).build());
1✔
126

127
    /**
128
     * Short-circuit logical AND operator with two input booleans and one output boolean.
129
     */
130
    public static final IOperator LOGICAL_OR = REGISTRY.register(OperatorBuilders.LOGICAL_2.symbol("||").operatorInteract("or")
9✔
131
            .function(variables -> {
1✔
132
                ValueTypeBoolean.ValueBoolean a = variables.getValue(0, ValueTypes.BOOLEAN);
6✔
133
                if (a.getRawValue()) {
3✔
134
                    return ValueTypeBoolean.ValueBoolean.of(true);
3✔
135
                } else {
136
                    return variables.getValue(1, ValueTypes.BOOLEAN);
5✔
137
                }
138
            }).build());
1✔
139

140
    /**
141
     * Logical NOT operator with one input booleans and one output boolean.
142
     */
143
    public static final IOperator LOGICAL_NOT = REGISTRY.register(OperatorBuilders.LOGICAL_1_PREFIX.symbol("!").operatorInteract("not")
9✔
144
            .function(variables -> {
1✔
145
                        ValueTypeBoolean.ValueBoolean valueBoolean = variables.getValue(0, ValueTypes.BOOLEAN);
6✔
146
                        return ValueTypeBoolean.ValueBoolean.of(!valueBoolean.getRawValue());
8✔
147
                    }
148
            ).build());
1✔
149

150
    /**
151
     * Short-circuit logical NAND operator with two input booleans and one output boolean.
152
     */
153
    public static final IOperator LOGICAL_NAND = REGISTRY.register(
13✔
154
            new CompositionalOperator.AppliedOperatorBuilder(LOGICAL_NOT).apply(LOGICAL_AND).build(
7✔
155
                    "!&&", "nand", "nand", IConfigRenderPattern.INFIX, "logical"));
156

157
    /**
158
     * Short-circuit logical NAND operator with two input booleans and one output boolean.
159
     */
160
    public static final IOperator LOGICAL_NOR = REGISTRY.register(
13✔
161
            new CompositionalOperator.AppliedOperatorBuilder(LOGICAL_NOT).apply(LOGICAL_OR).build(
7✔
162
                    "!||", "nor", "nor", IConfigRenderPattern.INFIX, "logical"));
163

164
    /**
165
     * ----------------------------------- ARITHMETIC OPERATORS -----------------------------------
166
     */
167

168
    /**
169
     * Arithmetic ADD operator with two input numbers and one output number.
170
     */
171
    public static final IOperator ARITHMETIC_ADDITION = REGISTRY.register(OperatorBuilders.ARITHMETIC_2.symbol("+").operatorName("addition").interactName("add")
11✔
172
            .function(
1✔
173
                variables -> ValueTypes.CATEGORY_NUMBER.add(variables.getVariables()[0], variables.getVariables()[1])
11✔
174
            ).build());
1✔
175

176
    /**
177
     * Arithmetic MINUS operator with two input numbers and one output number.
178
     */
179
    public static final IOperator ARITHMETIC_SUBTRACTION = REGISTRY.register(OperatorBuilders.ARITHMETIC_2.symbol("-").operatorName("subtraction").interactName("subtract")
11✔
180
            .function(
1✔
181
                variables -> ValueTypes.CATEGORY_NUMBER.subtract(variables.getVariables()[0], variables.getVariables()[1])
11✔
182
            ).build());
1✔
183

184
    /**
185
     * Arithmetic MULTIPLY operator with two input numbers and one output number.
186
     */
187
    public static final IOperator ARITHMETIC_MULTIPLICATION = REGISTRY.register(OperatorBuilders.ARITHMETIC_2.symbol("*").operatorName("multiplication").interactName("multiply")
11✔
188
            .function(
1✔
189
                variables -> ValueTypes.CATEGORY_NUMBER.multiply(variables.getVariables()[0], variables.getVariables()[1])
11✔
190
            ).build());
1✔
191

192
    /**
193
     * Arithmetic DIVIDE operator with two input numbers and one output number.
194
     */
195
    public static final IOperator ARITHMETIC_DIVISION = REGISTRY.register(OperatorBuilders.ARITHMETIC_2.symbol("/").operatorName("division").interactName("divide")
11✔
196
            .function(
1✔
197
                variables -> ValueTypes.CATEGORY_NUMBER.divide(variables.getVariables()[0], variables.getVariables()[1])
11✔
198
            ).build());
1✔
199

200
    /**
201
     * Arithmetic MAX operator with two input numbers and one output number.
202
     */
203
    public static final IOperator ARITHMETIC_MAXIMUM = REGISTRY.register(OperatorBuilders.ARITHMETIC_2_PREFIX.symbol("max").operatorName("maximum").interactName("max")
11✔
204
            .function(
1✔
205
                variables -> ValueTypes.CATEGORY_NUMBER.max(variables.getVariables()[0], variables.getVariables()[1])
11✔
206
            ).build());
1✔
207

208
    /**
209
     * Arithmetic MIN operator with two input numbers and one output number.
210
     */
211
    public static final IOperator ARITHMETIC_MINIMUM = REGISTRY.register(OperatorBuilders.ARITHMETIC_2_PREFIX.symbol("min").operatorName("minimum").interactName("min")
11✔
212
            .function(
1✔
213
                variables -> ValueTypes.CATEGORY_NUMBER.min(variables.getVariables()[0], variables.getVariables()[1])
11✔
214
            ).build());
1✔
215

216
    /**
217
     * Arithmetic INCREMENT operator with one input numbers and one output number.
218
     */
219
    public static final IOperator ARITHMETIC_INCREMENT = REGISTRY.register(OperatorBuilders.ARITHMETIC_1_SUFFIX.symbol("++").operatorInteract("increment")
9✔
220
            .function(
1✔
221
                variables -> ValueTypes.CATEGORY_NUMBER.increment(variables.getVariables()[0])
7✔
222
            ).build());
1✔
223

224
    /**
225
     * Arithmetic DECREMENT operator with one input numbers and one output number.
226
     */
227
    public static final IOperator ARITHMETIC_DECREMENT = REGISTRY.register(OperatorBuilders.ARITHMETIC_1_SUFFIX.symbol("--").operatorInteract("decrement")
9✔
228
            .function(
1✔
229
                variables -> ValueTypes.CATEGORY_NUMBER.decrement(variables.getVariables()[0])
7✔
230
            ).build());
1✔
231

232
    /**
233
     * Arithmetic MODULO operator with two input numbers and one output number.
234
     */
235
    public static final IOperator ARITHMETIC_MODULUS = REGISTRY.register(OperatorBuilders.ARITHMETIC_2.symbol("%").operatorInteract("modulus")
9✔
236
            .function(
1✔
237
                variables -> ValueTypes.CATEGORY_NUMBER.modulus(variables.getVariables()[0], variables.getVariables()[1])
11✔
238
            ).build());
1✔
239

240
    /**
241
     * ----------------------------------- INTEGER OPERATORS -----------------------------------
242
     */
243

244
     private static final ValueTypeInteger.ValueInteger ZERO = ValueTypeInteger.ValueInteger.of(0);
3✔
245

246
    /**
247
     * ----------------------------------- DOUBLE OPERATORS -----------------------------------
248
     */
249

250
    /**
251
     * Integer SQRT operator with two input numbers and one output number.
252
     */
253
    public static final IOperator DOUBLE_SQRT = REGISTRY.register(OperatorBuilders.DOUBLE_1_PREFIX.symbolOperatorInteract("sqrt")
7✔
254
            .function(variables -> {
1✔
255
                ValueTypeDouble.ValueDouble a = variables.getValue(0, ValueTypes.DOUBLE);
6✔
256
                return ValueTypeDouble.ValueDouble.of(Math.sqrt(a.getRawValue()));
5✔
257
            }).build());
1✔
258

259
    /**
260
     * Integer POW operator with two input numbers and one output number.
261
     */
262
    public static final IOperator DOUBLE_POW = REGISTRY.register(OperatorBuilders.DOUBLE_2.symbolOperatorInteract("pow")
7✔
263
            .function(variables -> {
1✔
264
                ValueTypeDouble.ValueDouble a = variables.getValue(0, ValueTypes.DOUBLE);
6✔
265
                ValueTypeDouble.ValueDouble b = variables.getValue(1, ValueTypes.DOUBLE);
6✔
266
                return ValueTypeDouble.ValueDouble.of(Math.pow(a.getRawValue(), b.getRawValue()));
7✔
267
            }).build());
1✔
268

269
    /**
270
     * ----------------------------------- RELATIONAL OPERATORS -----------------------------------
271
     */
272

273
    /**
274
     * Relational == operator with two inputs of any type (but equal) and one output boolean.
275
     */
276
    public static final IOperator RELATIONAL_EQUALS = REGISTRY.register(OperatorBuilders.RELATIONAL
6✔
277
            .inputTypes(2, ValueTypes.CATEGORY_ANY).renderPattern(IConfigRenderPattern.INFIX)
4✔
278
            .symbol("==").operatorInteract("equals")
4✔
279
            .function(
2✔
280
                variables -> ValueTypeBoolean.ValueBoolean.of(variables.getValue(0).equals(variables.getValue(1)))
9✔
281
            )
282
            .typeValidator((operator, input) -> {
1✔
283
                // Input size checking
284
                int requiredInputLength = operator.getRequiredInputLength();
3✔
285
                if(input.length != requiredInputLength) {
4✔
286
                    return Component.translatable(L10NValues.OPERATOR_ERROR_WRONGINPUTLENGTH,
8✔
287
                            operator.getOperatorName(), input.length, requiredInputLength);
13✔
288
                }
289
                // Input types checking
290
                IValueType temporarySecondInputType = null;
2✔
291
                for(int i = 0; i < requiredInputLength; i++) {
7✔
292
                    IValueType inputType = input[i];
4✔
293
                    if (inputType instanceof IValueTypeNumber) {
3✔
294
                        inputType = ValueTypes.CATEGORY_NUMBER;
2✔
295
                    }
296
                    if(inputType == null) {
2!
297
                        return Component.translatable(L10NValues.OPERATOR_ERROR_NULLTYPE, operator.getOperatorName(), Integer.toString(i));
×
298
                    }
299
                    if(i == 0) {
2✔
300
                        temporarySecondInputType = inputType;
3✔
301
                    } else if(i == 1) {
3!
302
                        if(!ValueHelpers.correspondsTo(temporarySecondInputType, inputType)) {
4✔
303
                            return Component.translatable(L10NValues.OPERATOR_ERROR_WRONGTYPE,
8✔
304
                                    operator.getOperatorName(), Component.translatable(inputType.getTranslationKey()),
11✔
305
                                    Integer.toString(i), Component.translatable(temporarySecondInputType.getTranslationKey()));
8✔
306
                        }
307
                    }
308
                }
309
                return null;
2✔
310
            })
311
            .build());
1✔
312

313
    /**
314
     * Relational &gt; operator with two input integers and one output boolean.
315
     */
316
    public static final IOperator RELATIONAL_GT = REGISTRY.register(OperatorBuilders.RELATIONAL_2
6✔
317
            .inputTypes(2, ValueTypes.CATEGORY_NUMBER).symbol(">").operatorName("gt").interactName("greaterThan")
8✔
318
            .function(
1✔
319
                variables -> ValueTypeBoolean.ValueBoolean.of(ValueTypes.CATEGORY_NUMBER.greaterThan(variables.getVariables()[0], variables.getVariables()[1]))
12✔
320
            ).build());
1✔
321

322
    /**
323
     * Relational &gt; operator with two input integers and one output boolean.
324
     */
325
    public static final IOperator RELATIONAL_LT = REGISTRY.register(OperatorBuilders.RELATIONAL_2
6✔
326
            .inputTypes(2, ValueTypes.CATEGORY_NUMBER).symbol("<").operatorName("lt").interactName("lessThan")
8✔
327
            .function(
1✔
328
                variables -> ValueTypeBoolean.ValueBoolean.of(ValueTypes.CATEGORY_NUMBER.lessThan(variables.getVariables()[0], variables.getVariables()[1]))
12✔
329
            ).build());
1✔
330

331
    /**
332
     * Relational != operator with two inputs of any type (but equal) and one output boolean.
333
     */
334
    public static final IOperator RELATIONAL_NOTEQUALS = REGISTRY.register(
13✔
335
            new CompositionalOperator.AppliedOperatorBuilder(LOGICAL_NOT).apply(RELATIONAL_EQUALS).build(
7✔
336
                    "!=", "notequals", "notEquals", IConfigRenderPattern.INFIX, "relational"));
337

338
    /**
339
     * Relational &gt;= operator with two inputs of any type (but equal) and one output boolean.
340
     */
341
    public static final IOperator RELATIONAL_GE = REGISTRY.register(
17✔
342
            new CompositionalOperator.AppliedOperatorBuilder(LOGICAL_OR).apply(RELATIONAL_EQUALS, RELATIONAL_GT).build(
7✔
343
                    ">=", "ge", "greaterThanOrEquals", IConfigRenderPattern.INFIX, "relational"));
344

345
    /**
346
     * Relational &lt;= operator with two inputs of any type (but equal) and one output boolean.
347
     */
348
    public static final IOperator RELATIONAL_LE = REGISTRY.register(
17✔
349
            new CompositionalOperator.AppliedOperatorBuilder(LOGICAL_OR).apply(RELATIONAL_EQUALS, RELATIONAL_LT).build(
7✔
350
                    "<=", "le", "lessThanOrEquals", IConfigRenderPattern.INFIX, "relational"));
351

352
    /**
353
     * ----------------------------------- BINARY OPERATORS -----------------------------------
354
     */
355

356
    /**
357
     * Binary AND operator with two input integers and one output integers.
358
     */
359
    public static final IOperator BINARY_AND = REGISTRY.register(OperatorBuilders.BINARY_2.symbol("&").operatorName("and").interactName("binaryAnd")
11✔
360
            .function(variables -> {
1✔
361
                ValueTypeInteger.ValueInteger a = variables.getValue(0, ValueTypes.INTEGER);
6✔
362
                ValueTypeInteger.ValueInteger b = variables.getValue(1, ValueTypes.INTEGER);
6✔
363
                return ValueTypeInteger.ValueInteger.of(a.getRawValue() & b.getRawValue());
7✔
364
            }).build());
1✔
365

366
    /**
367
     * Binary OR operator with two input integers and one output integers.
368
     */
369
    public static final IOperator BINARY_OR = REGISTRY.register(OperatorBuilders.BINARY_2.symbol("|").operatorName("or").interactName("binaryOr")
11✔
370
            .function(variables -> {
1✔
371
                ValueTypeInteger.ValueInteger a = variables.getValue(0, ValueTypes.INTEGER);
6✔
372
                ValueTypeInteger.ValueInteger b = variables.getValue(1, ValueTypes.INTEGER);
6✔
373
                return ValueTypeInteger.ValueInteger.of(a.getRawValue() | b.getRawValue());
7✔
374
            }).build());
1✔
375

376
    /**
377
     * Binary XOR operator with two input integers and one output integers.
378
     */
379
    public static final IOperator BINARY_XOR = REGISTRY.register(OperatorBuilders.BINARY_2.symbol("^").operatorInteract("xor")
9✔
380
            .function(variables -> {
1✔
381
                ValueTypeInteger.ValueInteger a = variables.getValue(0, ValueTypes.INTEGER);
6✔
382
                ValueTypeInteger.ValueInteger b = variables.getValue(1, ValueTypes.INTEGER);
6✔
383
                return ValueTypeInteger.ValueInteger.of(a.getRawValue() ^ b.getRawValue());
7✔
384
            }).build());
1✔
385

386
    /**
387
     * Binary COMPLEMENT operator with one input integers and one output integers.
388
     */
389
    public static final IOperator BINARY_COMPLEMENT = REGISTRY.register(OperatorBuilders.BINARY_1_PREFIX.symbol("~").operatorInteract("complement")
9✔
390
            .function(variables -> {
1✔
391
                ValueTypeInteger.ValueInteger a = variables.getValue(0, ValueTypes.INTEGER);
6✔
392
                return ValueTypeInteger.ValueInteger.of(~a.getRawValue());
6✔
393
            }).build());
1✔
394

395
    /**
396
     * Binary &lt;&lt; operator with two input integers and one output integers.
397
     */
398
    public static final IOperator BINARY_LSHIFT = REGISTRY.register(OperatorBuilders.BINARY_2.symbol("<<").operatorName("lshift").interactName("leftShift")
11✔
399
            .function(variables -> {
1✔
400
                ValueTypeInteger.ValueInteger a = variables.getValue(0, ValueTypes.INTEGER);
6✔
401
                ValueTypeInteger.ValueInteger b = variables.getValue(1, ValueTypes.INTEGER);
6✔
402
                return ValueTypeInteger.ValueInteger.of(a.getRawValue() << b.getRawValue());
7✔
403
            }).build());
1✔
404

405
    /**
406
     * Binary &gt;&gt; operator with two input integers and one output integers.
407
     */
408
    public static final IOperator BINARY_RSHIFT = REGISTRY.register(OperatorBuilders.BINARY_2.symbol(">>").operatorName("rshift").interactName("rightShift")
11✔
409
            .function(variables -> {
1✔
410
                ValueTypeInteger.ValueInteger a = variables.getValue(0, ValueTypes.INTEGER);
6✔
411
                ValueTypeInteger.ValueInteger b = variables.getValue(1, ValueTypes.INTEGER);
6✔
412
                return ValueTypeInteger.ValueInteger.of(a.getRawValue() >> b.getRawValue());
7✔
413
            }).build());
1✔
414

415
    /**
416
     * Binary &gt;&gt;&gt; operator with two input integers and one output integers.
417
     */
418
    public static final IOperator BINARY_RZSHIFT = REGISTRY.register(OperatorBuilders.BINARY_2.symbol(">>>").operatorName("rzshift").interactName("unsignedRightShift")
11✔
419
            .function(variables -> {
1✔
420
                ValueTypeInteger.ValueInteger a = variables.getValue(0, ValueTypes.INTEGER);
6✔
421
                ValueTypeInteger.ValueInteger b = variables.getValue(1, ValueTypes.INTEGER);
6✔
422
                return ValueTypeInteger.ValueInteger.of(a.getRawValue() >>> b.getRawValue());
7✔
423
            }).build());
1✔
424

425
    /**
426
     * ----------------------------------- STRING OPERATORS -----------------------------------
427
     */
428

429
    /**
430
     * String length operator with one input string and one output integer.
431
     */
432
    public static final IOperator STRING_LENGTH = REGISTRY.register(OperatorBuilders.STRING_1_PREFIX.symbol("len").operatorInteract("length")
9✔
433
            .output(ValueTypes.INTEGER).function(variables -> {
3✔
434
                ValueTypeString.ValueString a = variables.getValue(0, ValueTypes.STRING);
6✔
435
                return ValueTypeInteger.ValueInteger.of(a.getRawValue().length());
5✔
436
            }).build());
1✔
437

438
    /**
439
     * String concat operator with two input strings and one output string.
440
     */
441
    public static final IOperator STRING_CONCAT = REGISTRY.register(OperatorBuilders.STRING_2.symbol("+").operatorInteract("concat")
9✔
442
            .function(variables -> {
1✔
443
                ValueTypeString.ValueString a = variables.getValue(0, ValueTypes.STRING);
6✔
444
                ValueTypeString.ValueString b = variables.getValue(1, ValueTypes.STRING);
6✔
445
                return ValueTypeString.ValueString.of(a.getRawValue() + b.getRawValue());
7✔
446
            }).build());
1✔
447

448
    /**
449
     * String contains operator which checks whether a given (literal) string is contained in the given string.
450
     */
451
    public static final IOperator STRING_CONTAINS = REGISTRY.register(OperatorBuilders.STRING_2.symbolOperatorInteract("contains")
7✔
452
        .output(ValueTypes.BOOLEAN).function(variables -> {
3✔
453
                ValueTypeString.ValueString search = variables.getValue(0, ValueTypes.STRING);
6✔
454
                ValueTypeString.ValueString str = variables.getValue(1, ValueTypes.STRING);
6✔
455
                return ValueTypeBoolean.ValueBoolean.of(str.getRawValue().contains(search.getRawValue()));
7✔
456
            }).build());
1✔
457

458
    /**
459
     * String match operator which checks whether a given regular expression is contained within a string.
460
     */
461
    public static final IOperator STRING_CONTAINS_REGEX = REGISTRY.register(OperatorBuilders.STRING_2_LONG.symbolOperator("contains_regex").interactName("containsRegex")
9✔
462
        .output(ValueTypes.BOOLEAN).function(variables -> {
3✔
463
                ValueTypeString.ValueString pattern = variables.getValue(0, ValueTypes.STRING);
6✔
464
                ValueTypeString.ValueString str = variables.getValue(1, ValueTypes.STRING);
6✔
465
                try {
466
                    Matcher m = Pattern.compile(pattern.getRawValue()).matcher(str.getRawValue());
7✔
467
                    return ValueTypeBoolean.ValueBoolean.of(m.find());
4✔
468
                } catch (PatternSyntaxException e) {
1✔
469
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_REGEX_INVALID,
11✔
470
                            pattern.getRawValue()));
2✔
471
                }
472
            }).build());
1✔
473

474
    /**
475
     * String match operator which checks whether a given regular expression matches a string.
476
     */
477
    public static final IOperator STRING_MATCHES_REGEX = REGISTRY.register(OperatorBuilders.STRING_2_LONG.symbolOperator("matches_regex").interactName("matchesRegex")
9✔
478
            .output(ValueTypes.BOOLEAN).function(variables -> {
3✔
479
                ValueTypeString.ValueString pattern = variables.getValue(0, ValueTypes.STRING);
6✔
480
                ValueTypeString.ValueString str = variables.getValue(1, ValueTypes.STRING);
6✔
481
                try {
482
                    Matcher m = Pattern.compile(pattern.getRawValue()).matcher(str.getRawValue());
7✔
483
                    return ValueTypeBoolean.ValueBoolean.of(m.matches());
4✔
484
                } catch (PatternSyntaxException e) {
1✔
485
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_REGEX_INVALID,
11✔
486
                            pattern.getRawValue()));
2✔
487
                }
488
            }).build());
1✔
489

490
    /**
491
     * String operator which returns the integral index of the first position where the search string appears in the given string.
492
     */
493
    public static final IOperator STRING_INDEX_OF = REGISTRY.register(OperatorBuilders.STRING_2_LONG.symbolOperator("index_of").interactName("indexOf")
9✔
494
        .output(ValueTypes.INTEGER).function(variables -> {
3✔
495
                ValueTypeString.ValueString search = variables.getValue(0, ValueTypes.STRING);
6✔
496
                ValueTypeString.ValueString str = variables.getValue(1, ValueTypes.STRING);
6✔
497
                return ValueTypeInteger.ValueInteger.of(str.getRawValue().indexOf(search.getRawValue()));
7✔
498
            }).build());
1✔
499

500
    /**
501
     * String operator which returns the integral index where the a substring matching the regular expression appears in the given string.
502
     */
503
    public static final IOperator STRING_INDEX_OF_REGEX = REGISTRY.register(OperatorBuilders.STRING_2_LONG.symbolOperator("index_of_regex").interactName("indexOfRegex")
9✔
504
        .output(ValueTypes.INTEGER).function(variables -> {
3✔
505
                ValueTypeString.ValueString pattern = variables.getValue(0, ValueTypes.STRING);
6✔
506
                ValueTypeString.ValueString str = variables.getValue(1, ValueTypes.STRING);
6✔
507
                try {
508
                    Matcher m = Pattern.compile(pattern.getRawValue()).matcher(str.getRawValue());
7✔
509
                    if (m.find()) {
3✔
510
                        return ValueTypeInteger.ValueInteger.of(m.start());
4✔
511
                    } else {
512
                        return ValueTypeInteger.ValueInteger.of(-1);
3✔
513
                    }
514
                } catch (PatternSyntaxException e) {
1✔
515
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_REGEX_INVALID,
11✔
516
                            pattern.getRawValue()));
2✔
517
                }
518
            }).build());
1✔
519

520
    /**
521
     * String match operator which checks whether a given string matches the beginning of the given string.
522
     */
523
    public static final IOperator STRING_STARTS_WITH = REGISTRY.register(OperatorBuilders.STRING_2.symbolOperator("starts_with").interactName("startsWith")
9✔
524
        .output(ValueTypes.BOOLEAN).function(variables -> {
3✔
525
                ValueTypeString.ValueString search = variables.getValue(0, ValueTypes.STRING);
6✔
526
                ValueTypeString.ValueString str = variables.getValue(1, ValueTypes.STRING);
6✔
527
                return ValueTypeBoolean.ValueBoolean.of(str.getRawValue().startsWith(search.getRawValue()));
7✔
528
            }).build());
1✔
529

530
    /**
531
     * String match operator which checks whether a given string matches the end of the given string.
532
     */
533
    public static final IOperator STRING_ENDS_WITH = REGISTRY.register(OperatorBuilders.STRING_2.symbolOperator("ends_with").interactName("endsWith")
9✔
534
        .output(ValueTypes.BOOLEAN).function(variables -> {
3✔
535
                ValueTypeString.ValueString search = variables.getValue(0, ValueTypes.STRING);
6✔
536
                ValueTypeString.ValueString str = variables.getValue(1, ValueTypes.STRING);
6✔
537
                return ValueTypeBoolean.ValueBoolean.of(str.getRawValue().endsWith(search.getRawValue()));
7✔
538
            }).build());
1✔
539

540
    /**
541
     * String operator which splits on the given (literal) delimiter the input string .
542
     */
543
    public static final IOperator STRING_SPLIT_ON = REGISTRY.register(OperatorBuilders.STRING_2.symbolOperator("split_on").interactName("splitOn")
9✔
544
        .output(ValueTypes.LIST).function(variables -> {
3✔
545
                ValueTypeString.ValueString search = variables.getValue(0, ValueTypes.STRING);
6✔
546
                ValueTypeString.ValueString str = variables.getValue(1, ValueTypes.STRING);
6✔
547
                List<String> pieces = Arrays.asList(str.getRawValue().split(java.util.regex.Pattern.quote(search.getRawValue())));
8✔
548
                List<ValueTypeString.ValueString> values = Lists.newArrayList();
2✔
549
                for (String piece : pieces) {
10✔
550
                    values.add(ValueTypeString.ValueString.of(piece));
5✔
551
                }
1✔
552
                return ValueTypeList.ValueList.ofList(ValueTypes.STRING, values);
4✔
553
            }).build());
1✔
554

555
    /**
556
     * String operator which splits on the given (regular expression) delimiter the input string.
557
     */
558
    public static final IOperator STRING_SPLIT_ON_REGEX = REGISTRY.register(OperatorBuilders.STRING_2_LONG.symbolOperator("split_on_regex").interactName("splitOnRegex")
9✔
559
        .output(ValueTypes.LIST).function(variables -> {
3✔
560
                ValueTypeString.ValueString pattern = variables.getValue(0, ValueTypes.STRING);
6✔
561
                ValueTypeString.ValueString str = variables.getValue(1, ValueTypes.STRING);
6✔
562
                try {
563
                    List<String> pieces = Arrays.asList(Pattern.compile(pattern.getRawValue()).split(str.getRawValue()));
8✔
564
                    List<ValueTypeString.ValueString> values = Lists.newArrayList();
2✔
565
                    for (String piece : pieces) {
10✔
566
                        values.add(ValueTypeString.ValueString.of(piece));
5✔
567
                    }
1✔
568
                    return ValueTypeList.ValueList.ofList(ValueTypes.STRING, values);
4✔
569
                } catch (PatternSyntaxException e) {
1✔
570
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_REGEX_INVALID,
11✔
571
                            pattern.getRawValue()));
2✔
572
                }
573
            }).build());
1✔
574

575
    /**
576
     * String operator which takes the substring of the given string between the two integer indices.
577
     */
578
    public static final IOperator STRING_SUBSTRING = REGISTRY.register(OperatorBuilders.STRING.symbolOperatorInteract("substring")
7✔
579
        .renderPattern(IConfigRenderPattern.PREFIX_3_LONG)
15✔
580
        .inputTypes(ValueTypes.INTEGER, ValueTypes.INTEGER, ValueTypes.STRING)
2✔
581
        .output(ValueTypes.STRING)
2✔
582
        .function(variables -> {
1✔
583
            ValueTypeInteger.ValueInteger from = variables.getValue(0, ValueTypes.INTEGER);
6✔
584
            ValueTypeInteger.ValueInteger to = variables.getValue(1, ValueTypes.INTEGER);
6✔
585
            ValueTypeString.ValueString str = variables.getValue(2, ValueTypes.STRING);
6✔
586
            if (from.getRawValue() > to.getRawValue()) {
5✔
587
                throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_SUBSTRING_TOGREATERTHANFROM));
6✔
588
            }
589
            if (from.getRawValue() < 0 || to.getRawValue() < 0) {
6!
590
                throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_SUBSTRING_INDEXNEGATIVE));
6✔
591
            }
592
            int stringLength = str.getRawValue().length();
4✔
593
            if (from.getRawValue() > stringLength || to.getRawValue() > stringLength) {
8!
594
                throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_SUBSTRING_LONGERTHANSTRING));
6✔
595
            }
596
            return ValueTypeString.ValueString.of(str.getRawValue().substring(from.getRawValue(), to.getRawValue()));
9✔
597
        }).build());
1✔
598

599

600
    /**
601
     * String operator which matches against a regex and takes the group at the index of the integer given (including zero), in the input string. It is invalid for the pattern to not match.
602
     */
603
    public static final IOperator STRING_REGEX_GROUP = REGISTRY.register(OperatorBuilders.STRING.symbolOperator("regex_group").interactName("regexGroup")
9✔
604
        .renderPattern(IConfigRenderPattern.PREFIX_3_LONG)
15✔
605
        .inputTypes(ValueTypes.STRING, ValueTypes.INTEGER, ValueTypes.STRING)
2✔
606
        .output(ValueTypes.STRING)
2✔
607
        .function(variables -> {
1✔
608
            ValueTypeString.ValueString pattern = variables.getValue(0, ValueTypes.STRING);
6✔
609
            ValueTypeInteger.ValueInteger group = variables.getValue(1, ValueTypes.INTEGER);
6✔
610
            ValueTypeString.ValueString str = variables.getValue(2, ValueTypes.STRING);
6✔
611
            if (group.getRawValue() < 0) {
3✔
612
                throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_GROUP_INDEXNEGATIVE));
6✔
613
            }
614
            try {
615
                Matcher m = Pattern.compile(pattern.getRawValue()).matcher(str.getRawValue());
7✔
616
                if (m.find()) {
3!
617
                    String result = m.group(group.getRawValue());
5✔
618
                    return ValueTypeString.ValueString.of(result == null ? "" : result);
5!
619
                } else {
620
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_GROUP_NOMATCH,
×
621
                            str.getRawValue(), pattern.getRawValue()));
×
622
                }
623
            } catch (PatternSyntaxException e) {
1✔
624
                throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_REGEX_INVALID,
11✔
625
                        pattern.getRawValue()));
2✔
626
            } catch (IndexOutOfBoundsException e) {
1✔
627
                throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_GROUP_NOMATCHGROUP,
11✔
628
                        str.getRawValue(), pattern.getRawValue(), group.getRawValue()));
13✔
629
            }
630
        }).build()
1✔
631
    );
632

633
    /**
634
     * String operator which matches against a regex the input string and returns a list containing all groups matched (including zero). An empty list is returned if the regex does not match.
635
     */
636
    public static final IOperator STRING_REGEX_GROUPS = REGISTRY.register(OperatorBuilders.STRING_2_LONG.symbolOperator("regex_groups").interactName("regexGroups")
9✔
637
        .output(ValueTypes.LIST)
2✔
638
        .function(variables -> {
1✔
639
            ValueTypeString.ValueString pattern = variables.getValue(0, ValueTypes.STRING);
6✔
640
            ValueTypeString.ValueString str = variables.getValue(1, ValueTypes.STRING);
6✔
641
            try {
642
                Matcher m = Pattern.compile(pattern.getRawValue()).matcher(str.getRawValue());
7✔
643
                if (m.find()) {
3✔
644
                    List<ValueTypeString.ValueString> values = Lists.newArrayList();
2✔
645
                    for (int i = 0; i <= m.groupCount(); i++) {
8✔
646
                        String result = m.group(i);
4✔
647
                        values.add(ValueTypeString.ValueString.of(result == null ? "" : result));
7!
648
                    }
649
                    return ValueTypeList.ValueList.ofList(ValueTypes.STRING, values);
4✔
650
                } else {
651
                    return ValueTypeList.ValueList.ofList(ValueTypes.STRING, Collections.<ValueTypeString.ValueString>emptyList());
4✔
652
                }
653
            } catch (PatternSyntaxException e) {
1✔
654
                throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_REGEX_INVALID,
11✔
655
                        pattern.getRawValue()));
2✔
656
            }
657
        }).build()
1✔
658
    );
659

660
    /**
661
     * String operator which finds all matches of the regular expression in the given string and returns the given group for each match.
662
     */
663
    public static final IOperator STRING_REGEX_SCAN = REGISTRY.register(OperatorBuilders.STRING.symbolOperator("regex_scan").interactName("regexScan")
9✔
664
        .renderPattern(IConfigRenderPattern.PREFIX_3_LONG)
15✔
665
        .inputTypes(ValueTypes.STRING, ValueTypes.INTEGER, ValueTypes.STRING)
2✔
666
        .output(ValueTypes.LIST)
2✔
667
        .function(variables -> {
1✔
668
            ValueTypeString.ValueString pattern = variables.getValue(0, ValueTypes.STRING);
6✔
669
            ValueTypeInteger.ValueInteger group = variables.getValue(1, ValueTypes.INTEGER);
6✔
670
            ValueTypeString.ValueString str = variables.getValue(2, ValueTypes.STRING);
6✔
671
            if (group.getRawValue() < 0) {
3!
672
                throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_REGEXSCAN_INDEXNEGATIVE));
×
673
            }
674
            try {
675
                Matcher m = Pattern.compile(pattern.getRawValue()).matcher(str.getRawValue());
7✔
676
                List<ValueTypeString.ValueString> values = Lists.newArrayList();
2✔
677
                while (m.find()) {
3✔
678
                    String match = m.group(group.getRawValue());
5✔
679
                    if (match != null) {
2✔
680
                        values.add(ValueTypeString.ValueString.of(match));
5✔
681
                    }
682
                }
1✔
683
                return ValueTypeList.ValueList.ofList(ValueTypes.STRING, values);
4✔
684
            } catch (PatternSyntaxException e) {
1✔
685
                throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_REGEX_INVALID,
11✔
686
                        pattern.getRawValue()));
2✔
687
            } catch (IndexOutOfBoundsException e) {
×
688
                throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_REGEXSCAN_NOMATCHGROUP,
×
689
                        str.getRawValue(), pattern.getRawValue(), group.getRawValue()));
×
690
            }
691
        }).build()
1✔
692
    );
693

694
    /**
695
     * String operator which, finds all the matches of the (literal) search and replaces them with the given replacement, in the input string.
696
     */
697
    public static final IOperator STRING_REPLACE = REGISTRY.register(OperatorBuilders.STRING.symbolOperatorInteract("replace")
7✔
698
        .renderPattern(IConfigRenderPattern.PREFIX_3_LONG)
3✔
699
        .inputTypes(3, ValueTypes.STRING)
2✔
700
        .output(ValueTypes.STRING)
2✔
701
        .function(variables -> {
1✔
702
            ValueTypeString.ValueString search = variables.getValue(0, ValueTypes.STRING);
6✔
703
            ValueTypeString.ValueString replacement = variables.getValue(1, ValueTypes.STRING);
6✔
704
            ValueTypeString.ValueString str = variables.getValue(2, ValueTypes.STRING);
6✔
705
            return ValueTypeString.ValueString.of(str.getRawValue().replaceAll(java.util.regex.Pattern.quote(search.getRawValue()), java.util.regex.Matcher.quoteReplacement(replacement.getRawValue())));
11✔
706
        }).build()
1✔
707
    );
708

709
    /**
710
     * String operator which, finds all the matches of the regular expression pattern and replaces them with the given replacement, in the input string.
711
     */
712
    public static final IOperator STRING_REPLACE_REGEX = REGISTRY.register(OperatorBuilders.STRING.symbolOperator("replace_regex").interactName("replaceRegex")
9✔
713
        .renderPattern(IConfigRenderPattern.PREFIX_3_LONG)
3✔
714
        .inputTypes(3, ValueTypes.STRING)
2✔
715
        .output(ValueTypes.STRING)
2✔
716
        .function(variables -> {
1✔
717
            ValueTypeString.ValueString pattern = variables.getValue(0, ValueTypes.STRING);
6✔
718
            ValueTypeString.ValueString replacement = variables.getValue(1, ValueTypes.STRING);
6✔
719
            ValueTypeString.ValueString str = variables.getValue(2, ValueTypes.STRING);
6✔
720
            try {
721
                return ValueTypeString.ValueString.of(Pattern.compile(pattern.getRawValue()).matcher(str.getRawValue()).replaceAll(replacement.getRawValue()));
11✔
722
            } catch (PatternSyntaxException e) {
×
723
                throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_REGEX_INVALID,
×
724
                        pattern.getRawValue()));
×
725
            } catch (IndexOutOfBoundsException e) {
×
726
                throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_REPLACEREGEX_INVALIDGROUP,
×
727
                        replacement.getRawValue(), e.getMessage()));
×
728
            }
729
        }).build()
1✔
730
    );
731

732
    /**
733
     * String operator to join a list using a string delimiter
734
     */
735
    public static final IOperator STRING_JOIN = REGISTRY.register(OperatorBuilders.STRING.symbolOperatorInteract("join")
7✔
736
            .renderPattern(IConfigRenderPattern.PREFIX_2)
11✔
737
            .inputTypes(ValueTypes.STRING, ValueTypes.LIST)
2✔
738
            .output(ValueTypes.STRING)
4✔
739
            .function(new OperatorBase.IFunction() {
4✔
740
                @Override
741
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
742
                    // Prepare values
743
                    ValueTypeString.ValueString delimiter = variables.getValue(0, ValueTypes.STRING);
6✔
744
                    ValueTypeList.ValueList<?, ?> elements = variables.getValue(1, ValueTypes.LIST);
6✔
745
                    if (!ValueHelpers.correspondsTo(elements.getRawValue().getValueType(), ValueTypes.STRING)) {
6✔
746
                        throw new EvaluationException(Component.translatable(
11✔
747
                                L10NValues.VALUETYPE_ERROR_INVALIDLISTVALUETYPE,
748
                                Component.translatable(elements.getRawValue().getValueType().getTranslationKey()),
8✔
749
                                Component.translatable(ValueTypes.STRING.getTranslationKey())));
3✔
750
                    }
751

752
                    // Don't allow joining on an infinite list
753
                    if (elements.getRawValue().isInfinite()) {
4✔
754
                        throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_INFINITELIST_ILLEGAL,
11✔
755
                                STRING_JOIN.getLocalizedNameFull()));
2✔
756
                    }
757

758
                    // Join in O(n), while type-checking each element, as the list may have been of ANY type.
759
                    StringBuilder sb = new StringBuilder();
4✔
760
                    for (IValue value : elements.getRawValue()) {
11✔
761
                        if (value.getType() != ValueTypes.STRING) {
4✔
762
                            throw new EvaluationException(Component.translatable(
11✔
763
                                    L10NValues.VALUETYPE_ERROR_INVALIDLISTVALUETYPE,
764
                                    Component.translatable(value.getType().getTranslationKey()),
7✔
765
                                    Component.translatable(ValueTypes.STRING.getTranslationKey())));
3✔
766
                        }
767
                        if (sb.length() > 0) {
3✔
768
                            sb.append(delimiter.getRawValue());
5✔
769
                        }
770
                        sb.append(((ValueTypeString.ValueString) value).getRawValue());
6✔
771
                    }
1✔
772

773
                    return ValueTypeString.ValueString.of(sb.toString());
4✔
774
                }
775
            }).build()
1✔
776
    );
777

778
    /**
779
     * Get a name value type name.
780
     */
781
    public static final IOperator NAMED_NAME = REGISTRY.register(OperatorBuilders.STRING_2.symbolOperatorInteract("name")
7✔
782
            .inputType(ValueTypes.CATEGORY_NAMED).renderPattern(IConfigRenderPattern.SUFFIX_1_LONG)
4✔
783
            .function(
1✔
784
                variables -> ValueTypeString.ValueString.of(ValueTypes.CATEGORY_NAMED.getName(variables.getVariables()[0]))
8✔
785
            ).build());
1✔
786

787
    /**
788
     * Get a unique name value type name.
789
     */
790
    public static final IOperator UNIQUELYNAMED_UNIQUENAME = REGISTRY.register(OperatorBuilders.STRING_2.symbol("uname").operatorName("unique_name").interactName("uniqueName")
11✔
791
            .inputType(ValueTypes.CATEGORY_UNIQUELY_NAMED).renderPattern(IConfigRenderPattern.SUFFIX_1_LONG)
4✔
792
            .function(
1✔
793
                variables -> ValueTypeString.ValueString.of(ValueTypes.CATEGORY_UNIQUELY_NAMED.getUniqueName(variables.getVariables()[0]))
×
794
            ).build());
1✔
795

796
    /**
797
     * Throw a custom error
798
     */
799
    public static final IOperator STRING_ERROR  = REGISTRY.register(OperatorBuilders.STRING_2.symbol("error").operatorName("string_error").interactName("stringError")
11✔
800
            .inputType(ValueTypes.STRING).renderPattern(IConfigRenderPattern.SUFFIX_1_LONG)
4✔
801
            .function(
1✔
802
                (variables) -> {
803
                    throw new EvaluationException(Component.translatable(variables.getValue(0, ValueTypes.STRING).getRawValue()));
11✔
804
                }
805
            ).build());
1✔
806

807
    /**
808
     * ----------------------------------- NUMBER OPERATORS -----------------------------------
809
     */
810

811
    /**
812
     * Number round operator with one input double and one output integers.
813
     */
814
    public static final IOperator NUMBER_ROUND = REGISTRY.register(OperatorBuilders.NUMBER_1_PREFIX
5✔
815
            .inputType(ValueTypes.CATEGORY_NUMBER).output(ValueTypes.INTEGER).symbol("|| ||").operatorInteract("round")
8✔
816
            .function(
1✔
817
                variables -> ValueTypes.CATEGORY_NUMBER.round(variables.getVariables()[0])
7✔
818
            ).build());
1✔
819

820
    /**
821
     * Number ceil operator with one input double and one output integers.
822
     */
823
    public static final IOperator NUMBER_CEIL = REGISTRY.register(OperatorBuilders.NUMBER_1_PREFIX
5✔
824
            .inputType(ValueTypes.CATEGORY_NUMBER).output(ValueTypes.INTEGER).symbol("⌈ ⌉").operatorInteract("ceil")
8✔
825
            .function(
1✔
826
                variables -> ValueTypes.CATEGORY_NUMBER.ceil(variables.getVariables()[0])
7✔
827
            ).build());
1✔
828

829
    /**
830
     * Number floor operator with one input double and one output integers.
831
     */
832
    public static final IOperator NUMBER_FLOOR = REGISTRY.register(OperatorBuilders.NUMBER_1_PREFIX
5✔
833
            .inputType(ValueTypes.CATEGORY_NUMBER).output(ValueTypes.INTEGER).symbol("⌊ ⌋").operatorInteract("floor")
8✔
834
            .function(
1✔
835
                variables -> ValueTypes.CATEGORY_NUMBER.floor(variables.getVariables()[0])
7✔
836
            ).build());
1✔
837

838
    /**
839
     * Accepts a number, and returns a string roughly representing that number
840
     */
841
    public static final IOperator NUMBER_COMPACT = REGISTRY.register(OperatorBuilders.NUMBER_1_LONG
5✔
842
            .inputType(ValueTypes.CATEGORY_NUMBER).output(ValueTypes.STRING).symbolOperatorInteract("compact")
6✔
843
            .function(
1✔
844
                variables -> ValueTypes.CATEGORY_NUMBER.compact(variables.getVariables()[0])
7✔
845
            ).build());
1✔
846

847
    /**
848
     * ----------------------------------- NULLABLE OPERATORS -----------------------------------
849
     */
850

851
    /**
852
     * Check if something is null
853
     */
854
    public static final IOperator NULLABLE_ISNULL = REGISTRY.register(OperatorBuilders.NULLABLE_1_PREFIX.symbol("o").operatorName("isnull").interactName("isNull")
11✔
855
            .inputType(ValueTypes.CATEGORY_ANY).output(ValueTypes.BOOLEAN).function(variables -> {
5✔
856
                if(ValueHelpers.correspondsTo(variables.getVariables()[0].getType(), ValueTypes.CATEGORY_NULLABLE)) {
8!
857
                    return ValueTypeBoolean.ValueBoolean.of(ValueTypes.CATEGORY_NULLABLE.isNull(variables.getVariables()[0]));
×
858
                }
859
                return ValueTypeBoolean.ValueBoolean.of(false);
3✔
860
            }).build());
1✔
861

862
    /**
863
     * Check if something is not null
864
     */
865
    public static final IOperator NULLABLE_ISNOTNULL = REGISTRY.register(new CompositionalOperator.AppliedOperatorBuilder(LOGICAL_NOT)
13✔
866
            .apply(NULLABLE_ISNULL).build("∅", "isnotnull", "isNotNull", IConfigRenderPattern.PREFIX_1, "general"));
7✔
867

868
    /**
869
     * ----------------------------------- LIST OPERATORS -----------------------------------
870
     */
871

872
    /**
873
     * List operator with one input list and one output integer
874
     */
875
    public static final IOperator LIST_LENGTH = REGISTRY.register(OperatorBuilders.LIST_1_PREFIX.output(ValueTypes.INTEGER).symbol("| |").operatorInteract("length")
11✔
876
            .function(variables -> {
1✔
877
                ValueTypeList.ValueList valueList = variables.getValue(0, ValueTypes.LIST);
6✔
878
                IValueTypeListProxy a = valueList.getRawValue();
3✔
879
                return ValueTypeInteger.ValueInteger.of(a.getLength());
4✔
880
            }).build());
1✔
881

882
    /**
883
     * Check if a list is empty
884
     */
885
    public static final IOperator LIST_EMPTY = REGISTRY.register(OperatorBuilders.LIST_1_PREFIX.output(ValueTypes.BOOLEAN).symbol("∅").operatorName("empty").interactName("isEmpty")
13✔
886
            .function(variables -> {
1✔
887
                ValueTypeList.ValueList valueList = variables.getValue(0, ValueTypes.LIST);
6✔
888
                IValueTypeListProxy a = valueList.getRawValue();
3✔
889
                return ValueTypeBoolean.ValueBoolean.of(a.getLength() == 0);
8✔
890
            }).build());
1✔
891

892
    /**
893
     * Check if a list is not empty
894
     */
895
    public static final IOperator LIST_NOT_EMPTY = REGISTRY.register(
13✔
896
            new CompositionalOperator.AppliedOperatorBuilder(LOGICAL_NOT).apply(LIST_EMPTY).build(
7✔
897
                    "o", "notempty", "isNotEmpty", IConfigRenderPattern.PREFIX_1, "list"));
898

899
    /**
900
     * List operator with one input list and one output integer
901
     */
902
    public static final IOperator LIST_ELEMENT = REGISTRY.register(OperatorBuilders.LIST_1_PREFIX
14✔
903
            .inputTypes(new IValueType[]{ValueTypes.LIST, ValueTypes.INTEGER}).output(ValueTypes.CATEGORY_ANY)
4✔
904
            .renderPattern(IConfigRenderPattern.INFIX).symbolOperatorInteract("get")
4✔
905
            .function(variables -> {
2✔
906
                ValueTypeList.ValueList valueList = variables.getValue(0, ValueTypes.LIST);
6✔
907
                IValueTypeListProxy a = valueList.getRawValue();
3✔
908
                ValueTypeInteger.ValueInteger b = variables.getValue(1, ValueTypes.INTEGER);
6✔
909
                if (b.getRawValue() < a.getLength() && b.getRawValue() >= 0) {
8!
910
                    return a.get(b.getRawValue());
5✔
911
                } else {
912
                    throw new EvaluationException(Component.translatable(
11✔
913
                            L10NValues.OPERATOR_ERROR_INDEXOUTOFBOUNDS, b.getRawValue(), a.getLength()));
9✔
914
                }
915
            }).conditionalOutputTypeDeriver((operator, input) -> {
1✔
916
                try {
917
                    IValueTypeListProxy a = ((ValueTypeList.ValueList) input[0].getValue()).getRawValue();
×
918
                    return a.getValueType();
×
919
                } catch (ClassCastException | EvaluationException e) {
×
920
                    return operator.getOutputType();
×
921
                }
922
            }).build());
1✔
923

924
    /**
925
     * List operator with one input list, one output integer, and one default value
926
     */
927
    public static final IOperator LIST_ELEMENT_DEFAULT = REGISTRY.register(OperatorBuilders.LIST_1_PREFIX
18✔
928
            .inputTypes(new IValueType[]{ValueTypes.LIST, ValueTypes.INTEGER, ValueTypes.CATEGORY_ANY}).output(ValueTypes.CATEGORY_ANY)
4✔
929
            .renderPattern(IConfigRenderPattern.INFIX_2_LONG).symbolOperator("get_or_default").interactName("getOrDefault")
6✔
930
            .function(variables -> {
2✔
931
                ValueTypeList.ValueList valueList = variables.getValue(0, ValueTypes.LIST);
6✔
932
                IValueTypeListProxy a = valueList.getRawValue();
3✔
933
                ValueTypeInteger.ValueInteger b = variables.getValue(1, ValueTypes.INTEGER);
6✔
934
                if (b.getRawValue() < a.getLength() && b.getRawValue() >= 0) {
8✔
935
                    return a.get(b.getRawValue());
5✔
936
                } else {
937
                    if (!ValueHelpers.correspondsTo(a.getValueType(), variables.getVariables()[2].getType())) {
9!
938
                        throw new EvaluationException(Component.translatable(
×
939
                                L10NValues.VALUETYPE_ERROR_INVALIDLISTVALUETYPE,
940
                                Component.translatable(a.getValueType().getTranslationKey()),
×
941
                                Component.translatable(variables.getVariables()[2].getType().getTranslationKey())));
×
942
                    }
943
                    return variables.getValue(2);
4✔
944
                }
945
            }).conditionalOutputTypeDeriver(
1✔
946
                (operator, input) -> input[2].getType()
×
947
            ).build());
1✔
948

949
    /**
950
     * List contains operator that takes a list, a list element to look for and returns a boolean.
951
     */
952
    public static final IOperator LIST_CONTAINS = REGISTRY.register(OperatorBuilders.LIST
14✔
953
            .inputTypes(new IValueType[]{ValueTypes.LIST, ValueTypes.CATEGORY_ANY})
2✔
954
            .renderPattern(IConfigRenderPattern.PREFIX_2_LONG)
2✔
955
            .output(ValueTypes.BOOLEAN).symbolOperatorInteract("contains")
6✔
956
            .function(new OperatorBase.IFunction() {
4✔
957
                @Override
958
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
959
                    ValueTypeList.ValueList valueList = variables.getValue(0, ValueTypes.LIST);
6✔
960
                    IValueTypeListProxy<IValueType<IValue>, IValue> list = valueList.getRawValue();
3✔
961
                    if (list.isInfinite()) {
3!
962
                        throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_INFINITELIST_ILLEGAL,
×
963
                                LIST_CONTAINS.getLocalizedNameFull()));
×
964
                    }
965
                    IValue input = variables.getValue(1);
4✔
966
                    for (IValue value : list) {
10✔
967
                        if (value.equals(input)) {
4✔
968
                            return ValueTypeBoolean.ValueBoolean.of(true);
3✔
969
                        }
970
                    }
1✔
971
                    return ValueTypeBoolean.ValueBoolean.of(false);
3✔
972
                }
973
            }).build());
1✔
974

975
    /**
976
     * List contains operator that takes a list, a predicate that maps a list element to a boolean, a list element and returns a boolean.
977
     */
978
    public static final IOperator LIST_CONTAINS_PREDICATE = REGISTRY.register(OperatorBuilders.LIST
14✔
979
            .inputTypes(new IValueType[]{ValueTypes.LIST, ValueTypes.OPERATOR})
2✔
980
            .renderPattern(IConfigRenderPattern.INFIX)
2✔
981
            .output(ValueTypes.BOOLEAN).symbolOperator("contains_p").interactName("containsPredicate")
8✔
982
            .function(new OperatorBase.IFunction() {
4✔
983
                @Override
984
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
985
                    ValueTypeList.ValueList valueList = variables.getValue(0, ValueTypes.LIST);
6✔
986
                    IValueTypeListProxy<IValueType<IValue>, IValue> list = valueList.getRawValue();
3✔
987
                    if (list.isInfinite()) {
3!
988
                        throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_INFINITELIST_ILLEGAL,
×
989
                                LIST_CONTAINS_PREDICATE.getLocalizedNameFull()));
×
990
                    }
991
                    IOperator operator = OperatorBuilders.getSafePredictate(variables.getValue(1, ValueTypes.OPERATOR));
7✔
992
                    for (IValue value : list) {
10✔
993
                        IValue result = ValueHelpers.evaluateOperator(operator, value);
9✔
994
                        ValueHelpers.validatePredicateOutput(operator, result);
3✔
995
                        if (((ValueTypeBoolean.ValueBoolean) result).getRawValue()) {
4✔
996
                            return ValueTypeBoolean.ValueBoolean.of(true);
3✔
997
                        }
998
                    }
1✔
999
                    return ValueTypeBoolean.ValueBoolean.of(false);
3✔
1000
                }
1001
            }).build());
1✔
1002

1003
    /**
1004
     * List operator with one input list, and element and one output integer
1005
     */
1006
    public static final IOperator LIST_COUNT = REGISTRY.register(OperatorBuilders.LIST
14✔
1007
            .inputTypes(new IValueType[]{ValueTypes.LIST, ValueTypes.CATEGORY_ANY})
2✔
1008
            .renderPattern(IConfigRenderPattern.INFIX).output(ValueTypes.INTEGER)
4✔
1009
            .symbolOperatorInteract("count")
4✔
1010
            .function(new OperatorBase.IFunction() {
4✔
1011
                @Override
1012
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
1013
                    ValueTypeList.ValueList valueList = variables.getValue(0, ValueTypes.LIST);
6✔
1014
                    IValueTypeListProxy<IValueType<IValue>, IValue> list = valueList.getRawValue();
3✔
1015
                    if (list.isInfinite()) {
3✔
1016
                        throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_INFINITELIST_ILLEGAL,
11✔
1017
                                LIST_COUNT.getLocalizedNameFull()));
2✔
1018
                    }
1019
                    IValue value = variables.getValue(1);
4✔
1020
                    int count = 0;
2✔
1021
                    for (IValue listValue : list) {
10✔
1022
                        if (listValue.equals(value)) {
4✔
1023
                            count++;
1✔
1024
                        }
1025
                    }
1✔
1026
                    return ValueTypeInteger.ValueInteger.of(count);
3✔
1027
                }
1028
            }).build());
1✔
1029

1030
    /**
1031
     * List operator with one input list, a predicate and one output integer
1032
     */
1033
    public static final IOperator LIST_COUNT_PREDICATE = REGISTRY.register(OperatorBuilders.LIST
14✔
1034
            .inputTypes(new IValueType[]{ValueTypes.LIST, ValueTypes.OPERATOR})
2✔
1035
            .renderPattern(IConfigRenderPattern.INFIX).output(ValueTypes.INTEGER)
4✔
1036
            .symbolOperator("count_p").interactName("countPredicate")
6✔
1037
            .function(new OperatorBase.IFunction() {
4✔
1038
                @Override
1039
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
1040
                    ValueTypeList.ValueList valueList = variables.getValue(0, ValueTypes.LIST);
6✔
1041
                    IValueTypeListProxy<IValueType<IValue>, IValue> list = valueList.getRawValue();
3✔
1042
                    if (list.isInfinite()) {
3!
1043
                        throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_INFINITELIST_ILLEGAL,
×
1044
                                LIST_COUNT_PREDICATE.getLocalizedNameFull()));
×
1045
                    }
1046
                    IOperator operator = OperatorBuilders.getSafePredictate(variables.getValue(1, ValueTypes.OPERATOR));
7✔
1047
                    int count = 0;
2✔
1048
                    for (IValue listValue : list) {
10✔
1049
                        IValue result = ValueHelpers.evaluateOperator(operator, listValue);
9✔
1050
                        ValueHelpers.validatePredicateOutput(operator, result);
3✔
1051
                        if (((ValueTypeBoolean.ValueBoolean) result).getRawValue()) {
4✔
1052
                            count++;
1✔
1053
                        }
1054
                    }
1✔
1055
                    return ValueTypeInteger.ValueInteger.of(count);
3✔
1056
                }
1057
            }).build());
1✔
1058

1059
    /**
1060
     * Append an element to the given list
1061
     */
1062
    public static final IOperator LIST_APPEND = REGISTRY.register(OperatorBuilders.LIST
14✔
1063
            .inputTypes(new IValueType[]{ValueTypes.LIST, ValueTypes.CATEGORY_ANY})
2✔
1064
            .renderPattern(IConfigRenderPattern.INFIX).output(ValueTypes.LIST)
4✔
1065
            .symbolOperatorInteract("append")
2✔
1066
            .function(variables -> {
1✔
1067
                ValueTypeList.ValueList valueList = variables.getValue(0, ValueTypes.LIST);
6✔
1068
                IValueTypeListProxy a = valueList.getRawValue();
3✔
1069
                IValue value = variables.getValue(1);
4✔
1070
                if (!ValueHelpers.correspondsTo(a.getValueType(), value.getType())) {
6✔
1071
                    throw new EvaluationException(Component.translatable(
11✔
1072
                            L10NValues.VALUETYPE_ERROR_INVALIDLISTVALUETYPE,
1073
                            Component.translatable(a.getValueType().getTranslationKey()),
7✔
1074
                            Component.translatable(value.getType().getTranslationKey())));
4✔
1075
                }
1076
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyAppend(a, value));
7✔
1077
            }).build());
1✔
1078

1079
    /**
1080
     * Concatenate two lists
1081
     */
1082
    public static final IOperator LIST_CONCAT = REGISTRY.register(OperatorBuilders.LIST
14✔
1083
            .inputTypes(new IValueType[]{ValueTypes.LIST, ValueTypes.LIST})
2✔
1084
            .renderPattern(IConfigRenderPattern.INFIX).output(ValueTypes.LIST)
4✔
1085
            .symbolOperatorInteract("concat")
2✔
1086
            .function(variables -> {
1✔
1087
                ValueTypeList.ValueList valueList0 = variables.getValue(0, ValueTypes.LIST);
6✔
1088
                IValueTypeListProxy a = valueList0.getRawValue();
3✔
1089
                ValueTypeList.ValueList valueList1 = variables.getValue(1, ValueTypes.LIST);
6✔
1090
                IValueTypeListProxy b = valueList1.getRawValue();
3✔
1091
                if (!ValueHelpers.correspondsTo(a.getValueType(), b.getValueType())) {
6!
1092
                    throw new EvaluationException(Component.translatable(
×
1093
                            L10NValues.VALUETYPE_ERROR_INVALIDLISTVALUETYPE,
1094
                            Component.translatable(a.getValueType().getTranslationKey()),
×
1095
                            Component.translatable(b.getValueType().getTranslationKey())));
×
1096
                }
1097
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyConcat(a, b));
15✔
1098
            }).build());
1✔
1099

1100
    /**
1101
     * Build a list lazily using a start value and an operator that is applied to the previous element to get a next element.
1102
     */
1103
    public static final IOperator LIST_LAZYBUILT = REGISTRY.register(OperatorBuilders.LIST
14✔
1104
            .inputTypes(new IValueType[]{ValueTypes.CATEGORY_ANY, ValueTypes.OPERATOR})
2✔
1105
            .renderPattern(IConfigRenderPattern.INFIX).output(ValueTypes.LIST)
4✔
1106
            .symbolOperator("lazybuilt").interactName("lazyBuilt")
4✔
1107
            .function(variables -> {
1✔
1108
                IValue a = variables.getValue(0);
4✔
1109
                IOperator operator = OperatorBuilders.getSafeOperator(variables.getValue(1, ValueTypes.OPERATOR), a.getType());
9✔
1110
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyLazyBuilt<>(a, operator));
7✔
1111
            }).build());
1✔
1112

1113
    /**
1114
     * Get the first element of the given list.
1115
     */
1116
    public static final IOperator LIST_HEAD = REGISTRY.register(OperatorBuilders.LIST_1_PREFIX
10✔
1117
            .inputTypes(new IValueType[]{ValueTypes.LIST}).output(ValueTypes.CATEGORY_ANY)
4✔
1118
            .renderPattern(IConfigRenderPattern.PREFIX_1_LONG).symbolOperatorInteract("head")
4✔
1119
            .function(variables -> {
2✔
1120
                ValueTypeList.ValueList list = variables.getValue(0, ValueTypes.LIST);
6✔
1121
                IValueTypeListProxy a = list.getRawValue();
3✔
1122
                if (a.getLength() > 0) {
3!
1123
                    return a.get(0);
4✔
1124
                } else {
1125
                    throw new EvaluationException(Component.translatable(
×
1126
                            L10NValues.OPERATOR_ERROR_INDEXOUTOFBOUNDS, 0, a.getLength()));
×
1127
                }
1128
            }).conditionalOutputTypeDeriver((operator, input) -> {
1✔
1129
                try {
1130
                    IValueTypeListProxy a = ((ValueTypeList.ValueList) input[0].getValue()).getRawValue();
×
1131
                    return a.getValueType();
×
1132
                } catch (EvaluationException e) {
×
1133
                    return operator.getOutputType();
×
1134
                }
1135
            }).build());
1✔
1136

1137
    /**
1138
     * Append an element to the given list.
1139
     */
1140
    public static final IOperator LIST_TAIL = REGISTRY.register(OperatorBuilders.LIST
10✔
1141
            .inputTypes(new IValueType[]{ValueTypes.LIST})
2✔
1142
            .renderPattern(IConfigRenderPattern.PREFIX_1_LONG).output(ValueTypes.LIST)
4✔
1143
            .symbolOperatorInteract("tail")
2✔
1144
            .function(variables -> {
1✔
1145
                ValueTypeList.ValueList list = variables.getValue(0, ValueTypes.LIST);
6✔
1146
                IValueTypeListProxy a = list.getRawValue();
3✔
1147
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyTail(a));
6✔
1148
            }).build());
1✔
1149

1150
    /**
1151
     * Deduplicate the given list elements based on the given predicate.
1152
     */
1153
    public static final IOperator LIST_UNIQ_PREDICATE = REGISTRY.register(OperatorBuilders.LIST
14✔
1154
            .inputTypes(new IValueType[]{ValueTypes.LIST, ValueTypes.OPERATOR})
2✔
1155
            .renderPattern(IConfigRenderPattern.INFIX).output(ValueTypes.LIST)
4✔
1156
            .symbolOperator("uniq_p").interactName("uniquePredicate")
6✔
1157
            .function(new OperatorBase.IFunction() {
4✔
1158
                @Override
1159
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
1160
                    ValueTypeList.ValueList valueList = variables.getValue(0, ValueTypes.LIST);
6✔
1161
                    IValueTypeListProxy<IValueType<IValue>, IValue> list = valueList.getRawValue();
3✔
1162
                    if (list.isInfinite()) {
3!
1163
                        throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_INFINITELIST_ILLEGAL,
×
1164
                                LIST_UNIQ_PREDICATE.getLocalizedNameFull()));
×
1165
                    }
1166
                    final IOperator operator = OperatorBuilders.getSafePredictate(variables.getValue(1, ValueTypes.OPERATOR));
7✔
1167
                    List<IValue> values = new ArrayList<>();
4✔
1168
                    outerLoop:
1169
                    for(IValue value : list) {
10✔
1170
                        for(IValue existing : values) {
10✔
1171
                            IValue result;
1172
                            try {
1173
                                result = ValueHelpers.evaluateOperator(operator, value, existing);
13✔
1174
                                ValueHelpers.validatePredicateOutput(operator, result);
3✔
1175
                            } catch (EvaluationException e) {
×
1176
                                throw Lombok.sneakyThrow(e);
×
1177
                            }
1✔
1178
                            if(((ValueTypeBoolean.ValueBoolean) result).getRawValue()) continue outerLoop;
5✔
1179
                        }
1✔
1180
                        values.add(value);
4✔
1181
                    }
1✔
1182
                    return ValueTypeList.ValueList.ofList(list.getValueType(), values);
5✔
1183
                }
1184
            }).build());
1✔
1185

1186
    /**
1187
     * Deduplicate the given list elements.
1188
     */
1189
    public static final IOperator LIST_UNIQ = REGISTRY.register(OperatorBuilders.LIST
5✔
1190
            .inputType(ValueTypes.LIST)
2✔
1191
            .renderPattern(IConfigRenderPattern.PREFIX_1_LONG).output(ValueTypes.LIST)
4✔
1192
            .symbolOperator("uniq").interactName("unique")
6✔
1193
            .function(new OperatorBase.IFunction() {
4✔
1194
                @Override
1195
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
1196
                    ValueTypeList.ValueList valueList =variables.getValue(0, ValueTypes.LIST);
6✔
1197
                    IValueTypeListProxy<IValueType<IValue>, IValue> list = valueList.getRawValue();
3✔
1198
                    if (list.isInfinite()) {
3!
1199
                        throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_INFINITELIST_ILLEGAL,
×
1200
                                LIST_UNIQ.getLocalizedNameFull()));
×
1201
                    }
1202
                    return ValueTypeList.ValueList.ofList(list.getValueType(), new ArrayList<>(Sets.newLinkedHashSet(list)));
9✔
1203
                }
1204
            }).build());
1✔
1205

1206
    /**
1207
     * Take a subset of the given list from the given index (inclusive) to the given index (exclusive).
1208
     */
1209
    public static final IOperator LIST_SLICE = REGISTRY.register(OperatorBuilders.LIST
18✔
1210
            .inputTypes(ValueTypes.LIST, ValueTypes.INTEGER, ValueTypes.INTEGER)
2✔
1211
            .renderPattern(IConfigRenderPattern.PREFIX_3).output(ValueTypes.LIST)
4✔
1212
            .symbolOperatorInteract("slice")
2✔
1213
            .function(variables -> {
1✔
1214
                ValueTypeList.ValueList valueList =variables.getValue(0, ValueTypes.LIST);
6✔
1215
                IValueTypeListProxy<IValueType<IValue>, IValue> list = valueList.getRawValue();
3✔
1216
                ValueTypeInteger.ValueInteger from = variables.getValue(1, ValueTypes.INTEGER);
6✔
1217
                ValueTypeInteger.ValueInteger to = variables.getValue(2, ValueTypes.INTEGER);
6✔
1218
                if (from.getRawValue() >= to.getRawValue()) {
5✔
1219
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_SLICE_TOGREATERTHANFROM));
6✔
1220
                }
1221
                if (from.getRawValue() < 0 || to.getRawValue() < 0){
6!
1222
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_SLICE_INDEXNEGATIVE));
6✔
1223
                }
1224
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxySlice<>(list, from.getRawValue(), to.getRawValue()));
10✔
1225
            }).build());
1✔
1226

1227
    public static final IOperator LIST_INTERSECTION = REGISTRY.register(OperatorBuilders.LIST
14✔
1228
            .inputTypes(ValueTypes.LIST, ValueTypes.LIST)
2✔
1229
            .renderPattern(IConfigRenderPattern.INFIX).output(ValueTypes.LIST)
4✔
1230
            .symbol("∩").operatorInteract("intersection")
6✔
1231
            .function(new OperatorBase.IFunction() {
4✔
1232
                @Override
1233
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
1234
                    IValueTypeListProxy<IValueType<IValue>, IValue> rawList1 = variables.getValue(0, ValueTypes.LIST).getRawValue();
7✔
1235
                    IValueTypeListProxy<IValueType<IValue>, IValue> rawList2 = variables.getValue(1, ValueTypes.LIST).getRawValue();
7✔
1236
                    if (rawList1.isInfinite() || rawList2.isInfinite()) {
6!
1237
                        throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_INFINITELIST_ILLEGAL,
×
1238
                                LIST_INTERSECTION.getLocalizedNameFull()));
×
1239
                    }
1240
                    LinkedHashSet<IValue> result = Sets.newLinkedHashSet(rawList1);
3✔
1241
                    result.retainAll(Sets.newLinkedHashSet(rawList2));
5✔
1242

1243
                    return ValueTypeList.ValueList.ofList(rawList1.getValueType(), result.stream().toList());
7✔
1244
                }
1245
            }).build());
1✔
1246

1247
    /**
1248
     * Test list equality using set semantics.
1249
     */
1250
    public static final IOperator LIST_EQUALS_SET = REGISTRY.register(OperatorBuilders.LIST
14✔
1251
            .inputTypes(new IValueType[]{ValueTypes.LIST, ValueTypes.LIST})
2✔
1252
            .renderPattern(IConfigRenderPattern.INFIX).output(ValueTypes.BOOLEAN)
4✔
1253
            .symbol("=set=").operatorInteract("equals_set")
4✔
1254
            .function(variables -> {
1✔
1255
                ValueTypeList.ValueList valueList0 = variables.getValue(0, ValueTypes.LIST);
6✔
1256
                IValueTypeListProxy a = valueList0.getRawValue();
3✔
1257
                ValueTypeList.ValueList valueList1 = variables.getValue(1, ValueTypes.LIST);
6✔
1258
                IValueTypeListProxy b = valueList1.getRawValue();
3✔
1259
                if (!ValueHelpers.correspondsTo(a.getValueType(), b.getValueType())) {
6!
1260
                    throw new EvaluationException(Component.translatable(
×
1261
                            L10NValues.VALUETYPE_ERROR_INVALIDLISTVALUETYPE,
1262
                            Component.translatable(a.getValueType().getTranslationKey()),
×
1263
                            Component.translatable(b.getValueType().getTranslationKey())));
×
1264
                }
1265
                Set<Object> setA = Sets.newHashSet(a);
3✔
1266
                Set<Object> setB = Sets.newHashSet(b);
3✔
1267
                return ValueTypeBoolean.ValueBoolean.of(setA.equals(setB));
5✔
1268
            }).build());
1✔
1269

1270
    /**
1271
     * Test list equality using multiset semantics.
1272
     */
1273
    public static final IOperator LIST_EQUALS_MULTISET = REGISTRY.register(OperatorBuilders.LIST
14✔
1274
            .inputTypes(new IValueType[]{ValueTypes.LIST, ValueTypes.LIST})
2✔
1275
            .renderPattern(IConfigRenderPattern.INFIX).output(ValueTypes.BOOLEAN)
4✔
1276
            .symbol("=multiset=").operatorInteract("equals_multiset")
4✔
1277
            .function(variables -> {
1✔
1278
                ValueTypeList.ValueList valueList0 = variables.getValue(0, ValueTypes.LIST);
6✔
1279
                IValueTypeListProxy a = valueList0.getRawValue();
3✔
1280
                ValueTypeList.ValueList valueList1 = variables.getValue(1, ValueTypes.LIST);
6✔
1281
                IValueTypeListProxy b = valueList1.getRawValue();
3✔
1282
                if (!ValueHelpers.correspondsTo(a.getValueType(), b.getValueType())) {
6!
1283
                    throw new EvaluationException(Component.translatable(
×
1284
                            L10NValues.VALUETYPE_ERROR_INVALIDLISTVALUETYPE,
1285
                            Component.translatable(a.getValueType().getTranslationKey()),
×
1286
                            Component.translatable(b.getValueType().getTranslationKey())));
×
1287
                }
1288
                Multiset<Object> setA = HashMultiset.create(a);
3✔
1289
                Multiset<Object> setB = HashMultiset.create(b);
3✔
1290
                return ValueTypeBoolean.ValueBoolean.of(setA.equals(setB));
5✔
1291
            }).build());
1✔
1292

1293
    /**
1294
     * ----------------------------------- BLOCK OBJECT OPERATORS -----------------------------------
1295
     */
1296

1297
    /**
1298
     * Block isOpaque operator with one input block and one output boolean.
1299
     */
1300
    public static final IOperator OBJECT_BLOCK_OPAQUE = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG.output(ValueTypes.BOOLEAN).symbolOperator("opaque").interactName("isOpaque")
11✔
1301
            .function(variables -> {
1✔
1302
                ValueObjectTypeBlock.ValueBlock a = variables.getValue(0, ValueTypes.OBJECT_BLOCK);
6✔
1303
                return ValueTypeBoolean.ValueBoolean.of(a.getRawValue().isPresent() && a.getRawValue().get().isSolidRender());
15!
1304
            }).build());
1✔
1305

1306
    /**
1307
     * The itemstack representation of the block
1308
     */
1309
    public static final IOperator OBJECT_BLOCK_ITEMSTACK = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG.output(ValueTypes.OBJECT_ITEMSTACK).symbolOperator("itemstack").interactName("itemStack")
11✔
1310
            .function(variables -> {
1✔
1311
                ValueObjectTypeBlock.ValueBlock a = variables.getValue(0, ValueTypes.OBJECT_BLOCK);
6✔
1312
                return ValueObjectTypeItemStack.ValueItemStack.of(a.getRawValue().isPresent() ? IModHelpers.get().getBlockHelpers().getItemStackFromBlockState(a.getRawValue().get()) : ItemStack.EMPTY);
14!
1313
            }).build());
1✔
1314

1315
    /**
1316
     * The name of the mod owning this block
1317
     */
1318
    public static final IOperator OBJECT_BLOCK_MODNAME = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG.output(ValueTypes.STRING).symbolOperatorInteract("mod")
20✔
1319
            .function(new IterativeFunction(Lists.newArrayList(
3✔
1320
                    (OperatorBase.SafeVariablesGetter variables) -> {
1321
                        ValueObjectTypeBlock.ValueBlock a = variables.getValue(0, ValueTypes.OBJECT_BLOCK);
6✔
1322
                        return a.getRawValue().isPresent() ? BuiltInRegistries.BLOCK.getKey(a.getRawValue().get().getBlock()) : Identifier.parse("");
13!
1323
                    },
1324
                    OperatorBuilders.PROPAGATOR_RESOURCELOCATION_MODNAME
1325
            ))).build());
1✔
1326

1327
    /**
1328
     * The breaksound of the block
1329
     */
1330
    public static final IOperator OBJECT_BLOCK_BREAKSOUND = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG.output(ValueTypes.STRING)
7✔
1331
            .symbol("break_sound").operatorName("breaksound").interactName("breakSound")
21✔
1332
            .function(new IterativeFunction(Lists.newArrayList(
3✔
1333
                    OperatorBuilders.BLOCK_SOUND,
1334
                    (Optional<SoundType> sound) -> sound.isPresent() ? sound.get().getBreakSound().location().toString() : "",
11!
1335
                    OperatorBuilders.PROPAGATOR_STRING_VALUE
1336
            ))).build());
1✔
1337
    /**
1338
     * The placesound of the block
1339
     */
1340
    public static final IOperator OBJECT_BLOCK_PLACESOUND = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG.output(ValueTypes.STRING)
7✔
1341
            .symbol("place_sound").operatorName("placesound").interactName("placeSound")
21✔
1342
            .function(new IterativeFunction(Lists.newArrayList(
3✔
1343
                    OperatorBuilders.BLOCK_SOUND,
1344
                    (Optional<SoundType> sound) -> sound.isPresent() ? sound.get().getPlaceSound().location().toString() : "",
11!
1345
                    OperatorBuilders.PROPAGATOR_STRING_VALUE
1346
            ))).build());
1✔
1347
    /**
1348
     * The stepsound of the block
1349
     */
1350
    public static final IOperator OBJECT_BLOCK_STEPSOUND = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG.output(ValueTypes.STRING)
7✔
1351
            .symbol("step_sound").operatorName("stepsound").interactName("stepSound")
21✔
1352
            .function(new IterativeFunction(Lists.newArrayList(
3✔
1353
                    OperatorBuilders.BLOCK_SOUND,
1354
                    (Optional<SoundType> sound) -> sound.isPresent() ? sound.get().getStepSound().location().toString() : "",
11!
1355
                    OperatorBuilders.PROPAGATOR_STRING_VALUE
1356
            ))).build());
1✔
1357

1358
    /**
1359
     * If the block is shearable
1360
     */
1361
    public static final IOperator OBJECT_BLOCK_ISSHEARABLE = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG.output(ValueTypes.BOOLEAN)
7✔
1362
            .symbol("is_shearable").operatorName("isshearable").interactName("isShearable")
6✔
1363
            .function(variables -> {
1✔
1364
                ValueObjectTypeBlock.ValueBlock a = variables.getValue(0, ValueTypes.OBJECT_BLOCK);
6✔
1365
                return ValueTypeBoolean.ValueBoolean.of(a.getRawValue().isPresent()
7!
1366
                        && a.getRawValue().get().getBlock() instanceof IShearable
7✔
1367
                        && ((IShearable) a.getRawValue().get().getBlock()).isShearable(null, ItemStack.EMPTY, null, null));
14!
1368
            }).build());
1✔
1369

1370
    /**
1371
     * The block when this block is planted
1372
     */
1373
    public static final IOperator OBJECT_BLOCK_PLANTAGE = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG
5✔
1374
            .output(ValueTypes.INTEGER).symbol("plant_age").operatorName("plantage").interactName("plantAge")
8✔
1375
            .function(variables -> {
1✔
1376
                ValueObjectTypeBlock.ValueBlock a = variables.getValue(0, ValueTypes.OBJECT_BLOCK);
6✔
1377
                int age = 0;
2✔
1378
                if (a.getRawValue().isPresent()) {
4!
1379
                    for (Property<?> prop : a.getRawValue().get().getProperties()) {
14✔
1380
                        if (prop.getName().equals("age") && prop.getValueClass() == Integer.class) {
9!
1381
                            age = (Integer) a.getRawValue().get().getValue(prop);
9✔
1382
                        }
1383
                    }
1✔
1384
                }
1385
                return ValueTypeInteger.ValueInteger.of(age);
3✔
1386
            }).build());
1✔
1387

1388
    /**
1389
     * Get a block by name.
1390
     */
1391
    public static final IOperator OBJECT_BLOCK_BY_NAME = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG
5✔
1392
            .inputType(ValueTypes.STRING).output(ValueTypes.OBJECT_BLOCK)
4✔
1393
            .symbol("block_by_name").operatorName("blockbyname").interactName("blockByName")
7✔
1394
            .function(OperatorBuilders.FUNCTION_STRING_TO_RESOURCE_LOCATION
1✔
1395
                    .build(input -> {
1✔
1396
                        Block block = BuiltInRegistries.BLOCK.getValue(input);
5✔
1397
                        return ValueObjectTypeBlock.ValueBlock.of(block.defaultBlockState());
4✔
1398
                    })).build());
1✔
1399

1400
    /**
1401
     * Get the block properties as NBT compound tag.
1402
     */
1403
    public static final IOperator OBJECT_BLOCK_PROPERTIES = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG
5✔
1404
            .output(ValueTypes.NBT)
2✔
1405
            .symbol("block_props").operatorName("blockproperties").interactName("properties")
6✔
1406
            .function(variables -> {
1✔
1407
                ValueObjectTypeBlock.ValueBlock a = variables.getValue(0, ValueTypes.OBJECT_BLOCK);
6✔
1408
                return ValueTypeNbt.ValueNbt.of(a.getRawValue().map(blockState -> {
6✔
1409
                    CompoundTag tag = new CompoundTag();
4✔
1410
                    for (Property property : blockState.getProperties()) {
11✔
1411
                        Comparable<?> value = blockState.getValue(property);
4✔
1412
                        tag.putString(property.getName(), property.getName(value));
7✔
1413
                    }
1✔
1414
                    return tag;
2✔
1415
                }));
1416
            }).build());
1✔
1417

1418
    /**
1419
     * Get the given block applied with the given properties.
1420
     */
1421
    public static final IOperator OBJECT_BLOCK_WITH_PROPERTIES = REGISTRY.register(OperatorBuilders.BLOCK_INFIX_VERYLONG
14✔
1422
            .inputTypes(ValueTypes.OBJECT_BLOCK, ValueTypes.NBT).output(ValueTypes.OBJECT_BLOCK)
4✔
1423
            .symbol("block_with_props").operatorName("blockfromproperties").interactName("withProperties")
6✔
1424
            .function(variables -> {
1✔
1425
                ValueObjectTypeBlock.ValueBlock a = variables.getValue(0, ValueTypes.OBJECT_BLOCK);
6✔
1426
                ValueTypeNbt.ValueNbt b = variables.getValue(1, ValueTypes.NBT);
6✔
1427
                if (a.getRawValue().isPresent() && a.getRawValue().isPresent()) {
8!
1428
                    BlockState blockState = a.getRawValue().get();
5✔
1429
                    Tag tagRaw = b.getRawValue().get();
5✔
1430
                    if (tagRaw instanceof CompoundTag) {
3!
1431
                        CompoundTag tag = (CompoundTag) tagRaw;
3✔
1432
                        for (Property property : blockState.getProperties()) {
11✔
1433
                            if (tag.contains(property.getName())) {
5!
1434
                                Optional<Comparable> valueOptional = property.getValue(tag.getString(property.getName()).orElseThrow());
9✔
1435
                                if (valueOptional.isPresent()) {
3!
1436
                                    blockState = blockState.setValue(property, valueOptional.get());
8✔
1437
                                }
1438
                            }
1439
                        }
1✔
1440
                        return ValueObjectTypeBlock.ValueBlock.of(blockState);
3✔
1441
                    }
1442
                }
1443
                return a;
×
1444
            }).build());
1✔
1445

1446
    /**
1447
     * Get all possible block properties as NBT compound tag with list values.
1448
     */
1449
    public static final IOperator OBJECT_BLOCK_POSSIBLE_PROPERTIES = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG
5✔
1450
            .output(ValueTypes.NBT)
2✔
1451
            .symbol("block_all_props").operatorName("blockpossibleproperties").interactName("possibleProperties")
6✔
1452
            .function(variables -> {
1✔
1453
                ValueObjectTypeBlock.ValueBlock a = variables.getValue(0, ValueTypes.OBJECT_BLOCK);
6✔
1454
                return ValueTypeNbt.ValueNbt.of(a.getRawValue().map(blockState -> {
6✔
1455
                    CompoundTag tag = new CompoundTag();
4✔
1456
                    for (Property property : blockState.getProperties()) {
11✔
1457
                        ListTag list = new ListTag();
4✔
1458
                        for (Comparable value : (Collection<Comparable>) property.getPossibleValues()) {
11✔
1459
                            list.add(StringTag.valueOf(property.getName(value)));
7✔
1460
                        }
1✔
1461
                        tag.put(property.getName(), list);
6✔
1462
                    }
1✔
1463
                    return tag;
2✔
1464
                }));
1465
            }).build());
1✔
1466

1467
    /**
1468
     * The tag entries of the given block
1469
     */
1470
    public static final IOperator OBJECT_BLOCK_TAG = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG
5✔
1471
            .output(ValueTypes.LIST)
2✔
1472
            .symbol("block_tag_names").operatorName("tag").interactName("tags")
6✔
1473
            .function(variables -> {
1✔
1474
                ValueObjectTypeBlock.ValueBlock a = variables.getValue(0, ValueTypes.OBJECT_BLOCK);
6✔
1475
                ImmutableList.Builder<ValueTypeString.ValueString> builder = ImmutableList.builder();
2✔
1476
                if(!a.getRawValue().isEmpty()) {
4!
1477
                    a.getRawValue().get().getBlock().builtInRegistryHolder().tags()
9✔
1478
                            .forEach(owningTag -> builder.add(ValueTypeString.ValueString
6✔
1479
                                    .of(owningTag.location().toString())));
3✔
1480
                }
1481
                return ValueTypeList.ValueList.ofList(ValueTypes.STRING, builder.build());
5✔
1482
            }).build());
1✔
1483

1484
    /**
1485
     * Get a list of blocks that correspond to the given tag key.
1486
     */
1487
    public static final IOperator OBJECT_BLOCK_TAG_STACKS = REGISTRY.register(OperatorBuilders.STRING_1_PREFIX
5✔
1488
            .output(ValueTypes.LIST)
2✔
1489
            .symbol("block_tag_values").operatorName("blocktag").interactName("blocksByTag")
6✔
1490
            .inputType(ValueTypes.STRING).renderPattern(IConfigRenderPattern.SUFFIX_1_LONG)
4✔
1491
            .function(variables -> {
1✔
1492
                ValueTypeString.ValueString a = variables.getValue(0, ValueTypes.STRING);
6✔
1493
                ImmutableList.Builder<ValueObjectTypeBlock.ValueBlock> builder = ImmutableList.builder();
2✔
1494
                if (!StringUtil.isNullOrEmpty(a.getRawValue())) {
4!
1495
                    try {
1496
                        Helpers.getBlockTagValues(a.getRawValue())
4✔
1497
                                .map(ValueObjectTypeBlock.ValueBlock::of)
3✔
1498
                                .forEach(builder::add);
4✔
1499
                    } catch (IdentifierException e) {
×
1500
                        throw new EvaluationException(Component.translatable(e.getMessage()));
×
1501
                    }
1✔
1502
                }
1503
                return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_BLOCK, builder.build());
5✔
1504
            }).build());
1✔
1505

1506
    /**
1507
     * ----------------------------------- ITEM STACK OBJECT OPERATORS -----------------------------------
1508
     */
1509

1510
    /**
1511
     * Item Stack size operator with one input itemstack and one output integer.
1512
     */
1513
    public static final IOperator OBJECT_ITEMSTACK_SIZE = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1514
            .output(ValueTypes.INTEGER).symbolOperator("size").interactName("size")
7✔
1515
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_INT.build(
2✔
1516
                itemStack -> !itemStack.isEmpty() ? itemStack.getCount() : 0
8!
1517
            )).build());
1✔
1518

1519
    /**
1520
     * Item Stack maxsize operator with one input itemstack and one output integer.
1521
     */
1522
    public static final IOperator OBJECT_ITEMSTACK_MAXSIZE = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1523
            .output(ValueTypes.INTEGER).symbolOperator("maxsize").interactName("maxSize")
7✔
1524
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_INT.build(
2✔
1525
                itemStack -> !itemStack.isEmpty() ? itemStack.getMaxStackSize() : 0
8!
1526
            )).build());
1✔
1527

1528
    /**
1529
     * Item Stack isstackable operator with one input itemstack and one output boolean.
1530
     */
1531
    public static final IOperator OBJECT_ITEMSTACK_ISSTACKABLE = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1532
            .output(ValueTypes.BOOLEAN).symbolOperator("stackable").interactName("isStackable")
7✔
1533
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_BOOLEAN.build(
2✔
1534
                itemStack -> !itemStack.isEmpty() && itemStack.isStackable()
11!
1535
            )).build());
1✔
1536

1537
    /**
1538
     * Item Stack isdamageable operator with one input itemstack and one output boolean.
1539
     */
1540
    public static final IOperator OBJECT_ITEMSTACK_ISDAMAGEABLE = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1541
            .output(ValueTypes.BOOLEAN).symbolOperator("damageable").interactName("isDamageable")
7✔
1542
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_BOOLEAN.build(
2✔
1543
                itemStack -> !itemStack.isEmpty() && itemStack.isDamageableItem()
11!
1544
            )).build());
1✔
1545

1546
    /**
1547
     * Item Stack damage operator with one input itemstack and one output integer.
1548
     */
1549
    public static final IOperator OBJECT_ITEMSTACK_DAMAGE = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1550
            .output(ValueTypes.INTEGER).symbolOperator("damage").interactName("damage")
7✔
1551
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_INT.build(
2✔
1552
                itemStack -> !itemStack.isEmpty() ? itemStack.getDamageValue() : 0
8!
1553
            )).build());
1✔
1554

1555
    /**
1556
     * Item Stack maxdamage operator with one input itemstack and one output integer.
1557
     */
1558
    public static final IOperator OBJECT_ITEMSTACK_MAXDAMAGE = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1559
            .output(ValueTypes.INTEGER).symbol("max_damage").operatorName("maxdamage").interactName("maxDamage")
9✔
1560
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_INT.build(
2✔
1561
                itemStack -> !itemStack.isEmpty() ? itemStack.getMaxDamage() : 0
8!
1562
            )).build());
1✔
1563

1564
    /**
1565
     * Item Stack isenchanted operator with one input itemstack and one output boolean.
1566
     */
1567
    public static final IOperator OBJECT_ITEMSTACK_ISENCHANTED = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1568
            .output(ValueTypes.BOOLEAN).symbolOperator("enchanted").interactName("isEnchanted")
7✔
1569
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_BOOLEAN.build(
2✔
1570
                itemStack -> !itemStack.isEmpty() && itemStack.isEnchanted()
11!
1571
            )).build());
1✔
1572

1573
    /**
1574
     * Item Stack isenchantable operator with one input itemstack and one output boolean.
1575
     */
1576
    public static final IOperator OBJECT_ITEMSTACK_ISENCHANTABLE = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1577
            .output(ValueTypes.BOOLEAN).symbolOperator("enchantable").interactName("isEnchantable")
7✔
1578
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_BOOLEAN.build(
2✔
1579
                itemStack -> !itemStack.isEmpty() && itemStack.isEnchantable()
11!
1580
            )).build());
1✔
1581

1582
    /**
1583
     * Item Stack repair cost with one input itemstack and one output integer.
1584
     */
1585
    public static final IOperator OBJECT_ITEMSTACK_REPAIRCOST = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1586
            .output(ValueTypes.INTEGER)
2✔
1587
            .symbol("repair_cost").operatorName("repaircost").interactName("repairCost")
7✔
1588
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_INT.build(
2✔
1589
                itemStack -> !itemStack.isEmpty() ? itemStack.get(DataComponents.REPAIR_COST) : 0
9!
1590
            )).build());
1✔
1591

1592
    /**
1593
     * Get the rarity of an itemstack.
1594
     */
1595
    public static final IOperator OBJECT_ITEMSTACK_RARITY = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1596
            .output(ValueTypes.STRING).symbolOperatorInteract("rarity")
4✔
1597
            .function(variables -> {
1✔
1598
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1599
                return ValueTypeString.ValueString.of(!a.getRawValue().isEmpty() ? a.getRawValue().getRarity().name() : "");
11!
1600
            }).build());
1✔
1601

1602
    /**
1603
     * Get the strength of an itemstack against a block as a double.
1604
     */
1605
    public static final IOperator OBJECT_ITEMSTACK_STRENGTH_VS_BLOCK = REGISTRY.register(OperatorBuilders.ITEMSTACK_2
14✔
1606
            .inputTypes(new IValueType[]{ValueTypes.OBJECT_ITEMSTACK, ValueTypes.OBJECT_BLOCK}).output(ValueTypes.DOUBLE)
4✔
1607
            .symbolOperatorInteract("strength")
2✔
1608
            .function(variables -> {
1✔
1609
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1610
                ValueObjectTypeBlock.ValueBlock b = variables.getValue(1, ValueTypes.OBJECT_BLOCK);
6✔
1611
                return ValueTypeDouble.ValueDouble.of(!a.getRawValue().isEmpty() && b.getRawValue().isPresent() ? a.getRawValue().getDestroySpeed(b.getRawValue().get()) : 0);
19!
1612
            }).build());
1✔
1613

1614
    /**
1615
     * If the given itemstack can be used to harvest the given block.
1616
     */
1617
    public static final IOperator OBJECT_ITEMSTACK_CAN_HARVEST_BLOCK = REGISTRY.register(OperatorBuilders.ITEMSTACK_2_LONG
14✔
1618
            .inputTypes(new IValueType[]{ValueTypes.OBJECT_ITEMSTACK, ValueTypes.OBJECT_BLOCK}).output(ValueTypes.BOOLEAN)
4✔
1619
            .symbol("can_harvest").operatorName("canharvest").interactName("canHarvest")
6✔
1620
            .function(variables -> {
1✔
1621
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1622
                ValueObjectTypeBlock.ValueBlock b = variables.getValue(1, ValueTypes.OBJECT_BLOCK);
6✔
1623
                return ValueTypeBoolean.ValueBoolean.of(!a.getRawValue().isEmpty() && b.getRawValue().isPresent() && a.getRawValue().isCorrectToolForDrops(b.getRawValue().get()));
21!
1624
            }).build());
1✔
1625

1626
    /**
1627
     * The block from the stack
1628
     */
1629
    public static final IOperator OBJECT_ITEMSTACK_BLOCK = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1630
            .output(ValueTypes.OBJECT_BLOCK).symbolOperatorInteract("block")
4✔
1631
            .function(variables -> {
1✔
1632
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1633
                return ValueObjectTypeBlock.ValueBlock.of((!a.getRawValue().isEmpty() && a.getRawValue().getItem() instanceof BlockItem) ? IModHelpers.get().getBlockHelpers().getBlockStateFromItemStack(a.getRawValue()) : null);
17!
1634
            }).build());
1✔
1635

1636
    /**
1637
     * If the given stack has a fluid.
1638
     */
1639
    public static final IOperator OBJECT_ITEMSTACK_ISFLUIDSTACK = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1640
            .output(ValueTypes.BOOLEAN)
2✔
1641
            .symbol("is_fluidstack").operatorName("isfluidstack").interactName("isFluidStack")
7✔
1642
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_BOOLEAN.build(
2✔
1643
                itemStack -> !itemStack.isEmpty() && !Helpers.getFluidStack(itemStack).isEmpty()
12!
1644
            )).build());
1✔
1645

1646
    /**
1647
     * The fluidstack from the stack
1648
     */
1649
    public static final IOperator OBJECT_ITEMSTACK_FLUIDSTACK = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1650
            .output(ValueTypes.OBJECT_FLUIDSTACK).symbolOperator("fluidstack").interactName("fluidStack")
6✔
1651
            .function(variables -> {
1✔
1652
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1653
                return ValueObjectTypeFluidStack.ValueFluidStack.of(!a.getRawValue().isEmpty() ? Helpers.getFluidStack(a.getRawValue()) : FluidStack.EMPTY);
11✔
1654
            }).build());
1✔
1655

1656
    /**
1657
     * The capacity of the fluidstack from the stack.
1658
     */
1659
    public static final IOperator OBJECT_ITEMSTACK_FLUIDSTACKCAPACITY = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1660
            .output(ValueTypes.LONG)
2✔
1661
            .symbol("fluidstack_capacity").operatorName("fluidstackcapacity").interactName("fluidCapacity")
7✔
1662
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_LONG.build(
2✔
1663
                itemStack -> !itemStack.isEmpty() ? Helpers.getFluidStackCapacity(itemStack) : 0
8!
1664
            )).build());
1✔
1665

1666
    /**
1667
     * If the data components of the given stacks are equal.
1668
     */
1669
    public static final IOperator OBJECT_ITEMSTACK_ISDATAEQUAL = REGISTRY.register(OperatorBuilders.ITEMSTACK_2
5✔
1670
            .output(ValueTypes.BOOLEAN).symbol("=NBT=").operatorName("isnbtequal").interactName("isNbtEqual")
8✔
1671
            .function(variables -> {
1✔
1672
                ValueObjectTypeItemStack.ValueItemStack valueStack0 = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1673
                ValueObjectTypeItemStack.ValueItemStack valueStack1 = variables.getValue(1, ValueTypes.OBJECT_ITEMSTACK);
6✔
1674
                ItemStack a = valueStack0.getRawValue();
3✔
1675
                ItemStack b = valueStack1.getRawValue();
3✔
1676
                boolean equal = false;
2✔
1677
                if(!a.isEmpty() && !b.isEmpty()) {
6!
1678
                    equal = ItemStack.isSameItem(a, b) && ItemMatch.areItemStacksEqual(a, b, ItemMatch.DATA);
14✔
1679
                } else if(a.isEmpty() && b.isEmpty()) {
×
1680
                    equal = true;
×
1681
                }
1682
                return ValueTypeBoolean.ValueBoolean.of(equal);
3✔
1683
            }).build());
1✔
1684

1685
    /**
1686
     * If the raw items of the given stacks are equal, ignoring data components but including damage value.
1687
     */
1688
    public static final IOperator OBJECT_ITEMSTACK_ISITEMEQUALNODATA = REGISTRY.register(OperatorBuilders.ITEMSTACK_2
5✔
1689
            .output(ValueTypes.BOOLEAN).symbol("=NoNBT=").operatorName("isitemequalnonbt").interactName("isEqualNonNbt")
8✔
1690
            .function(variables -> {
1✔
1691
                ValueObjectTypeItemStack.ValueItemStack valueStack0 = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
×
1692
                ValueObjectTypeItemStack.ValueItemStack valueStack1 = variables.getValue(1, ValueTypes.OBJECT_ITEMSTACK);
×
1693
                ItemStack a = valueStack0.getRawValue();
×
1694
                ItemStack b = valueStack1.getRawValue();
×
1695
                boolean equal = false;
×
1696
                if(!a.isEmpty() && !b.isEmpty()) {
×
1697
                    equal = ItemMatch.areItemStacksEqual(a, b, ItemMatch.ITEM);
×
1698
                } else if(a.isEmpty() && b.isEmpty()) {
×
1699
                    equal = true;
×
1700
                }
1701
                return ValueTypeBoolean.ValueBoolean.of(equal);
×
1702
            }).build());
1✔
1703

1704
    /**
1705
     * If the raw items of the given stacks are equal, ignoring data components and damage value.
1706
     */
1707
    public static final IOperator OBJECT_ITEMSTACK_ISRAWITEMEQUAL = REGISTRY.register(OperatorBuilders.ITEMSTACK_2
5✔
1708
            .output(ValueTypes.BOOLEAN).symbol("=Raw=").operatorName("israwitemequal").interactName("isEqualRaw")
8✔
1709
            .function(variables -> {
1✔
1710
                ValueObjectTypeItemStack.ValueItemStack valueStack0 = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1711
                ValueObjectTypeItemStack.ValueItemStack valueStack1 = variables.getValue(1, ValueTypes.OBJECT_ITEMSTACK);
6✔
1712
                ItemStack a = valueStack0.getRawValue();
3✔
1713
                ItemStack b = valueStack1.getRawValue();
3✔
1714
                boolean equal = false;
2✔
1715
                if(!a.isEmpty() && !b.isEmpty()) {
6!
1716
                    equal = ItemMatch.areItemStacksEqual(a, b, ItemMatch.ITEM);
6✔
1717
                } else if(a.isEmpty() && b.isEmpty()) {
×
1718
                    equal = true;
×
1719
                }
1720
                return ValueTypeBoolean.ValueBoolean.of(equal);
3✔
1721
            }).build());
1✔
1722

1723
    /**
1724
     * The name of the mod owning this item
1725
     */
1726
    public static final IOperator OBJECT_ITEMSTACK_MODNAME = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG.output(ValueTypes.STRING)
7✔
1727
            .symbolOperatorInteract("mod")
13✔
1728
            .function(new IterativeFunction(Lists.newArrayList(
3✔
1729
                    (OperatorBase.SafeVariablesGetter variables) -> {
1730
                        ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1731
                        return !a.getRawValue().isEmpty() ? BuiltInRegistries.ITEM.getKey(a.getRawValue().getItem()) : Identifier.parse("");
11!
1732
                    },
1733
                    OperatorBuilders.PROPAGATOR_RESOURCELOCATION_MODNAME
1734
            ))).build());
1✔
1735

1736
    /**
1737
     * The fuel burn time of the given item
1738
     */
1739
    public static final IOperator OBJECT_ITEMSTACK_FUELBURNTIME = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1740
            .output(ValueTypes.INTEGER)
2✔
1741
            .symbol("burn_time").operatorName("burntime").interactName("burnTime")
7✔
1742
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_INT.build(itemStack -> {
2✔
1743
                if (!itemStack.isEmpty()) {
3!
1744
                    int burnTime = itemStack.getBurnTime(null, ServerLifecycleHooks.getCurrentServer().fuelValues());
6✔
1745
                    return EventHooks.getItemBurnTime(itemStack, burnTime == -1
7!
1746
                            ? itemStack.getBurnTime(RecipeType.SMELTING, ServerLifecycleHooks.getCurrentServer().fuelValues())
×
1747
                            : burnTime, null, ServerLifecycleHooks.getCurrentServer().fuelValues());
4✔
1748
                }
1749
                return 0;
×
1750
            })).build());
1✔
1751

1752
    /**
1753
     * If the given item can be used as fuel
1754
     */
1755
    public static final IOperator OBJECT_ITEMSTACK_CANBURN = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1756
            .output(ValueTypes.BOOLEAN)
2✔
1757
            .symbol("can_burn").operatorName("canburn").interactName("canBurn")
7✔
1758
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_BOOLEAN
1✔
1759
                    .build(stack -> stack.getBurnTime(null, ServerLifecycleHooks.getCurrentServer().fuelValues()) > 0))
12✔
1760
            .build());
1✔
1761

1762
    /**
1763
     * The tag entries of the given item
1764
     */
1765
    public static final IOperator OBJECT_ITEMSTACK_TAG = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1766
            .output(ValueTypes.LIST)
2✔
1767
            .symbol("item_tag_names").operatorName("tag").interactName("tags")
6✔
1768
            .function(variables -> {
1✔
1769
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1770
                ImmutableList.Builder<ValueTypeString.ValueString> builder = ImmutableList.builder();
2✔
1771
                if(!a.getRawValue().isEmpty()) {
4!
1772
                    a.getRawValue().getItem().builtInRegistryHolder().tags()
7✔
1773
                            .forEach(owningTag -> builder.add(ValueTypeString.ValueString
6✔
1774
                                    .of(owningTag.location().toString())));
3✔
1775
                }
1776
                return ValueTypeList.ValueList.ofList(ValueTypes.STRING, builder.build());
5✔
1777
            }).build());
1✔
1778

1779
    /**
1780
     * Get a list of items that correspond to the given tag key.
1781
     */
1782
    public static final IOperator OBJECT_ITEMSTACK_TAG_STACKS = REGISTRY.register(OperatorBuilders.STRING_1_PREFIX
5✔
1783
            .output(ValueTypes.LIST)
2✔
1784
            .symbol("item_tag_values").operatorName("tag").interactName("itemsByTag")
6✔
1785
            .inputType(ValueTypes.STRING).renderPattern(IConfigRenderPattern.SUFFIX_1_LONG)
4✔
1786
            .function(variables -> {
1✔
1787
                ValueTypeString.ValueString a = variables.getValue(0, ValueTypes.STRING);
6✔
1788
                ImmutableList.Builder<ValueObjectTypeItemStack.ValueItemStack> builder = ImmutableList.builder();
2✔
1789
                if (!StringUtil.isNullOrEmpty(a.getRawValue())) {
4!
1790
                    try {
1791
                        Helpers.getTagValues(a.getRawValue())
4✔
1792
                                .map(ValueObjectTypeItemStack.ValueItemStack::of)
3✔
1793
                                .forEach(builder::add);
4✔
1794
                    } catch (IdentifierException e) {
×
1795
                        throw new EvaluationException(Component.translatable(e.getMessage()));
×
1796
                    }
1✔
1797
                }
1798
                return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_ITEMSTACK, builder.build());
5✔
1799
            }).build());
1✔
1800

1801
    /**
1802
     * ItemStack operator that applies the given stacksize to the given itemstack and creates a new ItemStack.
1803
     */
1804
    public static final IOperator OBJECT_ITEMSTACK_WITHSIZE = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_INTEGER_1
5✔
1805
            .output(ValueTypes.OBJECT_ITEMSTACK)
2✔
1806
            .symbol("with_size").operatorName("withsize").interactName("withSize")
6✔
1807
            .function(variables -> {
1✔
1808
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1809
                ValueTypeInteger.ValueInteger b = variables.getValue(1, ValueTypes.INTEGER);
6✔
1810
                if (!a.getRawValue().isEmpty()) {
4!
1811
                    ItemStack itemStack = a.getRawValue().copy();
4✔
1812
                    itemStack.setCount(b.getRawValue());
4✔
1813
                    return ValueObjectTypeItemStack.ValueItemStack.of(itemStack);
3✔
1814
                }
1815
                return a;
×
1816
            }).build());
1✔
1817

1818
    /**
1819
     * Check if the item is an energy container item
1820
     */
1821
    public static final IOperator OBJECT_ITEMSTACK_ISENERGYCONTAINER = Operators.REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1822
            .output(ValueTypes.BOOLEAN)
2✔
1823
            .symbol("is_energy_container").operatorName("isenergycontainer").interactName("isEnergyContainer")
7✔
1824
            .function(OperatorBuilders.FUNCTION_CONTAINERITEM_TO_BOOLEAN.build(
2✔
1825
                Objects::nonNull
1826
            )).build());
1✔
1827

1828
    /**
1829
     * Get the storage energy
1830
     */
1831
    public static final IOperator OBJECT_ITEMSTACK_STOREDENERGY = Operators.REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1832
            .output(ValueTypes.LONG)
2✔
1833
            .symbol("stored_energy").operatorName("storedenergy").interactName("energyStored")
7✔
1834
            .function(OperatorBuilders.FUNCTION_CONTAINERITEM_TO_LONG.build(
2✔
1835
                input -> input != null ? input.getAmountAsLong() : 0
8✔
1836
            )).build());
1✔
1837

1838
    /**
1839
     * Get the energy capacity
1840
     */
1841
    public static final IOperator OBJECT_ITEMSTACK_ENERGYCAPACITY = Operators.REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1842
            .output(ValueTypes.LONG)
2✔
1843
            .symbol("capacity_energy").operatorName("energycapacity").interactName("energyCapacity")
7✔
1844
            .function(OperatorBuilders.FUNCTION_CONTAINERITEM_TO_LONG.build(
2✔
1845
                input -> input != null ? input.getCapacityAsLong() : 0
8✔
1846
            )).build());
1✔
1847

1848

1849
    /**
1850
     * If the given item has an inventory.
1851
     */
1852
    public static final IOperator OBJECT_ITEMSTACK_HASINVENTORY = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1853
            .output(ValueTypes.BOOLEAN)
2✔
1854
            .symbol("has_inventory").operatorName("hasinventory").interactName("hasInventory")
6✔
1855
            .function(variables -> {
1✔
1856
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1857
                return ValueTypeBoolean.ValueBoolean.of(!a.getRawValue().isEmpty() && ItemAccess.forStack(a.getRawValue()).getCapability(Capabilities.Item.ITEM) != null);
15!
1858
            }).build());
1✔
1859

1860

1861

1862

1863
    /**
1864
     * Retrieve the inventory size of the given item handler contents.
1865
     */
1866
    public static final IOperator OBJECT_ITEMSTACK_INVENTORYSIZE = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1867
            .output(ValueTypes.INTEGER)
2✔
1868
            .symbol("inventory_size").operatorName("inventorysize").interactName("inventorySize")
6✔
1869
            .function(variables -> {
1✔
1870
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1871
                ResourceHandler<ItemResource> itemHandler = ItemAccess.forStack(a.getRawValue()).getCapability(Capabilities.Item.ITEM);
7✔
1872
                return ValueTypeInteger.ValueInteger.of(itemHandler != null ? itemHandler.size() : 0);
8✔
1873
            }).build());
1✔
1874

1875
    /**
1876
     * Retrieve the inventory of the given item handler contents.
1877
     */
1878
    public static final IOperator OBJECT_ITEMSTACK_INVENTORY = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1879
            .output(ValueTypes.LIST).symbolOperator("inventory").interactName("inventory")
6✔
1880
            .function(variables -> {
1✔
1881
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1882
                ResourceHandler<ItemResource> itemHandler = ItemAccess.forStack(a.getRawValue()).getCapability(Capabilities.Item.ITEM);
7✔
1883
                if (itemHandler != null) {
2✔
1884
                    List<ValueObjectTypeItemStack.ValueItemStack> values = Lists.newArrayListWithCapacity(itemHandler.size());
4✔
1885
                    for (int i = 0; i < itemHandler.size(); i++) {
8✔
1886
                        values.add(ValueObjectTypeItemStack.ValueItemStack.of(itemHandler.getResource(i).toStack(itemHandler.getAmountAsInt(i))));
12✔
1887
                    }
1888
                    return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_ITEMSTACK, values);
4✔
1889
                }
1890
                return ValueTypes.LIST.getDefault();
3✔
1891
            }).build());
1✔
1892

1893
    /**
1894
     * Get an item by name.
1895
     */
1896
    public static final IOperator OBJECT_ITEMSTACK_BY_NAME = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_PREFIX_LONG
5✔
1897
            .inputType(ValueTypes.STRING).output(ValueTypes.OBJECT_ITEMSTACK)
4✔
1898
            .symbol("item_by_name").operatorName("itembyname").interactName("itemByName")
7✔
1899
            .function(OperatorBuilders.FUNCTION_STRING_TO_RESOURCE_LOCATION
1✔
1900
                    .build(input -> {
1✔
1901
                        Item item = BuiltInRegistries.ITEM.getValue(input);
5✔
1902
                        ItemStack itemStack = ItemStack.EMPTY;
2✔
1903
                        if (item != null) {
2!
1904
                            itemStack = new ItemStack(item);
5✔
1905
                        }
1906
                        return ValueObjectTypeItemStack.ValueItemStack.of(itemStack);
3✔
1907
                    })).build());
1✔
1908

1909
    /**
1910
     * Get the total item count of the given item in a list.
1911
     */
1912
    public static final IOperator OBJECT_ITEMSTACK_LIST_COUNT = REGISTRY.register(OperatorBuilders.ITEMSTACK_2_LONG
14✔
1913
            .inputTypes(ValueTypes.LIST, ValueTypes.OBJECT_ITEMSTACK)
2✔
1914
            .output(ValueTypes.INTEGER)
2✔
1915
            .symbol("item_list_count").operatorName("itemlistcount").interactName("itemListCount")
6✔
1916
            .function(variables -> {
1✔
1917
                ValueTypeList.ValueList<IValueType<IValue>, IValue> a = variables.getValue(0, ValueTypes.LIST);
6✔
1918
                ValueObjectTypeItemStack.ValueItemStack b = variables.getValue(1, ValueTypes.OBJECT_ITEMSTACK);
6✔
1919
                if (!ValueHelpers.correspondsTo(a.getRawValue().getValueType(), ValueTypes.OBJECT_ITEMSTACK)) {
6!
1920
                    MutableComponent error = Component.translatable(
×
1921
                            L10NValues.VALUETYPE_ERROR_INVALIDLISTVALUETYPE,
1922
                            Component.translatable(a.getRawValue().getValueType().getTranslationKey()),
×
1923
                            Component.translatable(ValueTypes.OBJECT_ITEMSTACK.getTranslationKey()));
×
1924
                    throw new EvaluationException(error);
×
1925
                }
1926

1927
                ItemStack itemStack = b.getRawValue();
3✔
1928
                int count = 0;
2✔
1929
                for (IValue listValueRaw : a.getRawValue()) {
11✔
1930
                    if (listValueRaw.getType().correspondsTo(ValueTypes.OBJECT_ITEMSTACK)) {
5!
1931
                        ValueObjectTypeItemStack.ValueItemStack listValue = (ValueObjectTypeItemStack.ValueItemStack) listValueRaw;
3✔
1932
                        if (!listValue.getRawValue().isEmpty()) {
4!
1933
                            ItemStack listItem = listValue.getRawValue();
3✔
1934
                            if (!itemStack.isEmpty()) {
3!
1935
                                if (ItemStack.isSameItemSameComponents(itemStack, listItem)) {
4✔
1936
                                    count += listItem.getCount();
6✔
1937
                                }
1938
                            } else {
1939
                                count += listItem.getCount();
×
1940
                            }
1941
                        }
1942
                    }
1943
                }
1✔
1944

1945
                return ValueTypeInteger.ValueInteger.of(count);
3✔
1946
            }).build());
1✔
1947

1948
    /**
1949
     * Item Stack size operator with one input itemstack and one output NBT tag.
1950
     */
1951
    public static final IOperator OBJECT_ITEMSTACK_DATA = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1952
            .output(ValueTypes.NBT).symbol("NBT()").operatorName("nbt").interactName("nbt")
8✔
1953
            .function(input -> {
1✔
1954
                ValueObjectTypeItemStack.ValueItemStack itemStack = input.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1955
                // Explicitly check for item emptiness first, because vanilla sometimes persists NBT when setting stacks to empty
1956
                if (itemStack.getRawValue().isEmpty() || itemStack.getRawValue().getComponents().isEmpty()) {
9!
1957
                    return ValueTypeNbt.ValueNbt.of();
×
1958
                }
1959
                CompoundTag tag = (CompoundTag) DataComponentPatch.CODEC.encodeStart(ServerLifecycleHooks.getCurrentServer().registryAccess().createSerializationContext(NbtOps.INSTANCE), itemStack.getRawValue().getComponentsPatch()).getOrThrow();
12✔
1960
                // Remove entries that have been marked as removed.
1961
                for (String key : Sets.newHashSet(tag.keySet())) {
12✔
1962
                    if (key.startsWith("!")) {
4✔
1963
                        tag.remove(key);
4✔
1964
                    }
1965
                }
1✔
1966
                if (tag.isEmpty()) {
3✔
1967
                    return ValueTypeNbt.ValueNbt.of();
2✔
1968
                }
1969
                return ValueTypeNbt.ValueNbt.of(Optional.of(tag));
4✔
1970
            }).build());
1✔
1971

1972
    /**
1973
     * Item Stack has_nbt operator with one input itemstack and one output boolean.
1974
     */
1975
    public static final IOperator OBJECT_ITEMSTACK_HASDATA = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_PREFIX_LONG
5✔
1976
            .output(ValueTypes.BOOLEAN).symbol("has_nbt").operatorName("hasnbt").interactName("hasNbt")
9✔
1977
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_BOOLEAN.build(
2✔
1978
                    itemStack -> !itemStack.isEmpty() && itemStack.getComponents().stream().anyMatch(t -> !t.type().isTransient())
21!
1979
            )).build());
1✔
1980

1981
    /**
1982
     * Get the data component keys of an itemstack.
1983
     */
1984
    public static final IOperator OBJECT_ITEMSTACK_DATA_KEYS = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1985
            .output(ValueTypes.LIST).symbol("data_keys").operatorName("datakeys").interactName("dataKeys")
8✔
1986
            .function(input -> {
1✔
1987
                ValueObjectTypeItemStack.ValueItemStack itemStack = input.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1988
                // Explicitly check for item emptiness first, because vanilla sometimes persists NBT when setting stacks to empty
1989
                return ValueTypeList.ValueList.ofList(ValueTypes.STRING,
3✔
1990
                        itemStack.getRawValue().isEmpty() ?
4✔
1991
                                Lists.newArrayList() :
2✔
1992
                                itemStack.getRawValue().getComponents().keySet().stream()
5✔
1993
                                        .filter(c -> !c.isTransient())
8!
1994
                                        .map(c -> ValueTypeString.ValueString.of(BuiltInRegistries.DATA_COMPONENT_TYPE.getKey(c).toString()))
8✔
1995
                                        .sorted(Comparator.comparing(ValueTypeString.ValueString::getRawValue))
2✔
1996
                                        .toList());
2✔
1997
            }).build());
1✔
1998

1999
    /**
2000
     * Get the data component value by key
2001
     */
2002
    public static final IOperator OBJECT_ITEMSTACK_DATA_VALUE = REGISTRY.register(OperatorBuilders.ITEMSTACK_2_LONG
14✔
2003
            .inputTypes(ValueTypes.OBJECT_ITEMSTACK, ValueTypes.STRING)
2✔
2004
            .output(ValueTypes.NBT).symbol("data_value").operatorName("datavalue").interactName("dataValue")
8✔
2005
            .function(input -> {
1✔
2006
                ValueObjectTypeItemStack.ValueItemStack itemStack = input.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
2007

2008
                // Determine data component type
2009
                DataComponentType<?> dataComponentType;
2010
                try {
2011
                    dataComponentType = BuiltInRegistries.DATA_COMPONENT_TYPE.getValue(Identifier.parse(input.getValue(1, ValueTypes.STRING).getRawValue()));
11✔
2012
                } catch (IdentifierException e) {
×
2013
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
2014
                }
1✔
2015

2016
                // Fetch component value
2017
                TypedDataComponent<?> typedComponent = itemStack.getRawValue().getComponents().getTyped(dataComponentType);
6✔
2018
                if (typedComponent == null) {
2✔
2019
                    return ValueTypeNbt.ValueNbt.of((Tag) null);
4✔
2020
                }
2021

2022
                // Encode component value
2023
                try {
2024
                    Tag tag = typedComponent.encodeValue(ServerLifecycleHooks.getCurrentServer().registryAccess().createSerializationContext(NbtOps.INSTANCE)).getOrThrow();
9✔
2025
                    return ValueTypeNbt.ValueNbt.of(tag);
3✔
2026
                } catch (IllegalStateException e) {
×
2027
                    return ValueTypeNbt.ValueNbt.of((Tag) null);
×
2028
                }
2029
            }).build());
1✔
2030

2031
    /**
2032
     * Get the data component value by key
2033
     */
2034
    public static final IOperator OBJECT_ITEMSTACK_WITH_DATA = REGISTRY.register(OperatorBuilders.ITEMSTACK_3
18✔
2035
            .inputTypes(ValueTypes.OBJECT_ITEMSTACK, ValueTypes.STRING, ValueTypes.NBT)
2✔
2036
            .output(ValueTypes.NBT).symbol("with_data").operatorName("withdata").interactName("withData")
8✔
2037
            .function(input -> {
1✔
2038
                ValueObjectTypeItemStack.ValueItemStack itemStack = input.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
2039

2040
                // Skip further processing if input value is empty
2041
                Optional<Tag> tagOptional = input.getValue(2, ValueTypes.NBT).getRawValue();
7✔
2042
                if (!tagOptional.isPresent()) {
3!
2043
                    return itemStack;
×
2044
                }
2045

2046
                // Determine data component type
2047
                DataComponentType<?> dataComponentType;
2048
                try {
2049
                    dataComponentType = BuiltInRegistries.DATA_COMPONENT_TYPE.getValue(Identifier.parse(input.getValue(1, ValueTypes.STRING).getRawValue()));
11✔
2050
                } catch (IdentifierException e) {
×
2051
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
2052
                }
1✔
2053

2054
                // Encode component value
2055
                try {
2056
                    Object value = dataComponentType.codec().decode(ServerLifecycleHooks.getCurrentServer().registryAccess().createSerializationContext(NbtOps.INSTANCE), tagOptional.get()).getOrThrow().getFirst();
14✔
2057
                    itemStack = ValueObjectTypeItemStack.ValueItemStack.of(itemStack.getRawValue().copy());
5✔
2058
                    itemStack.getRawValue().set((DataComponentType) dataComponentType, value);
6✔
2059
                    return itemStack;
2✔
2060
                } catch (IllegalStateException e) {
×
2061
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
2062
                }
2063
            }).build());
1✔
2064

2065
    /**
2066
     * Get the tooltip of an itemstack in list form.
2067
     */
2068
    public static final IOperator OBJECT_ITEMSTACK_TOOLTIP = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
2069
            .output(ValueTypes.LIST).symbol("tooltip").operatorName("tooltip").interactName("tooltip")
8✔
2070
            .function(input -> {
1✔
2071
                ValueObjectTypeItemStack.ValueItemStack itemStack = input.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
2072
                return ValueTypeList.ValueList.ofList(ValueTypes.STRING,
4✔
2073
                        itemStack.getRawValue().getTooltipLines(Item.TooltipContext.EMPTY, null, TooltipFlag.Default.NORMAL).stream()
7✔
2074
                                .map(c -> ValueTypeString.ValueString.of(c.getString()))
5✔
2075
                                .toList());
1✔
2076
            }).build());
1✔
2077
    /**
2078
     * Get the tooltip of an itemstack in list form, using the provided player entity as the player context.
2079
     */
2080
    public static final IOperator OBJECT_ITEMSTACK_ENTITY_TOOLTIP = REGISTRY.register(OperatorBuilders.ENTITY_1_ITEMSTACK_1
14✔
2081
            .inputTypes(ValueTypes.OBJECT_ENTITY, ValueTypes.OBJECT_ITEMSTACK)
2✔
2082
            .output(ValueTypes.LIST).symbol("entity_item_tooltip").operatorName("entityitemtooltip").interactName("entityItemTooltip")
8✔
2083
            .function(variables -> {
1✔
2084
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2085
                ValueObjectTypeItemStack.ValueItemStack itemStack = variables.getValue(1, ValueTypes.OBJECT_ITEMSTACK);
×
2086
                if(a.getRawValue().isPresent() && a.getRawValue().get() instanceof Player) {
×
2087
                    Player entity = (Player) a.getRawValue().get();
×
2088
                    return ValueTypeList.ValueList.ofList(ValueTypes.STRING,
×
2089
                            itemStack.getRawValue().getTooltipLines(Item.TooltipContext.of(entity.level()), entity, TooltipFlag.Default.NORMAL).stream()
×
2090
                                    .map(c -> ValueTypeString.ValueString.of(c.getString()))
×
2091
                                    .toList());
×
2092
                }
2093
                return ValueTypes.LIST.getDefault();
×
2094
            }).build());
1✔
2095

2096
    /**
2097
     * ----------------------------------- ENTITY OBJECT OPERATORS -----------------------------------
2098
     */
2099

2100
    /**
2101
     * If the entity is a mob
2102
     */
2103
    public static final IOperator OBJECT_ENTITY_ISMOB = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2104
            .output(ValueTypes.BOOLEAN).symbol("is_mob").operatorName("ismob").interactName("isMob")
9✔
2105
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2106
                entity -> entity instanceof Enemy
4✔
2107
            )).build());
1✔
2108

2109
    /**
2110
     * If the entity is an animal
2111
     */
2112
    public static final IOperator OBJECT_ENTITY_ISANIMAL = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2113
            .output(ValueTypes.BOOLEAN).symbol("is_animal").operatorName("isanimal").interactName("isAnimal")
9✔
2114
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2115
                entity -> entity instanceof Animal && !(entity instanceof Enemy)
11!
2116
            )).build());
1✔
2117

2118
    /**
2119
     * If the entity is an item
2120
     */
2121
    public static final IOperator OBJECT_ENTITY_ISITEM = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2122
            .output(ValueTypes.BOOLEAN).symbol("is_item").operatorName("isitem").interactName("isItem")
9✔
2123
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2124
                entity -> entity instanceof ItemEntity
4✔
2125
            )).build());
1✔
2126

2127
    /**
2128
     * If the entity is a player
2129
     */
2130
    public static final IOperator OBJECT_ENTITY_ISPLAYER = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2131
            .output(ValueTypes.BOOLEAN).symbol("is_player").operatorName("isplayer").interactName("isPlayer")
9✔
2132
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2133
                entity -> entity instanceof Player
4✔
2134
            )).build());
1✔
2135

2136
    /**
2137
     * If the entity is a minecart
2138
     */
2139
    public static final IOperator OBJECT_ENTITY_ISMINECART = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2140
            .output(ValueTypes.BOOLEAN).symbol("is_minecart").operatorName("isminecart").interactName("isMinecart")
9✔
2141
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2142
                entity -> entity instanceof AbstractMinecart
×
2143
            )).build());
1✔
2144

2145
    /**
2146
     * The itemstack from the entity
2147
     */
2148
    public static final IOperator OBJECT_ENTITY_ITEMSTACK = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX
5✔
2149
            .output(ValueTypes.OBJECT_ITEMSTACK).symbolOperatorInteract("item")
4✔
2150
            .function(variables -> {
1✔
2151
                ValueObjectTypeEntity.ValueEntity valueEntity = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2152
                Optional<Entity> a = valueEntity.getRawValue();
3✔
2153
                return ValueObjectTypeItemStack.ValueItemStack.of((a.isPresent() && a.get() instanceof ItemEntity) ? ((ItemEntity) a.get()).getItem() : ItemStack.EMPTY);
15!
2154
            }).build());
1✔
2155

2156
    /**
2157
     * The entity health
2158
     */
2159
    public static final IOperator OBJECT_ENTITY_HEALTH = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2160
            .output(ValueTypes.DOUBLE).symbolOperatorInteract("health")
5✔
2161
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_DOUBLE.build(
2✔
2162
                entity -> entity instanceof LivingEntity ? ((LivingEntity) entity).getHealth() : 0.0
11✔
2163
            )).build());
1✔
2164

2165
    /**
2166
     * The entity width
2167
     */
2168
    public static final IOperator OBJECT_ENTITY_WIDTH = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2169
            .output(ValueTypes.DOUBLE).symbolOperatorInteract("width")
5✔
2170
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_DOUBLE.build(
2✔
2171
                entity -> entity != null ? entity.getBbWidth() : 0.0
8!
2172
            )).build());
1✔
2173

2174
    /**
2175
     * The entity width
2176
     */
2177
    public static final IOperator OBJECT_ENTITY_HEIGHT = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2178
            .output(ValueTypes.DOUBLE).symbolOperatorInteract("height")
5✔
2179
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_DOUBLE.build(
2✔
2180
                entity -> entity != null ? entity.getBbHeight() : 0.0
8!
2181
            )).build());
1✔
2182

2183
    /**
2184
     * If the entity is burning
2185
     */
2186
    public static final IOperator OBJECT_ENTITY_ISBURNING = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2187
            .output(ValueTypes.BOOLEAN).symbol("is_burning").operatorName("isburning").interactName("entityIsBurning")
9✔
2188
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2189
                entity -> entity != null && entity.isOnFire()
10!
2190
            )).build());
1✔
2191

2192
    /**
2193
     * If the entity is wet
2194
     */
2195
    public static final IOperator OBJECT_ENTITY_ISWET = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2196
            .output(ValueTypes.BOOLEAN).symbol("is_wet").operatorName("iswet").interactName("isWet")
9✔
2197
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2198
                entity -> entity != null && entity.isInWaterOrRain()
10!
2199
            )).build());
1✔
2200

2201
    /**
2202
     * If the entity is crouching
2203
     */
2204
    public static final IOperator OBJECT_ENTITY_ISCROUCHING = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2205
            .output(ValueTypes.BOOLEAN).symbol("is_crouching").operatorName("iscrouching").interactName("isCrouching")
9✔
2206
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2207
                entity -> entity != null && entity.isCrouching()
10!
2208
            )).build());
1✔
2209

2210
    /**
2211
     * If the entity is eating
2212
     */
2213
    public static final IOperator OBJECT_ENTITY_ISEATING = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2214
            .output(ValueTypes.BOOLEAN).symbol("is_eating").operatorName("iseating").interactName("isEating")
9✔
2215
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2216
                entity -> entity instanceof LivingEntity && ((LivingEntity) entity).getUseItemRemainingTicks() > 0
12!
2217
            )).build());
1✔
2218

2219
    /**
2220
     * The list of armor itemstacks from an entity
2221
     */
2222
    public static final IOperator OBJECT_ENTITY_ARMORINVENTORY = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2223
            .output(ValueTypes.LIST).symbol("armor_inventory").operatorName("armorinventory").interactName("armorInventory")
8✔
2224
            .function(variables -> {
1✔
2225
                ValueObjectTypeEntity.ValueEntity valueEntity = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2226
                Optional<Entity> a = valueEntity.getRawValue();
×
2227
                if(a.isPresent()) {
×
2228
                    Entity entity = a.get();
×
2229
                    return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyEntityArmorInventory(entity.level(), entity));
×
2230
                } else {
2231
                    return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_ITEMSTACK, Collections.<ValueObjectTypeItemStack.ValueItemStack>emptyList());
×
2232
                }
2233
            }).build());
1✔
2234

2235
    /**
2236
     * The list of itemstacks from an entity
2237
     */
2238
    public static final IOperator OBJECT_ENTITY_INVENTORY = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2239
            .output(ValueTypes.LIST).symbolOperator("inventory").interactName("inventory")
6✔
2240
            .function(variables -> {
1✔
2241
                ValueObjectTypeEntity.ValueEntity valueEntity = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2242
                Optional<Entity> a = valueEntity.getRawValue();
×
2243
                if(a.isPresent()) {
×
2244
                    Entity entity = a.get();
×
2245
                    return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyEntityInventory(entity.level(), entity));
×
2246
                } else {
2247
                    return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_ITEMSTACK, Collections.<ValueObjectTypeItemStack.ValueItemStack>emptyList());
×
2248
                }
2249
            }).build());
1✔
2250

2251
    /**
2252
     * The name of the mod owning this entity
2253
     */
2254
    public static final IOperator OBJECT_ENTITY_MODNAME = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.STRING)
7✔
2255
            .symbolOperatorInteract("mod")
13✔
2256
            .function(new IterativeFunction(Lists.newArrayList(
3✔
2257
                    (OperatorBase.SafeVariablesGetter variables) -> {
2258
                        ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2259
                        if(a.getRawValue().isPresent()) {
4!
2260
                            Entity entity = a.getRawValue().get();
5✔
2261
                            return BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType());
5✔
2262
                        }
2263
                        return Identifier.parse("");
×
2264
                    },
2265
                    OperatorBuilders.PROPAGATOR_RESOURCELOCATION_MODNAME
2266
            )))
2267
            .build());
1✔
2268

2269
    /**
2270
     * The block the given player is currently looking at.
2271
     */
2272
    public static final IOperator OBJECT_PLAYER_TARGETBLOCK = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.OBJECT_BLOCK)
7✔
2273
            .symbol("target_block").operatorName("targetblock").interactName("targetBlock")
6✔
2274
            .function(variables -> {
1✔
2275
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2276
                BlockState blockState = null;
×
2277
                if(a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
×
2278
                    LivingEntity entity = (LivingEntity) a.getRawValue().get();
×
2279
                    AttributeInstance reachDistanceAttribute = entity.getAttribute(Attributes.BLOCK_INTERACTION_RANGE);
×
2280
                    double reachDistance = reachDistanceAttribute == null ? 5 : reachDistanceAttribute.getValue();
×
2281
                    double eyeHeight = entity.getEyeHeight();
×
2282
                    Vec3 lookVec = entity.getLookAngle();
×
2283
                    Vec3 origin = new Vec3(entity.getX(), entity.getY() + eyeHeight, entity.getZ());
×
2284
                    Vec3 direction = origin.add(lookVec.x * reachDistance, lookVec.y * reachDistance, lookVec.z * reachDistance);
×
2285

2286
                    ClipContext rayTraceContext = new ClipContext(origin, direction, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity);
×
2287
                    BlockHitResult mop = entity.level().clip(rayTraceContext);
×
2288
                    if(mop != null && mop.getType() == HitResult.Type.BLOCK) {
×
2289
                        blockState = entity.level().getBlockState(mop.getBlockPos());
×
2290
                    }
2291
                }
2292
                return ValueObjectTypeBlock.ValueBlock.of(blockState);
×
2293
            }).build());
1✔
2294

2295
    /**
2296
     * The entity the given player is currently looking at.
2297
     */
2298
    public static final IOperator OBJECT_PLAYER_TARGETENTITY = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.OBJECT_ENTITY)
7✔
2299
            .symbol("target_entity").operatorName("targetentity").interactName("targetEntity")
6✔
2300
            .function(variables -> {
1✔
2301
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2302
                Entity entityOut = null;
×
2303
                if(a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
×
2304
                    LivingEntity entity = (LivingEntity) a.getRawValue().get();
×
2305
                    AttributeInstance reachDistanceAttribute = entity.getAttribute(Attributes.ENTITY_INTERACTION_RANGE);
×
2306
                    double reachDistance = reachDistanceAttribute == null ? 5 : reachDistanceAttribute.getValue();
×
2307

2308
                    // Copied and modified from GameRenderer#getMouseOver
2309
                    Vec3 origin = entity.getEyePosition(1.0F);
×
2310
                    double reachDistanceSquared = reachDistance * reachDistance;
×
2311

2312
                    Vec3 lookVec = entity.getViewVector(1.0F);
×
2313
                    Vec3 direction = origin.add(lookVec.x * reachDistance, lookVec.y * reachDistance, lookVec.z * reachDistance);
×
2314
                    AABB boundingBox = entity.getBoundingBox()
×
2315
                            .expandTowards(lookVec.scale(reachDistance))
×
2316
                            .inflate(1.0D, 1.0D, 1.0D);
×
2317
                    EntityHitResult entityraytraceresult = ProjectileUtil.getEntityHitResult(entity, origin, direction,
×
2318
                            boundingBox, e -> !e.isSpectator() && e.isPickable(), reachDistanceSquared);
×
2319
                    if (entityraytraceresult != null) {
×
2320
                        Entity entity1 = entityraytraceresult.getEntity();
×
2321
                        Vec3 vec3d3 = entityraytraceresult.getLocation();
×
2322
                        double distanceSquared = origin.distanceToSqr(vec3d3);
×
2323
                        if (distanceSquared < reachDistanceSquared
×
2324
                                && (entity1 instanceof LivingEntity || entity1 instanceof ItemFrame)) {
2325
                            entityOut = entity1;
×
2326
                        }
2327
                    }
2328
                }
2329
                return ValueObjectTypeEntity.ValueEntity.of(entityOut);
×
2330
            }).build());
1✔
2331

2332
    /**
2333
     * If the given player has an external gui open.
2334
     */
2335
    public static final IOperator OBJECT_PLAYER_HASGUIOPEN = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.BOOLEAN)
7✔
2336
            .symbol("has_gui_open").operatorName("hasguiopen").interactName("hasGuiOpen")
6✔
2337
            .function(variables -> {
1✔
2338
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2339
                if(a.getRawValue().isPresent() && a.getRawValue().get() instanceof Player) {
×
2340
                    Player entity = (Player) a.getRawValue().get();
×
2341
                    return ValueTypeBoolean.ValueBoolean.of(entity.containerMenu != entity.inventoryMenu);
×
2342
                }
2343
                return ValueTypeBoolean.ValueBoolean.of(false);
×
2344
            }).build());
1✔
2345

2346
    /**
2347
     * The item the given entity is currently holding in its main hand.
2348
     */
2349
    public static final IOperator OBJECT_ENTITY_HELDITEM_MAIN = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.OBJECT_ITEMSTACK)
7✔
2350
            .symbol("held_item_1").operatorName("helditem").interactName("heldItem")
6✔
2351
            .function(variables -> {
1✔
2352
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2353
                ItemStack itemStack = ItemStack.EMPTY;
2✔
2354
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
9!
2355
                    itemStack = ((LivingEntity) a.getRawValue().get()).getMainHandItem();
6✔
2356
                }
2357
                return ValueObjectTypeItemStack.ValueItemStack.of(itemStack);
3✔
2358
            }).build());
1✔
2359

2360
    /**
2361
     * The item the given entity is currently holding in its off hand.
2362
     */
2363
    public static final IOperator OBJECT_ENTITY_HELDITEM_OFF = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.OBJECT_ITEMSTACK)
7✔
2364
            .symbol("held_item_2").operatorName("helditemoffhand").interactName("heldItemOffHand")
6✔
2365
            .function(variables -> {
1✔
2366
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2367
                ItemStack itemStack = ItemStack.EMPTY;
2✔
2368
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
9!
2369
                    itemStack = ((LivingEntity) a.getRawValue().get()).getOffhandItem();
6✔
2370
                }
2371
                return ValueObjectTypeItemStack.ValueItemStack.of(itemStack);
3✔
2372
            }).build());
1✔
2373

2374
    /**
2375
     * The entity's mounted entity
2376
     */
2377
    public static final IOperator OBJECT_ENTITY_MOUNTED = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.LIST)
7✔
2378
            .symbolOperator("mounted").interactName("mounted")
4✔
2379
            .function(variables -> {
1✔
2380
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2381
                List<ValueObjectTypeEntity.ValueEntity> passengers = Lists.newArrayList();
2✔
2382
                if(a.getRawValue().isPresent()) {
4!
2383
                    for (Entity passenger : a.getRawValue().get().getPassengers()) {
14✔
2384
                        passengers.add(ValueObjectTypeEntity.ValueEntity.of(passenger));
5✔
2385
                    }
1✔
2386
                }
2387
                return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_ENTITY, passengers);
4✔
2388
            }).build());
1✔
2389

2390
    /**
2391
     * The item frame's contents
2392
     */
2393
    public static final IOperator OBJECT_ITEMFRAME_CONTENTS = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.OBJECT_ITEMSTACK)
7✔
2394
            .symbol("itemframe_contents").operatorName("itemframecontents").interactName("itemFrameContents")
6✔
2395
            .function(variables -> {
1✔
2396
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2397
                ItemStack itemStack = ItemStack.EMPTY;
2✔
2398
                if(a.getRawValue().isPresent() && a.getRawValue().get() instanceof ItemFrame) {
9!
2399
                    itemStack = ((ItemFrame) a.getRawValue().get()).getItem();
6✔
2400
                }
2401
                return ValueObjectTypeItemStack.ValueItemStack.of(itemStack);
3✔
2402
            }).build());
1✔
2403

2404
    /**
2405
     * The item frame's rotation
2406
     */
2407
    public static final IOperator OBJECT_ITEMFRAME_ROTATION = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.INTEGER)
7✔
2408
            .symbol("itemframe_rotation").operatorName("itemframerotation").interactName("itemFrameRotation")
6✔
2409
            .function(variables -> {
1✔
2410
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2411
                Integer rotation = 0;
3✔
2412
                if(a.getRawValue().isPresent() && a.getRawValue().get() instanceof ItemFrame) {
9!
2413
                    rotation = ((ItemFrame) a.getRawValue().get()).getRotation();
7✔
2414
                }
2415
                return ValueTypeInteger.ValueInteger.of(rotation);
4✔
2416
            }).build());
1✔
2417

2418
    /**
2419
     * The hurtsound of this entity.
2420
     */
2421
    public static final IOperator OBJECT_ENTITY_HURTSOUND = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.STRING)
7✔
2422
            .symbolOperator("hurtsound").interactName("hurtSound")
4✔
2423
            .function(variables -> {
1✔
2424
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2425
                String hurtSound = "";
2✔
2426
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
9!
2427
                    String sound = ((LivingEntity) a.getRawValue().get()).getHurtSound(a.getRawValue().get().damageSources().generic()).location().toString();
14✔
2428
                    if (sound != null) {
2!
2429
                        hurtSound = sound;
2✔
2430
                    }
2431
                }
2432
                return ValueTypeString.ValueString.of(hurtSound);
3✔
2433
            }).build());
1✔
2434

2435
    /**
2436
     * The deathsound of this entity.
2437
     */
2438
    public static final IOperator OBJECT_ENTITY_DEATHSOUND = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.STRING)
7✔
2439
            .symbolOperator("deathsound").interactName("deathSound")
4✔
2440
            .function(variables -> {
1✔
2441
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2442
                String hurtSound = "";
2✔
2443
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
9!
2444
                    String sound = ((LivingEntity) a.getRawValue().get()).getDeathSound().location().toString();
8✔
2445
                    if (sound != null) {
2!
2446
                        hurtSound = sound;
2✔
2447
                    }
2448
                }
2449
                return ValueTypeString.ValueString.of(hurtSound);
3✔
2450
            }).build());
1✔
2451

2452
    /**
2453
     * The age of this entity.
2454
     */
2455
    public static final IOperator OBJECT_ENTITY_AGE = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.INTEGER)
7✔
2456
            .symbolOperatorInteract("age")
2✔
2457
            .function(variables -> {
1✔
2458
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2459
                int age = 0;
2✔
2460
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
9!
2461
                    age = ((LivingEntity) a.getRawValue().get()).getNoActionTime();
6✔
2462
                }
2463
                return ValueTypeInteger.ValueInteger.of(age);
3✔
2464
            }).build());
1✔
2465

2466
    /**
2467
     * If the entity is a child.
2468
     */
2469
    public static final IOperator OBJECT_ENTITY_ISCHILD = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.BOOLEAN)
7✔
2470
            .symbol("is_child").operatorName("ischild").interactName("isChild")
6✔
2471
            .function(variables -> {
1✔
2472
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2473
                boolean child = false;
2✔
2474
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
9!
2475
                    child = ((LivingEntity) a.getRawValue().get()).isBaby();
6✔
2476
                }
2477
                return ValueTypeBoolean.ValueBoolean.of(child);
3✔
2478
            }).build());
1✔
2479

2480
    /**
2481
     * If the entity can be bred.
2482
     */
2483
    public static final IOperator OBJECT_ENTITY_CANBREED = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.BOOLEAN)
7✔
2484
            .symbol("canbreed").operatorName("canbreed").interactName("canBreed")
6✔
2485
            .function(variables -> {
1✔
2486
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2487
                boolean canBreed = false;
2✔
2488
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof AgeableMob) {
9!
2489
                    canBreed = ((AgeableMob) a.getRawValue().get()).getAge() == 0;
10✔
2490
                }
2491
                return ValueTypeBoolean.ValueBoolean.of(canBreed);
3✔
2492
            }).build());
1✔
2493

2494
    /**
2495
     * If the entity is in love.
2496
     */
2497
    public static final IOperator OBJECT_ENTITY_ISINLOVE = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.BOOLEAN)
7✔
2498
            .symbol("is_in_love").operatorName("isinlove").interactName("isInLove")
6✔
2499
            .function(variables -> {
1✔
2500
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2501
                boolean inLove = false;
2✔
2502
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof Animal) {
9!
2503
                    inLove = ((Animal) a.getRawValue().get()).isInLove();
6✔
2504
                }
2505
                return ValueTypeBoolean.ValueBoolean.of(inLove);
3✔
2506
            }).build());
1✔
2507

2508
    /**
2509
     * If the entity can be bred with the given item.
2510
     */
2511
    public static final IOperator OBJECT_ENTITY_CANBREEDWITH = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
14✔
2512
            .inputTypes(ValueTypes.OBJECT_ENTITY, ValueTypes.OBJECT_ITEMSTACK)
2✔
2513
            .output(ValueTypes.BOOLEAN)
2✔
2514
            .symbol("can_breed_with").operatorName("canbreedwith").interactName("canBreedWith")
6✔
2515
            .renderPattern(IConfigRenderPattern.INFIX_LONG)
2✔
2516
            .function(variables -> {
1✔
2517
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2518
                ValueObjectTypeItemStack.ValueItemStack b = variables.getValue(1, ValueTypes.OBJECT_ITEMSTACK);
6✔
2519
                boolean canBreedWith = false;
2✔
2520
                if (a.getRawValue().isPresent() && !b.getRawValue().isEmpty() && a.getRawValue().get() instanceof Animal) {
13!
2521
                    canBreedWith = ((Animal) a.getRawValue().get()).isFood(b.getRawValue());
8✔
2522
                }
2523
                return ValueTypeBoolean.ValueBoolean.of(canBreedWith);
3✔
2524
            }).build());
1✔
2525

2526
    /**
2527
     * If the entity is shearable.
2528
     */
2529
    public static final IOperator OBJECT_ENTITY_ISSHEARABLE = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.BOOLEAN)
7✔
2530
            .symbol("is_shearable").operatorName("isshearable").interactName("isShearable")
6✔
2531
            .function(variables -> {
1✔
2532
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2533
                return ValueTypeBoolean.ValueBoolean.of(a.getRawValue().isPresent()
7!
2534
                        && a.getRawValue().get() instanceof IShearable
5✔
2535
                        && ((IShearable) a.getRawValue().get()).isShearable(null, ItemStack.EMPTY, null, null));
12✔
2536
            }).build());
1✔
2537

2538
    /**
2539
     * The entity serialized to NBT.
2540
     */
2541
    public static final IOperator OBJECT_ENTITY_NBT = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2542
            .output(ValueTypes.NBT).symbol("NBT()").operatorInteract("nbt")
6✔
2543
            .function(input -> {
1✔
2544
                ValueObjectTypeEntity.ValueEntity entity = input.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2545
                try {
2546
                    if (entity.getRawValue().isPresent()) {
4!
2547
                        Entity e = entity.getRawValue().get();
5✔
2548
                        try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(e.problemPath(), LOGGER)) {
7✔
2549
                            TagValueOutput valueOutput = TagValueOutput.createWithContext(scopedCollector, e.level().registryAccess());
6✔
2550
                            e.save(valueOutput);
4✔
2551
                            return ValueTypeNbt.ValueNbt.of(valueOutput.buildResult());
6✔
2552
                        }
2553
                    }
2554
                } catch (Exception e) {
×
2555
                    // Catch possible errors during NBT writing
2556
                }
×
2557
                return ValueTypes.NBT.getDefault();
×
2558
            }).build());
1✔
2559

2560
    /**
2561
     * The entity type.
2562
     */
2563
    public static final IOperator OBJECT_ENTITY_TYPE = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2564
            .output(ValueTypes.STRING).symbol("entity_type").operatorName("entitytype").interactName("type")
8✔
2565
            .function(input -> {
1✔
2566
                ValueObjectTypeEntity.ValueEntity entity = input.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2567
                String entityType = "";
2✔
2568
                if (entity.getRawValue().isPresent()) {
4!
2569
                    Entity e = entity.getRawValue().get();
5✔
2570
                    entityType = BuiltInRegistries.ENTITY_TYPE.getKey(e.getType()).toString();
6✔
2571
                }
2572
                return ValueTypeString.ValueString.of(entityType);
3✔
2573
            }).build());
1✔
2574

2575
    /**
2576
     * The entity items.
2577
     */
2578
    public static final IOperator OBJECT_ENTITY_ITEMS = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2579
            .output(ValueTypes.LIST).symbol("entity_items").operatorName("entityitems").interactName("items")
8✔
2580
            .function(input -> {
1✔
2581
                ValueObjectTypeEntity.ValueEntity valueEntity = input.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2582
                Optional<Entity> a = valueEntity.getRawValue();
×
2583
                if(a.isPresent()) {
×
2584
                    Entity entity = a.get();
×
2585
                    return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyEntityItems(entity.level(), entity, null));
×
2586
                } else {
2587
                    return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_ITEMSTACK, Collections.emptyList());
×
2588
                }
2589
            }).build());
1✔
2590

2591
    /**
2592
     * The entity fluids.
2593
     */
2594
    public static final IOperator OBJECT_ENTITY_FLUIDS = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2595
            .output(ValueTypes.LIST).symbol("entity_fluids").operatorName("entityfluids").interactName("fluids")
8✔
2596
            .function(input -> {
1✔
2597
                ValueObjectTypeEntity.ValueEntity valueEntity = input.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2598
                Optional<Entity> a = valueEntity.getRawValue();
×
2599
                if(a.isPresent()) {
×
2600
                    Entity entity = a.get();
×
2601
                    return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyEntityFluids(entity.level(), entity, null));
×
2602
                } else {
2603
                    return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_FLUIDSTACK, Collections.emptyList());
×
2604
                }
2605
            }).build());
1✔
2606

2607
    /**
2608
     * The entity energy stored.
2609
     */
2610
    public static final IOperator OBJECT_ENTITY_ENERGY_STORED = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2611
            .output(ValueTypes.LONG).symbol("entity_stored_energy").operatorName("entityenergystored").interactName("energy")
8✔
2612
            .function(input -> {
1✔
2613
                ValueObjectTypeEntity.ValueEntity valueEntity = input.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2614
                Optional<Entity> a = valueEntity.getRawValue();
×
2615
                if(a.isPresent()) {
×
2616
                    Entity entity = a.get();
×
2617
                    EnergyHandler energyStorage = entity.getCapability(Capabilities.Energy.ENTITY, null);
×
2618
                    return ValueTypeLong.ValueLong.of(energyStorage != null ? energyStorage.getAmountAsLong() : 0);
×
2619
                }
2620
                return ValueTypeLong.ValueLong.of(0);
×
2621
            }).build());
1✔
2622

2623
    /**
2624
     * The entity energy stored.
2625
     */
2626
    public static final IOperator OBJECT_ENTITY_ENERGY_CAPACITY = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2627
            .output(ValueTypes.LONG).symbol("entity_capacity_energy").operatorName("entityenergycapacity").interactName("energyCapacity")
8✔
2628
            .function(input -> {
1✔
2629
                ValueObjectTypeEntity.ValueEntity valueEntity = input.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2630
                Optional<Entity> a = valueEntity.getRawValue();
×
2631
                if(a.isPresent()) {
×
2632
                    Entity entity = a.get();
×
2633
                    EnergyHandler energyStorage = entity.getCapability(Capabilities.Energy.ENTITY, null);
×
2634
                    return ValueTypeLong.ValueLong.of(energyStorage != null ? energyStorage.getCapacityAsLong() : 0);
×
2635
                }
2636
                return ValueTypeLong.ValueLong.of(0);
×
2637
            }).build());
1✔
2638

2639
    /**
2640
     * ----------------------------------- FLUID STACK OBJECT OPERATORS -----------------------------------
2641
     */
2642

2643
    /**
2644
     * The amount of fluid in the fluidstack
2645
     */
2646
    public static final IOperator OBJECT_FLUIDSTACK_AMOUNT = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2647
            .output(ValueTypes.INTEGER).symbolOperatorInteract("amount")
5✔
2648
            .function(OperatorBuilders.FUNCTION_FLUIDSTACK_TO_INT.build(
2✔
2649
                    FluidStack::getAmount
2650
            )).build());
1✔
2651

2652
    /**
2653
     * The block from the fluidstack
2654
     */
2655
    public static final IOperator OBJECT_FLUIDSTACK_BLOCK = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2656
            .output(ValueTypes.OBJECT_BLOCK).symbolOperatorInteract("block")
4✔
2657
            .function(variables -> {
1✔
2658
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2659
                FluidStack a = valueFluidStack.getRawValue();
3✔
2660
                return ValueObjectTypeBlock.ValueBlock.of(!a.isEmpty() ? a.getFluid().getFluidType().getStateForPlacement(null, null, a).createLegacyBlock() : null);
14!
2661
            }).build());
1✔
2662

2663
    /**
2664
     * The fluidstack luminosity
2665
     */
2666
    public static final IOperator OBJECT_FLUIDSTACK_LIGHT_LEVEL = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2667
            .output(ValueTypes.INTEGER).symbolOperator("light_level").interactName("lightLevel")
7✔
2668
            .function(OperatorBuilders.FUNCTION_FLUIDSTACK_TO_INT.build(
2✔
2669
                fluidStack -> fluidStack.getFluid().getFluidType().getLightLevel(fluidStack)
7✔
2670
            )).build());
1✔
2671

2672
    /**
2673
     * The fluidstack density
2674
     */
2675
    public static final IOperator OBJECT_FLUIDSTACK_DENSITY = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2676
            .output(ValueTypes.INTEGER).symbolOperatorInteract("density")
5✔
2677
            .function(OperatorBuilders.FUNCTION_FLUIDSTACK_TO_INT.build(
2✔
2678
                fluidStack -> fluidStack.getFluid().getFluidType().getDensity(fluidStack)
7✔
2679
            )).build());
1✔
2680

2681
    /**
2682
     * The fluidstack temperature
2683
     */
2684
    public static final IOperator OBJECT_FLUIDSTACK_TEMPERATURE = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2685
            .output(ValueTypes.INTEGER).symbolOperatorInteract("temperature")
5✔
2686
            .function(OperatorBuilders.FUNCTION_FLUIDSTACK_TO_INT.build(
2✔
2687
                    fluidStack -> fluidStack.getFluid().getFluidType().getTemperature(fluidStack)
7✔
2688
            )).build());
1✔
2689

2690
    /**
2691
     * The fluidstack viscosity
2692
     */
2693
    public static final IOperator OBJECT_FLUIDSTACK_VISCOSITY = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2694
            .output(ValueTypes.INTEGER).symbolOperatorInteract("viscosity")
5✔
2695
            .function(OperatorBuilders.FUNCTION_FLUIDSTACK_TO_INT.build(
2✔
2696
                fluidStack -> fluidStack.getFluid().getFluidType().getViscosity(fluidStack)
7✔
2697
            )).build());
1✔
2698

2699
    /**
2700
     * If the fluidstack is gaseous
2701
     */
2702
    public static final IOperator OBJECT_FLUIDSTACK_IS_LIGHTER_THAN_AIR = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2703
            .output(ValueTypes.BOOLEAN).symbolOperator("lighter_than_air").interactName("isLighterThanAir")
7✔
2704
            .function(OperatorBuilders.FUNCTION_FLUIDSTACK_TO_BOOLEAN.build(
2✔
2705
                fluidStack -> fluidStack.getFluid().getFluidType().isLighterThanAir()
6✔
2706
            )).build());
1✔
2707

2708
    /**
2709
     * The rarity of the fluidstack
2710
     */
2711
    public static final IOperator OBJECT_FLUIDSTACK_RARITY = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2712
            .output(ValueTypes.STRING).symbolOperatorInteract("rarity")
4✔
2713
            .function(variables -> {
1✔
2714
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2715
                FluidStack a = valueFluidStack.getRawValue();
3✔
2716
                return ValueTypeString.ValueString.of(a.getFluid().getFluidType().getRarity(a).name());
8✔
2717
            }).build());
1✔
2718

2719
    /**
2720
     * The bucket empty sound of the fluidstack
2721
     */
2722
    public static final IOperator OBJECT_FLUIDSTACK_SOUND_BUCKET_EMPTY = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2723
            .output(ValueTypes.STRING).symbolOperator("sound_bucket_empty").interactName("bucketEmptySound")
6✔
2724
            .function(variables -> {
1✔
2725
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2726
                FluidStack a = valueFluidStack.getRawValue();
3✔
2727
                return ValueTypeString.ValueString.of(Optional.ofNullable(a.getFluid().getFluidType().getSound(a, SoundActions.BUCKET_EMPTY))
10✔
2728
                        .map(soundEvent -> soundEvent.location().toString())
6✔
2729
                        .orElse(""));
2✔
2730
            }).build());
1✔
2731

2732
    /**
2733
     * The fluid vaporize sound of the fluidstack
2734
     */
2735
    public static final IOperator OBJECT_FLUIDSTACK_SOUND_FLUID_VAPORIZE = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2736
            .output(ValueTypes.STRING).symbolOperator("sound_fluid_vaporize").interactName("fluidVaporizeSound")
6✔
2737
            .function(variables -> {
1✔
2738
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2739
                FluidStack a = valueFluidStack.getRawValue();
3✔
2740
                return ValueTypeString.ValueString.of(Optional.ofNullable(a.getFluid().getFluidType().getSound(a, SoundActions.FLUID_VAPORIZE))
10✔
2741
                        .map(soundEvent -> soundEvent.location().toString())
6✔
2742
                        .orElse(""));
2✔
2743
            }).build());
1✔
2744

2745
    /**
2746
     * The bucket fill sound of the fluidstack
2747
     */
2748
    public static final IOperator OBJECT_FLUIDSTACK_SOUND_BUCKET_FILL = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2749
            .output(ValueTypes.STRING).symbolOperator("sound_bucket_fill").interactName("bucketFillSound")
6✔
2750
            .function(variables -> {
1✔
2751
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2752
                FluidStack a = valueFluidStack.getRawValue();
3✔
2753
                return ValueTypeString.ValueString.of(Optional.ofNullable(a.getFluid().getFluidType().getSound(a, SoundActions.BUCKET_FILL))
10✔
2754
                        .map(soundEvent -> soundEvent.location().toString())
6✔
2755
                        .orElse(""));
2✔
2756
            }).build());
1✔
2757

2758
    /**
2759
     * The bucket of the fluidstack
2760
     */
2761
    public static final IOperator OBJECT_FLUIDSTACK_BUCKET = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2762
            .output(ValueTypes.OBJECT_ITEMSTACK).symbolOperatorInteract("bucket")
4✔
2763
            .function(variables -> {
1✔
2764
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2765
                FluidStack a = valueFluidStack.getRawValue();
3✔
2766
                return ValueObjectTypeItemStack.ValueItemStack.of(a.getFluid().getFluidType().getBucket(a));
7✔
2767
            }).build());
1✔
2768

2769
    /**
2770
     * If the fluid types of the two given fluidstacks are equal
2771
     */
2772
    public static final IOperator OBJECT_FLUIDSTACK_ISRAWFLUIDEQUAL = REGISTRY.register(OperatorBuilders.FLUIDSTACK_2
5✔
2773
            .output(ValueTypes.BOOLEAN).symbol("=Raw=").operatorName("israwfluidequal").interactName("isRawEqual")
8✔
2774
            .function(variables -> {
1✔
2775
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack0 = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2776
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack1 = variables.getValue(1, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2777
                return ValueTypeBoolean.ValueBoolean.of(FluidStack.isSameFluid(valueFluidStack0.getRawValue(), valueFluidStack1.getRawValue()));
7✔
2778
            }).build());
1✔
2779

2780
    /**
2781
     * The name of the mod owning this fluid
2782
     */
2783
    public static final IOperator OBJECT_FLUIDSTACK_MODNAME = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG.output(ValueTypes.STRING)
7✔
2784
            .symbolOperatorInteract("mod")
13✔
2785
            .function(new IterativeFunction(Lists.newArrayList(
3✔
2786
                    (OperatorBase.SafeVariablesGetter variables) -> {
2787
                        ValueObjectTypeFluidStack.ValueFluidStack a = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2788
                        return BuiltInRegistries.FLUID.getKey(a.getRawValue().getFluid());
6✔
2789
                    },
2790
                    OperatorBuilders.PROPAGATOR_RESOURCELOCATION_MODNAME
2791
            ))).build());
1✔
2792

2793
    /**
2794
     * The tag of the given fluidstack.
2795
     */
2796
    public static final IOperator OBJECT_FLUIDSTACK_DATA = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2797
            .output(ValueTypes.NBT).symbol("NBT()").operatorInteract("nbt")
6✔
2798
            .function(input -> {
1✔
2799
                ValueObjectTypeFluidStack.ValueFluidStack fluidStack = input.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2800
                if (fluidStack.getRawValue().getComponentsPatch().isEmpty()) {
5✔
2801
                    return ValueTypeNbt.ValueNbt.of(Optional.empty());
3✔
2802
                }
2803
                return ValueTypeNbt.ValueNbt.of(DataComponentPatch.CODEC.encodeStart(ServerLifecycleHooks.getCurrentServer().registryAccess().createSerializationContext(NbtOps.INSTANCE), fluidStack.getRawValue().getComponentsPatch()).getOrThrow());
13✔
2804
            }).build());
1✔
2805

2806
    /**
2807
     * Create a new fluidstack with the given amount.
2808
     */
2809
    public static final IOperator OBJECT_FLUIDSTACK_WITH_AMOUNT = REGISTRY.register(OperatorBuilders.FLUIDSTACK_2
14✔
2810
            .inputTypes(ValueTypes.OBJECT_FLUIDSTACK, ValueTypes.INTEGER)
2✔
2811
            .output(ValueTypes.OBJECT_FLUIDSTACK).symbolOperator("with_amount").interactName("withAmount")
6✔
2812
            .function(variables -> {
1✔
2813
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2814
                ValueTypeInteger.ValueInteger valueInteger = variables.getValue(1, ValueTypes.INTEGER);
6✔
2815
                FluidStack fluidStack = valueFluidStack.getRawValue().copy();
4✔
2816
                fluidStack.setAmount(valueInteger.getRawValue());
4✔
2817
                return ValueObjectTypeFluidStack.ValueFluidStack.of(fluidStack);
3✔
2818
            }).build());
1✔
2819

2820
    /**
2821
     * Get the data component keys of an fluidstack.
2822
     */
2823
    public static final IOperator OBJECT_FLUIDSTACK_DATA_KEYS = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2824
            .output(ValueTypes.LIST).symbol("data_keys").operatorName("datakeys").interactName("dataKeys")
8✔
2825
            .function(input -> {
1✔
2826
                ValueObjectTypeFluidStack.ValueFluidStack fluidStack = input.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2827
                // Explicitly check for fluid emptiness first, because vanilla sometimes persists NBT when setting stacks to empty
2828
                return ValueTypeList.ValueList.ofList(ValueTypes.STRING,
3✔
2829
                        fluidStack.getRawValue().isEmpty() ?
4!
2830
                                Lists.newArrayList() :
×
2831
                                fluidStack.getRawValue().getComponents().keySet().stream()
5✔
2832
                                        .filter(c -> !c.isTransient())
8!
2833
                                        .map(c -> ValueTypeString.ValueString.of(BuiltInRegistries.DATA_COMPONENT_TYPE.getKey(c).toString()))
8✔
2834
                                        .sorted((o1, o2) -> o1.getRawValue().compareTo(o2.getRawValue()))
1✔
2835
                                        .toList());
2✔
2836
            }).build());
1✔
2837

2838
    /**
2839
     * Get the data component value by key
2840
     */
2841
    public static final IOperator OBJECT_FLUIDSTACK_DATA_VALUE = REGISTRY.register(OperatorBuilders.FLUIDSTACK_2_LONG
14✔
2842
            .inputTypes(ValueTypes.OBJECT_FLUIDSTACK, ValueTypes.STRING)
2✔
2843
            .output(ValueTypes.NBT).symbol("data_value").operatorName("datavalue").interactName("dataValue")
8✔
2844
            .function(input -> {
1✔
2845
                ValueObjectTypeFluidStack.ValueFluidStack fluidStack = input.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2846

2847
                // Determine data component type
2848
                DataComponentType<?> dataComponentType;
2849
                try {
2850
                    dataComponentType = BuiltInRegistries.DATA_COMPONENT_TYPE.getValue(Identifier.parse(input.getValue(1, ValueTypes.STRING).getRawValue()));
11✔
2851
                } catch (IdentifierException e) {
×
2852
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
2853
                }
1✔
2854

2855
                // Fetch component value
2856
                TypedDataComponent<?> typedComponent = fluidStack.getRawValue().getComponents().getTyped(dataComponentType);
6✔
2857
                if (typedComponent == null) {
2✔
2858
                    return ValueTypeNbt.ValueNbt.of((Tag) null);
4✔
2859
                }
2860

2861
                // Encode component value
2862
                try {
2863
                    Tag tag = typedComponent.encodeValue(ServerLifecycleHooks.getCurrentServer().registryAccess().createSerializationContext(NbtOps.INSTANCE)).getOrThrow();
9✔
2864
                    return ValueTypeNbt.ValueNbt.of(tag);
3✔
2865
                } catch (IllegalStateException e) {
×
2866
                    return ValueTypeNbt.ValueNbt.of((Tag) null);
×
2867
                }
2868
            }).build());
1✔
2869

2870
    /**
2871
     * Set the data component value by key
2872
     */
2873
    public static final IOperator OBJECT_FLUIDSTACK_WITH_DATA = REGISTRY.register(OperatorBuilders.FLUIDSTACK_3
18✔
2874
            .inputTypes(ValueTypes.OBJECT_FLUIDSTACK, ValueTypes.STRING, ValueTypes.NBT)
2✔
2875
            .output(ValueTypes.NBT).symbol("with_data").operatorName("withdata").interactName("withData")
8✔
2876
            .function(input -> {
1✔
2877
                ValueObjectTypeFluidStack.ValueFluidStack fluidStack = input.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2878

2879
                // Skip further processing if input value is empty
2880
                Optional<Tag> tagOptional = input.getValue(2, ValueTypes.NBT).getRawValue();
7✔
2881
                if (!tagOptional.isPresent()) {
3!
2882
                    return fluidStack;
×
2883
                }
2884

2885
                // Determine data component type
2886
                DataComponentType<?> dataComponentType;
2887
                try {
2888
                    dataComponentType = BuiltInRegistries.DATA_COMPONENT_TYPE.getValue(Identifier.parse(input.getValue(1, ValueTypes.STRING).getRawValue()));
11✔
2889
                } catch (IdentifierException e) {
×
2890
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
2891
                }
1✔
2892

2893
                // Encode component value
2894
                try {
2895
                    Object value = dataComponentType.codec().decode(ServerLifecycleHooks.getCurrentServer().registryAccess().createSerializationContext(NbtOps.INSTANCE), tagOptional.get()).getOrThrow().getFirst();
14✔
2896
                    fluidStack = ValueObjectTypeFluidStack.ValueFluidStack.of(fluidStack.getRawValue().copy());
5✔
2897
                    fluidStack.getRawValue().set((DataComponentType) dataComponentType, value);
6✔
2898
                    return fluidStack;
2✔
2899
                } catch (IllegalStateException e) {
×
2900
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
2901
                }
2902
            }).build());
1✔
2903

2904
    /**
2905
     * The tag entries of the given fluidstack
2906
     */
2907
    public static final IOperator OBJECT_FLUIDSTACK_TAG = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2908
            .output(ValueTypes.LIST)
2✔
2909
            .symbol("fluid_tag_names").operatorName("tag").interactName("tags")
6✔
2910
            .function(variables -> {
1✔
2911
                ValueObjectTypeFluidStack.ValueFluidStack a = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2912
                ImmutableList.Builder<ValueTypeString.ValueString> builder = ImmutableList.builder();
2✔
2913
                if(!a.getRawValue().isEmpty()) {
4✔
2914
                    a.getRawValue().getFluid().builtInRegistryHolder().tags()
7✔
2915
                            .forEach(owningTag -> builder.add(ValueTypeString.ValueString
6✔
2916
                                    .of(owningTag.location().toString())));
3✔
2917
                }
2918
                return ValueTypeList.ValueList.ofList(ValueTypes.STRING, builder.build());
5✔
2919
            }).build());
1✔
2920

2921
    /**
2922
     * Get a list of fluidstacks that correspond to the given tag key.
2923
     */
2924
    public static final IOperator OBJECT_FLUIDSTACK_TAG_STACKS = REGISTRY.register(OperatorBuilders.STRING_1_PREFIX
5✔
2925
            .output(ValueTypes.LIST)
2✔
2926
            .symbol("fluid_tag_values").operatorName("fluidtag").interactName("fluidsByTag")
6✔
2927
            .symbol("fluid_tag_values").operatorName("fluidtag").interactName("fluidsByTag")
6✔
2928
            .inputType(ValueTypes.STRING).renderPattern(IConfigRenderPattern.SUFFIX_1_LONG)
4✔
2929
            .function(variables -> {
1✔
2930
                ValueTypeString.ValueString a = variables.getValue(0, ValueTypes.STRING);
6✔
2931
                ImmutableList.Builder<ValueObjectTypeFluidStack.ValueFluidStack> builder = ImmutableList.builder();
2✔
2932
                if (!StringUtil.isNullOrEmpty(a.getRawValue())) {
4!
2933
                    try {
2934
                        Helpers.getFluidTagValues(a.getRawValue())
4✔
2935
                                .map(ValueObjectTypeFluidStack.ValueFluidStack::of)
3✔
2936
                                .forEach(builder::add);
4✔
2937
                    } catch (IdentifierException e) {
×
2938
                        throw new EvaluationException(Component.translatable(e.getMessage()));
×
2939
                    }
1✔
2940
                }
2941
                return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_FLUIDSTACK, builder.build());
5✔
2942
            }).build());
1✔
2943

2944
    /**
2945
     * Get an fluid by name.
2946
     */
2947
    public static final IOperator OBJECT_FLUIDSTACK_BY_NAME = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_PREFIX_LONG
5✔
2948
            .inputType(ValueTypes.STRING).output(ValueTypes.OBJECT_FLUIDSTACK)
4✔
2949
            .symbol("fluid_by_name").operatorName("fluidbyname").interactName("fluidByName")
7✔
2950
            .function(OperatorBuilders.FUNCTION_STRING_TO_RESOURCE_LOCATION
1✔
2951
                    .build(input -> {
1✔
2952
                        Fluid fluid = BuiltInRegistries.FLUID.getValue(input);
5✔
2953
                        FluidStack fluidStack = FluidStack.EMPTY;
2✔
2954
                        if (fluid != null) {
2!
2955
                            fluidStack = new FluidStack(fluid, IModHelpersNeoForge.get().getFluidHelpers().getBucketVolume());
8✔
2956
                        }
2957
                        return ValueObjectTypeFluidStack.ValueFluidStack.of(fluidStack);
3✔
2958
                    })).build());
1✔
2959

2960
    /**
2961
     * ----------------------------------- OPERATOR OPERATORS -----------------------------------
2962
     */
2963

2964
    /**
2965
     * Apply for a given operator a given value.
2966
     */
2967
    public static final IOperator OPERATOR_APPLY = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
5✔
2968
            .conditionalOutputTypeDeriver(OperatorBuilders.OPERATOR_CONDITIONAL_OUTPUT_DERIVER)
2✔
2969
            .output(ValueTypes.CATEGORY_ANY).symbolOperatorInteract("apply")
9✔
2970
            .typeValidator(OperatorBuilders.createOperatorTypeValidator(ValueTypes.CATEGORY_ANY))
4✔
2971
            .function(OperatorBuilders.FUNCTION_OPERATOR_TAKE_OPERATOR.build(
2✔
2972
                    input -> {
2973
                        IOperator innerOperator = input.getLeft();
4✔
2974
                        OperatorBase.SafeVariablesGetter variables = input.getRight();
4✔
2975
                        IVariable variable = variables.getVariables()[0];
5✔
2976
                        return ValueHelpers.evaluateOperator(innerOperator, variable);
9✔
2977
                    })).build());
1✔
2978
    static {
2979
        REGISTRY.registerSerializer(new CurriedOperator.Serializer());
5✔
2980
    }
2981

2982
    /**
2983
     * Apply for a given operator the given 2 values.
2984
     */
2985
    public static final IOperator OPERATOR_APPLY_2 = REGISTRY.register(OperatorBuilders.OPERATOR
5✔
2986
            .renderPattern(IConfigRenderPattern.INFIX_2)
2✔
2987
            .conditionalOutputTypeDeriver(OperatorBuilders.OPERATOR_CONDITIONAL_OUTPUT_DERIVER)
15✔
2988
            .inputTypes(ValueTypes.OPERATOR, ValueTypes.CATEGORY_ANY, ValueTypes.CATEGORY_ANY)
2✔
2989
            .output(ValueTypes.CATEGORY_ANY).symbolOperatorInteract("apply2")
13✔
2990
            .typeValidator(OperatorBuilders.createOperatorTypeValidator(ValueTypes.CATEGORY_ANY, ValueTypes.CATEGORY_ANY))
4✔
2991
            .function(OperatorBuilders.FUNCTION_OPERATOR_TAKE_OPERATOR.build(
2✔
2992
                    input -> {
2993
                        IOperator innerOperator = input.getLeft();
4✔
2994
                        OperatorBase.SafeVariablesGetter variables = input.getRight();
4✔
2995
                        IVariable variable0 = variables.getVariables()[0];
5✔
2996
                        IVariable variable1 = variables.getVariables()[1];
5✔
2997
                        return ValueHelpers.evaluateOperator(innerOperator, variable0, variable1);
13✔
2998
                    })).build());
1✔
2999

3000
    /**
3001
     * Apply for a given operator the given 3 values.
3002
     */
3003
    public static final IOperator OPERATOR_APPLY_3 = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
5✔
3004
            .renderPattern(IConfigRenderPattern.INFIX_3)
2✔
3005
            .conditionalOutputTypeDeriver(OperatorBuilders.OPERATOR_CONDITIONAL_OUTPUT_DERIVER)
19✔
3006
            .inputTypes(ValueTypes.OPERATOR, ValueTypes.CATEGORY_ANY, ValueTypes.CATEGORY_ANY, ValueTypes.CATEGORY_ANY)
2✔
3007
            .output(ValueTypes.CATEGORY_ANY).symbolOperatorInteract("apply3")
17✔
3008
            .typeValidator(OperatorBuilders.createOperatorTypeValidator(ValueTypes.CATEGORY_ANY, ValueTypes.CATEGORY_ANY, ValueTypes.CATEGORY_ANY))
4✔
3009
            .function(OperatorBuilders.FUNCTION_OPERATOR_TAKE_OPERATOR.build(
2✔
3010
                    input -> {
3011
                        IOperator innerOperator = input.getLeft();
4✔
3012
                        OperatorBase.SafeVariablesGetter variables = input.getRight();
4✔
3013
                        IVariable variable0 = variables.getVariables()[0];
5✔
3014
                        IVariable variable1 = variables.getVariables()[1];
5✔
3015
                        IVariable variable2 = variables.getVariables()[2];
5✔
3016
                        return ValueHelpers.evaluateOperator(innerOperator, variable0, variable1, variable2);
17✔
3017
                    })).build());
1✔
3018

3019
    /**
3020
     * Apply for a given operator the given list of values.
3021
     */
3022
    public static final IOperator OPERATOR_APPLY_N = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
5✔
3023
            .conditionalOutputTypeDeriver(OperatorBuilders.OPERATOR_CONDITIONAL_OUTPUT_DERIVER_LIST)
11✔
3024
            .inputTypes(ValueTypes.OPERATOR, ValueTypes.LIST)
2✔
3025
            .output(ValueTypes.CATEGORY_ANY).symbolOperatorInteract("apply_n")
9✔
3026
            .typeValidator(OperatorBuilders.createOperatorTypeValidator(ValueTypes.LIST))
4✔
3027
            .function(OperatorBuilders.FUNCTION_OPERATOR_TAKE_OPERATOR_LIST.build(
2✔
3028
                    input -> {
3029
                        IOperator innerOperator = input.getLeft();
4✔
3030
                        OperatorBase.SafeVariablesGetter variables = input.getRight();
4✔
3031
                        IValueTypeListProxy<IValueType<IValue>, IValue> list = variables.getValue(0, ValueTypes.LIST).getRawValue();
7✔
3032
                        return ValueHelpers.evaluateOperator(innerOperator, Iterables.toArray(list, IValue.class));
7✔
3033
                    })).build());
1✔
3034

3035
    /**
3036
     * Apply for a given operator with zero arguments.
3037
     */
3038
    public static final IOperator OPERATOR_APPLY_0 = REGISTRY.register(OperatorBuilders.OPERATOR_1_PREFIX_LONG
5✔
3039
            .conditionalOutputTypeDeriver(OperatorBuilders.OPERATOR_CONDITIONAL_OUTPUT_DERIVER)
2✔
3040
            .output(ValueTypes.CATEGORY_ANY).symbolOperatorInteract("apply0")
5✔
3041
            .typeValidator(OperatorBuilders.createOperatorTypeValidator(new IValueType[0]))
4✔
3042
            .function(OperatorBuilders.FUNCTION_OPERATOR_TAKE_OPERATOR.build(
2✔
3043
                    input -> {
3044
                        IOperator innerOperator = input.getLeft();
4✔
3045
                        return ValueHelpers.evaluateOperator(innerOperator, new IVariable[0]);
5✔
3046
                    })).build());
1✔
3047

3048
    /**
3049
     * Apply the given operator on all elements of a list, resulting in a new list of mapped values.
3050
     */
3051
    public static final IOperator OPERATOR_MAP = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
14✔
3052
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.LIST})
2✔
3053
            .output(ValueTypes.LIST).symbolOperatorInteract("map")
5✔
3054
            .function(OperatorBuilders.FUNCTION_OPERATOR_TAKE_OPERATOR_LIST.build(
2✔
3055
                    input -> {
3056
                        final IOperator innerOperator = input.getLeft();
4✔
3057
                        OperatorBase.SafeVariablesGetter variables = input.getRight();
4✔
3058
                        ValueTypeList.ValueList inputList = variables.getValue(0, ValueTypes.LIST);
6✔
3059
                        return ValueTypeList.ValueList.ofFactory(
6✔
3060
                                new ValueTypeListProxyOperatorMapped(innerOperator, inputList.getRawValue()));
2✔
3061
                    })).build());
1✔
3062

3063
    /**
3064
     * Filter a list of elements by matching them all with the given predicate.
3065
     */
3066
    public static final IOperator OPERATOR_FILTER = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
14✔
3067
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.LIST})
2✔
3068
            .output(ValueTypes.LIST).symbolOperatorInteract("filter")
7✔
3069
            .function(OperatorBuilders.FUNCTION_OPERATOR_TAKE_OPERATOR_LIST.build(
2✔
3070
                    new IOperatorValuePropagator<Pair<IOperator, OperatorBase.SafeVariablesGetter>, IValue>() {
3✔
3071
                        @Override
3072
                        public IValue getOutput(Pair<IOperator, OperatorBase.SafeVariablesGetter> input) throws EvaluationException {
3073
                            final IOperator innerOperator = input.getLeft();
4✔
3074
                            OperatorBase.SafeVariablesGetter variables = input.getRight();
4✔
3075
                            ValueTypeList.ValueList<?, ?> inputList = variables.getValue(0, ValueTypes.LIST);
6✔
3076
                            List<IValue> filtered = Lists.newArrayList();
2✔
3077
                            for (IValue value : inputList.getRawValue()) {
11✔
3078
                                IValue result = ValueHelpers.evaluateOperator(innerOperator, value);
9✔
3079
                                ValueHelpers.validatePredicateOutput(innerOperator, result);
3✔
3080
                                if (((ValueTypeBoolean.ValueBoolean) result).getRawValue()) {
4✔
3081
                                    filtered.add(value);
4✔
3082
                                }
3083
                            }
1✔
3084
                            IValueType valueType = inputList.getRawValue().getValueType();
4✔
3085
                            return ValueTypeList.ValueList.ofList(valueType, filtered);
4✔
3086
                        }
3087
                    })).build());
1✔
3088

3089
    /**
3090
     * Takes the conjunction of two predicates.
3091
     */
3092
    public static final IOperator OPERATOR_CONJUNCTION = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
14✔
3093
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.OPERATOR})
2✔
3094
            .output(ValueTypes.OPERATOR).symbol(".&&.").operatorInteract("conjunction")
7✔
3095
            .function(OperatorBuilders.FUNCTION_TWO_PREDICATES.build(
2✔
3096
                input -> ValueTypeOperator.ValueOperator.of(CombinedOperator.Conjunction.asOperator(input.getLeft(), input.getRight()))
17✔
3097
            )).build());
1✔
3098
    static {
3099
        REGISTRY.registerSerializer(new CombinedOperator.Conjunction.Serializer());
5✔
3100
    }
3101

3102
    /**
3103
     * Takes the disjunction of two predicates.
3104
     */
3105
    public static final IOperator OPERATOR_DISJUNCTION = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
14✔
3106
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.OPERATOR})
2✔
3107
            .output(ValueTypes.OPERATOR).symbol(".||.").operatorInteract("disjunction")
7✔
3108
            .function(OperatorBuilders.FUNCTION_TWO_PREDICATES.build(
2✔
3109
                input -> ValueTypeOperator.ValueOperator.of(CombinedOperator.Disjunction.asOperator(input.getLeft(), input.getRight()))
17✔
3110
            )).build());
1✔
3111
    static {
3112
        REGISTRY.registerSerializer(new CombinedOperator.Disjunction.Serializer());
5✔
3113
    }
3114

3115
    /**
3116
     * Takes the negation of a predicate.
3117
     */
3118
    public static final IOperator OPERATOR_NEGATION = REGISTRY.register(OperatorBuilders.OPERATOR_1_PREFIX_LONG
5✔
3119
            .renderPattern(IConfigRenderPattern.PREFIX_1)
7✔
3120
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR})
2✔
3121
            .output(ValueTypes.OPERATOR).symbol("!.").operatorInteract("negation")
7✔
3122
            .function(OperatorBuilders.FUNCTION_ONE_PREDICATE.build(
2✔
3123
                input -> ValueTypeOperator.ValueOperator.of(CombinedOperator.Negation.asOperator(input))
4✔
3124
            )).build());
1✔
3125
    static {
3126
        REGISTRY.registerSerializer(new CombinedOperator.Negation.Serializer());
5✔
3127
    }
3128

3129
    /**
3130
     * Create a new operator that pipes the output from the first operator to the second operator.
3131
     */
3132
    public static final IOperator OPERATOR_PIPE = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
14✔
3133
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.OPERATOR})
2✔
3134
            .output(ValueTypes.OPERATOR).symbol(".").operatorInteract("pipe")
7✔
3135
            .function(OperatorBuilders.FUNCTION_TWO_OPERATORS.build(
2✔
3136
                input -> ValueTypeOperator.ValueOperator.of(CombinedOperator.Pipe.asOperator(input.getLeft(), input.getRight()))
17✔
3137
            )).build());
1✔
3138
    static {
3139
        REGISTRY.registerSerializer(new CombinedOperator.Pipe.Serializer());
5✔
3140
    }
3141

3142
    /**
3143
     * Create a new operator that gives its input to the first and second operators, and pipes the outputs from both of them to the third operator.
3144
     */
3145
    public static final IOperator OPERATOR_PIPE2 = REGISTRY.register(OperatorBuilders.OPERATOR
18✔
3146
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.OPERATOR, ValueTypes.OPERATOR})
2✔
3147
            .renderPattern(IConfigRenderPattern.INFIX_2_LATE)
2✔
3148
            .output(ValueTypes.OPERATOR).symbol(".2").operatorInteract("pipe2")
7✔
3149
            .function(OperatorBuilders.FUNCTION_THREE_OPERATORS.build(
2✔
3150
                input -> ValueTypeOperator.ValueOperator.of(CombinedOperator.Pipe2.asOperator(input.getLeft(), input.getMiddle(), input.getRight()))
23✔
3151
            )).build());
1✔
3152
    static {
3153
        REGISTRY.registerSerializer(new CombinedOperator.Pipe2.Serializer());
5✔
3154
    }
3155

3156
    /**
3157
     * Flip the input parameters of an operator with two inputs.
3158
     */
3159
    public static final IOperator OPERATOR_FLIP = REGISTRY.register(OperatorBuilders.OPERATOR_1_PREFIX_LONG
5✔
3160
            .renderPattern(IConfigRenderPattern.PREFIX_1)
7✔
3161
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR})
2✔
3162
            .output(ValueTypes.OPERATOR).symbolOperatorInteract("flip")
5✔
3163
            .function(OperatorBuilders.FUNCTION_ONE_OPERATOR.build(
2✔
3164
                input -> ValueTypeOperator.ValueOperator.of(CombinedOperator.Flip.asOperator(input))
4✔
3165
            )).build());
1✔
3166
    static {
3167
        REGISTRY.registerSerializer(new CombinedOperator.Flip.Serializer());
5✔
3168
    }
3169

3170
    /**
3171
     * Apply the given operator on all elements of a list to reduce the list to one value.
3172
     */
3173
    public static final IOperator OPERATOR_REDUCE = REGISTRY.register(OperatorBuilders.OPERATOR
18✔
3174
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.LIST, ValueTypes.CATEGORY_ANY})
2✔
3175
            .renderPattern(IConfigRenderPattern.PREFIX_3_LONG)
2✔
3176
            .output(ValueTypes.CATEGORY_ANY).symbolOperatorInteract("reduce")
4✔
3177
            .conditionalOutputTypeDeriver((operator, input) -> input[2].getType())
9✔
3178
            .function(new OperatorBase.IFunction() {
4✔
3179
                @Override
3180
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
3181
                    IValue accumulator = variables.getValue(2);
4✔
3182
                    final IOperator innerOperator = OperatorBuilders.getSafeOperator(
5✔
3183
                            variables.getValue(0, ValueTypes.OPERATOR), accumulator.getType());
4✔
3184
                    ValueTypeList.ValueList<IValueType<IValue>, IValue> inputList = variables.getValue(1, ValueTypes.LIST);
6✔
3185
                    if (inputList.getRawValue().isInfinite()) {
4!
3186
                        throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_INFINITELIST_ILLEGAL,
×
3187
                                OPERATOR_REDUCE.getLocalizedNameFull()));
×
3188
                    }
3189
                    for (IValue listValue : inputList.getRawValue()) {
11✔
3190
                        accumulator = ValueHelpers.evaluateOperator(innerOperator, accumulator, listValue);
13✔
3191
                    }
1✔
3192
                    return accumulator;
2✔
3193
                }
3194
            }).build());
1✔
3195

3196
    /**
3197
     * Apply the given operator on all elements of a list to reduce the list to one value.
3198
     */
3199
    public static final IOperator OPERATOR_REDUCE1 = REGISTRY.register(OperatorBuilders.OPERATOR
14✔
3200
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.LIST})
2✔
3201
            .renderPattern(IConfigRenderPattern.PREFIX_2_LONG)
2✔
3202
            .output(ValueTypes.CATEGORY_ANY).symbolOperatorInteract("reduce1")
4✔
3203
            .conditionalOutputTypeDeriver((operator, input) -> {
4✔
3204
                try {
3205
                    IValueTypeListProxy a = ((ValueTypeList.ValueList) input[1].getValue()).getRawValue();
7✔
3206
                    return a.getValueType();
3✔
3207
                } catch (EvaluationException e) {
×
3208
                    return operator.getOutputType();
×
3209
                }
3210
            })
3211
            .function(new OperatorBase.IFunction() {
4✔
3212
                @Override
3213
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
3214
                    ValueTypeList.ValueList valueList = variables.getValue(1, ValueTypes.LIST);
6✔
3215
                    if (valueList.getRawValue().isInfinite()) {
4!
3216
                        throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_INFINITELIST_ILLEGAL,
×
3217
                                OPERATOR_REDUCE1.getLocalizedNameFull()));
×
3218
                    }
3219
                    Iterator<IValue> iter = valueList.getRawValue().iterator();
4✔
3220
                    if (!iter.hasNext()) {
3✔
3221
                        throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_REDUCE_EMPTY));
6✔
3222
                    }
3223

3224
                    IValue accumulator = iter.next();
4✔
3225
                    final IOperator innerOperator = OperatorBuilders.getSafeOperator(
5✔
3226
                            variables.getValue(0, ValueTypes.OPERATOR), accumulator.getType());
4✔
3227

3228
                    while (iter.hasNext()) {
3✔
3229
                        IValue listValue = iter.next();
4✔
3230
                        accumulator = ValueHelpers.evaluateOperator(innerOperator, accumulator, listValue);
13✔
3231
                    }
1✔
3232
                    return accumulator;
2✔
3233
                }
3234
            }).build());
1✔
3235

3236
    /**
3237
     * Apply for a given operator a given value.
3238
     */
3239
    public static final IOperator OPERATOR_BY_NAME = REGISTRY.register(OperatorBuilders.OPERATOR_1_PREFIX_LONG
5✔
3240
            .inputType(ValueTypes.STRING).output(ValueTypes.OPERATOR)
4✔
3241
            .symbol("op_by_name").operatorName("by_name").interactName("operatorByName")
6✔
3242
            .function(input -> {
1✔
3243
                ValueTypeString.ValueString name = input.getValue(0, ValueTypes.STRING);
6✔
3244
                try {
3245
                    Identifier id = Identifier.parse(name.getRawValue());
4✔
3246
                    IOperator operator = Operators.REGISTRY.getOperator(id);
4✔
3247
                    if (operator == null) {
2✔
3248
                        throw new EvaluationException(Component.translatable(
11✔
3249
                                L10NValues.OPERATOR_ERROR_OPERATORNOTFOUND, name.getRawValue()));
2✔
3250
                    }
3251
                    return ValueTypeOperator.ValueOperator.of(operator);
3✔
3252
                } catch (IdentifierException e) {
×
3253
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
3254
                }
3255
            }).build());
1✔
3256

3257
    /**
3258
     * ----------------------------------- NBT OPERATORS -----------------------------------
3259
     */
3260

3261
    /**
3262
     * The number of entries in an NBT tag
3263
     */
3264
    public static final IOperator NBT_COMPOUND_SIZE = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3265
            .output(ValueTypes.INTEGER).operatorName("compound_size").symbol("NBT{}.size").interactName("size")
9✔
3266
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_TO_INT.build(
2✔
3267
                opt -> opt.map(CompoundTag::size).orElse(0)
8✔
3268
            )).build());
1✔
3269

3270
    /**
3271
     * The list of keys in an NBT tag
3272
     */
3273
    public static final IOperator NBT_COMPOUND_KEYS = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3274
            .output(ValueTypes.LIST).operatorName("compound_keys").symbol("NBT{}.keys").interactName("keys")
8✔
3275
            .function(variables -> {
1✔
3276
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3277
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtKeys(value.getRawValue()));
7✔
3278
            }).build());
1✔
3279

3280
    /**
3281
     * If an NBT tag has the given key
3282
     */
3283
    public static final IOperator NBT_COMPOUND_HASKEY = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3284
            .output(ValueTypes.BOOLEAN).operatorName("compound_haskey").symbol("NBT{}.has_key").interactName("hasKey")
9✔
3285
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_BOOLEAN.build(
2✔
3286
                    Optional::isPresent
3287
            )).build());
1✔
3288

3289
    /**
3290
     * The NBT value type of an entry
3291
     */
3292
    public static final IOperator NBT_COMPOUND_VALUE_TYPE = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3293
            .output(ValueTypes.STRING).operatorName("compound_type").symbol("NBT{}.type").interactName("type")
9✔
3294
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_STRING.build(tag -> {
2✔
3295
                if (tag.isPresent()) {
3✔
3296
                    try {
3297
                        return TagTypes.getType(tag.get().getId()).getName();
7✔
3298
                    } catch (IndexOutOfBoundsException e) {
×
3299

3300
                    }
3301
                }
3302
                return "null";
2✔
3303
            })).build());
1✔
3304

3305
    /**
3306
     * The NBT tag value
3307
     */
3308
    public static final IOperator NBT_COMPOUND_VALUE_TAG = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3309
            .output(ValueTypes.NBT).operatorName("compound_value_tag").symbol("NBT{}.get_tag").interactName("getTag")
9✔
3310
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_NBT.build(o -> o)).build());
5✔
3311

3312
    /**
3313
     * The NBT boolean value
3314
     */
3315
    public static final IOperator NBT_COMPOUND_VALUE_BOOLEAN = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3316
            .output(ValueTypes.BOOLEAN).operatorName("compound_value_boolean").symbol("NBT{}.get_boolean").interactName("getBoolean")
9✔
3317
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_BOOLEAN.build(
2✔
3318
                    o -> o.flatMap(Tag::asBoolean).orElse(false)
8✔
3319
            )).build());
1✔
3320

3321
    /**
3322
     * The NBT integer value
3323
     */
3324
    public static final IOperator NBT_COMPOUND_VALUE_INTEGER = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3325
            .output(ValueTypes.INTEGER).operatorName("compound_value_integer").symbol("NBT{}.get_integer").interactName("getInteger")
9✔
3326
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_INT.build(
2✔
3327
                    o -> o.flatMap(Tag::asInt).orElse(0)
8✔
3328
            )).build());
1✔
3329

3330
    /**
3331
     * The NBT long value
3332
     */
3333
    public static final IOperator NBT_COMPOUND_VALUE_LONG = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3334
            .output(ValueTypes.LONG).operatorName("compound_value_long").symbol("NBT{}.get_long").interactName("getLong")
9✔
3335
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_LONG.build(
2✔
3336
                    o -> o.flatMap(Tag::asLong).orElse(0L)
8✔
3337
            )).build());
1✔
3338

3339
    /**
3340
     * The NBT double value
3341
     */
3342
    public static final IOperator NBT_COMPOUND_VALUE_DOUBLE = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3343
            .output(ValueTypes.DOUBLE).operatorName("compound_value_double").symbol("NBT{}.get_double").interactName("getDouble")
9✔
3344
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_DOUBLE.build(
2✔
3345
                    o -> o.flatMap(Tag::asDouble).orElse(0D)
8✔
3346
            )).build());
1✔
3347

3348
    /**
3349
     * The NBT string value
3350
     */
3351
    public static final IOperator NBT_COMPOUND_VALUE_STRING = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3352
            .output(ValueTypes.STRING).operatorName("compound_value_string").symbol("NBT{}.get_string").interactName("getString")
9✔
3353
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_STRING.build(
2✔
3354
                    o -> o.flatMap(Tag::asString).orElse("")
7✔
3355
            )).build());
1✔
3356

3357
    /**
3358
     * The NBT compound value
3359
     */
3360
    public static final IOperator NBT_COMPOUND_VALUE_COMPOUND = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3361
            .output(ValueTypes.NBT).operatorName("compound_value_compound").symbol("NBT{}.get_compound").interactName("getCompound")
9✔
3362
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_NBT.build(
2✔
3363
                    o -> o.map(tag -> tag instanceof CompoundTag ? (CompoundTag) tag : new CompoundTag())
11!
3364
            )).build());
1✔
3365

3366
    /**
3367
     * The NBT tag list value
3368
     */
3369
    public static final IOperator NBT_COMPOUND_VALUE_LIST_TAG = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3370
            .output(ValueTypes.LIST).operatorName("compound_value_list_tag").symbol("NBT{}.get_list_tag").interactName("getListTag")
8✔
3371
            .function(variables -> {
1✔
3372
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3373
                ValueTypeString.ValueString key = variables.getValue(1, ValueTypes.STRING);
6✔
3374
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtValueListTag(key.getRawValue(), value.getRawValue()));
9✔
3375
            }).build());
1✔
3376

3377
    /**
3378
     * The NBT boolean list value
3379
     */
3380
    public static final IOperator NBT_COMPOUND_VALUE_LIST_BYTE = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3381
            .output(ValueTypes.LIST).operatorName("compound_value_list_byte").symbol("NBT{}.get_list_byte").interactName("getListByte")
8✔
3382
            .function(variables -> {
1✔
3383
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3384
                ValueTypeString.ValueString key = variables.getValue(1, ValueTypes.STRING);
6✔
3385
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtValueListByte(key.getRawValue(), value.getRawValue()));
9✔
3386
            }).build());
1✔
3387

3388
    /**
3389
     * The NBT int list value
3390
     */
3391
    public static final IOperator NBT_COMPOUND_VALUE_LIST_INT = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3392
            .output(ValueTypes.LIST).operatorName("compound_value_list_int").symbol("NBT{}.get_list_int").interactName("getListInt")
8✔
3393
            .function(variables -> {
1✔
3394
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3395
                ValueTypeString.ValueString key = variables.getValue(1, ValueTypes.STRING);
6✔
3396
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtValueListInt(key.getRawValue(), value.getRawValue()));
9✔
3397
            }).build());
1✔
3398

3399
    /**
3400
     * The NBT long list value
3401
     */
3402
    public static final IOperator NBT_COMPOUND_VALUE_LIST_LONG = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3403
            .output(ValueTypes.LIST).operatorName("compound_value_list_long").symbol("NBT{}.get_list_long").interactName("getListLong")
8✔
3404
            .function(variables -> {
1✔
3405
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3406
                ValueTypeString.ValueString key = variables.getValue(1, ValueTypes.STRING);
6✔
3407
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtValueListLong(key.getRawValue(), value.getRawValue()));
9✔
3408
            }).build());
1✔
3409

3410
    /**
3411
     * Remove an entry from an NBT compound
3412
     */
3413
    public static final IOperator NBT_COMPOUND_WITHOUT = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3414
            .output(ValueTypes.NBT).operatorName("compound_without").symbol("NBT{}.without").interactName("without")
8✔
3415
            .function(variables -> {
1✔
3416
                ValueTypeNbt.ValueNbt valueNbt = variables.getValue(0, ValueTypes.NBT);
6✔
3417
                Optional<Tag> tag = valueNbt.getRawValue();
3✔
3418
                if (tag.isPresent()) {
3!
3419
                    if (!(tag.get() instanceof CompoundTag)) {
4!
3420
                        return ValueTypeNbt.ValueNbt.of();
×
3421
                    }
3422
                    ValueTypeString.ValueString valueString = variables.getValue(1, ValueTypes.STRING);
6✔
3423
                    String key = valueString.getRawValue();
3✔
3424
                    CompoundTag tagCompound = (CompoundTag) tag.get();
4✔
3425
                    if (tagCompound.contains(key)) {
4!
3426
                        // Copy the tag to ensure immutability
3427
                        tagCompound = tagCompound.copy();
3✔
3428
                        tagCompound.remove(key);
4✔
3429
                    }
3430
                    return ValueTypeNbt.ValueNbt.of(tagCompound);
3✔
3431
                }
3432
                return valueNbt;
×
3433
            }).build());
1✔
3434

3435

3436

3437
    /**
3438
     * Set an NBT compound boolean value
3439
     */
3440
    public static final IOperator NBT_COMPOUND_WITH_BOOLEAN = REGISTRY.register(OperatorBuilders.NBT_3
5✔
3441
            .renderPattern(IConfigRenderPattern.INFIX_2_VERYLONG)
15✔
3442
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.BOOLEAN)
2✔
3443
            .operatorName("compound_with_boolean").symbol("NBT{}.with_boolean").interactName("withBoolean")
7✔
3444
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3445
                ValueTypeBoolean.ValueBoolean value = input.getRight().getValue(0, ValueTypes.BOOLEAN);
8✔
3446
                input.getLeft().ifPresent(tag -> tag.putBoolean(input.getMiddle(), value.getRawValue()));
15✔
3447
                return input.getLeft();
4✔
3448
            })).build());
1✔
3449

3450
    /**
3451
     * Set an NBT compound short value
3452
     */
3453
    public static final IOperator NBT_COMPOUND_WITH_SHORT = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3454
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.INTEGER)
2✔
3455
            .operatorName("compound_with_short").symbol("NBT{}.with_short").interactName("withShort")
7✔
3456
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3457
                ValueTypeInteger.ValueInteger value = input.getRight().getValue(0, ValueTypes.INTEGER);
8✔
3458
                input.getLeft().ifPresent(tag -> tag.putShort(input.getMiddle(), (short) value.getRawValue()));
16✔
3459
                return input.getLeft();
4✔
3460
            })).build());
1✔
3461

3462
    /**
3463
     * Set an NBT compound integer value
3464
     */
3465
    public static final IOperator NBT_COMPOUND_WITH_INTEGER = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3466
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.INTEGER)
2✔
3467
            .operatorName("compound_with_integer").symbol("NBT{}.with_integer").interactName("withInteger")
7✔
3468
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3469
                ValueTypeInteger.ValueInteger value = input.getRight().getValue(0, ValueTypes.INTEGER);
8✔
3470
                input.getLeft().ifPresent(tag -> tag.putInt(input.getMiddle(), value.getRawValue()));
15✔
3471
                return input.getLeft();
4✔
3472
            })).build());
1✔
3473

3474
    /**
3475
     * Set an NBT compound long value
3476
     */
3477
    public static final IOperator NBT_COMPOUND_WITH_LONG = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3478
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.LONG)
2✔
3479
            .operatorName("compound_with_long").symbol("NBT{}.with_long").interactName("withLong")
7✔
3480
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3481
                ValueTypeLong.ValueLong value = input.getRight().getValue(0, ValueTypes.LONG);
8✔
3482
                input.getLeft().ifPresent(tag -> tag.putLong(input.getMiddle(), value.getRawValue()));
15✔
3483
                return input.getLeft();
4✔
3484
            })).build());
1✔
3485

3486
    /**
3487
     * Set an NBT compound double value
3488
     */
3489
    public static final IOperator NBT_COMPOUND_WITH_DOUBLE = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3490
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.DOUBLE)
2✔
3491
            .operatorName("compound_with_double").symbol("NBT{}.with_double").interactName("withDouble")
7✔
3492
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3493
                ValueTypeDouble.ValueDouble value = input.getRight().getValue(0, ValueTypes.DOUBLE);
8✔
3494
                input.getLeft().ifPresent(tag -> tag.putDouble(input.getMiddle(), value.getRawValue()));
15✔
3495
                return input.getLeft();
4✔
3496
            })).build());
1✔
3497

3498
    /**
3499
     * Set an NBT compound float value
3500
     */
3501
    public static final IOperator NBT_COMPOUND_WITH_FLOAT = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3502
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.DOUBLE)
2✔
3503
            .operatorName("compound_with_float").symbol("NBT{}.with_float").interactName("withFloat")
7✔
3504
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3505
                ValueTypeDouble.ValueDouble value = input.getRight().getValue(0, ValueTypes.DOUBLE);
8✔
3506
                input.getLeft().ifPresent(tag -> tag.putFloat(input.getMiddle(), (float) value.getRawValue()));
16✔
3507
                return input.getLeft();
4✔
3508
            })).build());
1✔
3509

3510
    /**
3511
     * Set an NBT compound string value
3512
     */
3513
    public static final IOperator NBT_COMPOUND_WITH_STRING = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3514
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.STRING)
2✔
3515
            .operatorName("compound_with_string").symbol("NBT{}.with_string").interactName("withString")
7✔
3516
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3517
                ValueTypeString.ValueString value = input.getRight().getValue(0, ValueTypes.STRING);
8✔
3518
                input.getLeft().ifPresent(tag -> tag.putString(input.getMiddle(), value.getRawValue()));
15✔
3519
                return input.getLeft();
4✔
3520
            })).build());
1✔
3521

3522
    /**
3523
     * Set an NBT compound compound value
3524
     */
3525
    public static final IOperator NBT_COMPOUND_WITH_COMPOUND = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3526
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.NBT)
2✔
3527
            .operatorName("compound_with_tag").symbol("NBT{}.with_tag").interactName("withTag")
7✔
3528
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3529
                ValueTypeNbt.ValueNbt value = input.getRight().getValue(0, ValueTypes.NBT);
8✔
3530
                input.getLeft()
6✔
3531
                        .ifPresent(tag -> value.getRawValue()
7✔
3532
                                .ifPresent(v -> tag.put(input.getMiddle(), v)));
9✔
3533
                return input.getLeft();
4✔
3534
            })).build());
1✔
3535

3536
    /**
3537
     * Set an NBT compound tag list value
3538
     */
3539
    public static final IOperator NBT_COMPOUND_WITH_LIST_TAG = REGISTRY.register(OperatorBuilders.NBT_3
5✔
3540
            .renderPattern(IConfigRenderPattern.INFIX_2_VERYLONG)
15✔
3541
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.LIST)
2✔
3542
            .operatorName("compound_with_list_tag").symbol("NBT{}.with_tag_list").interactName("withTagList")
9✔
3543
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(new IOperatorValuePropagator<Triple<Optional<CompoundTag>, String, OperatorBase.SafeVariablesGetter>, Optional<CompoundTag>>() {
5✔
3544
                @Override
3545
                public Optional<CompoundTag> getOutput(Triple<Optional<CompoundTag>, String, OperatorBase.SafeVariablesGetter> input) throws EvaluationException {
3546
                    ValueTypeList.ValueList<?, ?> value = input.getRight().getValue(0, ValueTypes.LIST);
8✔
3547
                    input.getLeft().ifPresent(tag -> tag.put(input.getMiddle(),
16✔
3548
                            NbtHelpers.getListNbtTag(value, NBT_COMPOUND_WITH_LIST_TAG.getLocalizedNameFull())));
2✔
3549
                    return input.getLeft();
4✔
3550
                }
3551
            })).build());
1✔
3552

3553
    /**
3554
     * Set an NBT compound byte list value
3555
     */
3556
    public static final IOperator NBT_COMPOUND_WITH_LIST_BYTE = REGISTRY.register(OperatorBuilders.NBT_3
5✔
3557
            .renderPattern(IConfigRenderPattern.INFIX_2_VERYLONG)
15✔
3558
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.LIST)
2✔
3559
            .operatorName("compound_with_list_byte").symbol("NBT{}.with_byte_list").interactName("withByteList")
9✔
3560
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(new IOperatorValuePropagator<Triple<Optional<CompoundTag>, String, OperatorBase.SafeVariablesGetter>, Optional<CompoundTag>>() {
5✔
3561
                @Override
3562
                public Optional<CompoundTag> getOutput(Triple<Optional<CompoundTag>, String, OperatorBase.SafeVariablesGetter> input) throws EvaluationException {
3563
                    ValueTypeList.ValueList<?, ?> value = input.getRight().getValue(0, ValueTypes.LIST);
8✔
3564
                    input.getLeft().ifPresent(tag -> tag.put(input.getMiddle(),
16✔
3565
                            NbtHelpers.getListNbtByte(value, NBT_COMPOUND_WITH_LIST_BYTE.getLocalizedNameFull())));
2✔
3566
                    return input.getLeft();
4✔
3567
                }
3568
            })).build());
1✔
3569

3570
    /**
3571
     * Set an NBT compound int list value
3572
     */
3573
    public static final IOperator NBT_COMPOUND_WITH_LIST_INT = REGISTRY.register(OperatorBuilders.NBT_3
5✔
3574
            .renderPattern(IConfigRenderPattern.INFIX_2_VERYLONG)
15✔
3575
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.LIST)
2✔
3576
            .operatorName("compound_with_list_int").symbol("NBT{}.with_int_list").interactName("withIntList")
9✔
3577
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(new IOperatorValuePropagator<Triple<Optional<CompoundTag>, String, OperatorBase.SafeVariablesGetter>, Optional<CompoundTag>>() {
5✔
3578
                @Override
3579
                public Optional<CompoundTag> getOutput(Triple<Optional<CompoundTag>, String, OperatorBase.SafeVariablesGetter> input) throws EvaluationException {
3580
                    ValueTypeList.ValueList<?, ?> value = input.getRight().getValue(0, ValueTypes.LIST);
8✔
3581
                    input.getLeft().ifPresent(tag -> tag.put(input.getMiddle(),
16✔
3582
                            NbtHelpers.getListNbtInt(value, NBT_COMPOUND_WITH_LIST_INT.getLocalizedNameFull())));
2✔
3583
                    return input.getLeft();
4✔
3584
                }
3585
            })).build());
1✔
3586

3587
    /**
3588
     * Set an NBT compound long list value
3589
     */
3590
    public static final IOperator NBT_COMPOUND_WITH_LIST_LONG = REGISTRY.register(OperatorBuilders.NBT_3
5✔
3591
            .renderPattern(IConfigRenderPattern.INFIX_2_VERYLONG)
15✔
3592
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.LIST)
2✔
3593
            .operatorName("compound_with_list_long").symbol("NBT{}.with_list_long").interactName("withListLong")
9✔
3594
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(new IOperatorValuePropagator<Triple<Optional<CompoundTag>, String, OperatorBase.SafeVariablesGetter>, Optional<CompoundTag>>() {
5✔
3595
                @Override
3596
                public Optional<CompoundTag> getOutput(Triple<Optional<CompoundTag>, String, OperatorBase.SafeVariablesGetter> input) throws EvaluationException {
3597
                    ValueTypeList.ValueList<?, ?> value = input.getRight().getValue(0, ValueTypes.LIST);
8✔
3598
                    input.getLeft().ifPresent(tag -> tag.put(input.getMiddle(),
16✔
3599
                            NbtHelpers.getListNbtLong(value, NBT_COMPOUND_WITH_LIST_LONG.getLocalizedNameFull())));
2✔
3600
                    return input.getLeft();
4✔
3601
                }
3602
            })).build());
1✔
3603

3604
    /**
3605
     * Check if the first NBT compound tag is a subset of the second NBT compound tag.
3606
     */
3607
    public static final IOperator NBT_COMPOUND_SUBSET = REGISTRY.register(OperatorBuilders.NBT_2_NBT
5✔
3608
            .output(ValueTypes.BOOLEAN).operatorName("compound_subset").symbol("NBT{}.⊆").interactName("isSubset")
8✔
3609
            .function(variables -> {
1✔
3610
                ValueTypeNbt.ValueNbt valueNbt0 = variables.getValue(0, ValueTypes.NBT);
6✔
3611
                ValueTypeNbt.ValueNbt valueNbt1 = variables.getValue(1, ValueTypes.NBT);
6✔
3612
                if (valueNbt0.getRawValue().isPresent()
5!
3613
                        && valueNbt1.getRawValue().isPresent()
4!
3614
                        && valueNbt0.getRawValue().get() instanceof CompoundTag
5!
3615
                        && valueNbt1.getRawValue().get() instanceof CompoundTag) {
4!
3616
                    return ValueTypeBoolean.ValueBoolean.of(NbtHelpers.nbtMatchesSubset((CompoundTag) valueNbt0.getRawValue().get(), (CompoundTag) valueNbt1.getRawValue().get(), true));
12✔
3617
                }
3618
                return ValueTypeBoolean.ValueBoolean.of(false);
×
3619
            }).build());
1✔
3620

3621
    /**
3622
     * The union of the given NBT compound tags. Nested tags will be joined recusively.
3623
     */
3624
    public static final IOperator NBT_COMPOUND_UNION = REGISTRY.register(OperatorBuilders.NBT_2_NBT
5✔
3625
            .output(ValueTypes.NBT).operatorName("compound_union").symbol("NBT{}.∪").interactName("union")
8✔
3626
            .function(variables -> {
1✔
3627
                ValueTypeNbt.ValueNbt valueNbt0 = variables.getValue(0, ValueTypes.NBT);
6✔
3628
                ValueTypeNbt.ValueNbt valueNbt1 = variables.getValue(1, ValueTypes.NBT);
6✔
3629
                if (valueNbt0.getRawValue().isPresent()
5!
3630
                        && valueNbt1.getRawValue().isPresent()
4!
3631
                        && valueNbt0.getRawValue().get() instanceof CompoundTag
5!
3632
                        && valueNbt1.getRawValue().get() instanceof CompoundTag) {
4!
3633
                    return ValueTypeNbt.ValueNbt.of(NbtHelpers.union((CompoundTag) valueNbt0.getRawValue().get(), (CompoundTag) valueNbt1.getRawValue().get()));
19✔
3634
                }
3635
                return ValueTypeNbt.ValueNbt.of();
×
3636
            }).build());
1✔
3637

3638
    /**
3639
     * The intersection of the given NBT compound tags. Nested tags will be intersected recusively.
3640
     */
3641
    public static final IOperator NBT_COMPOUND_INTERSECTION = REGISTRY.register(OperatorBuilders.NBT_2_NBT
5✔
3642
            .output(ValueTypes.NBT).operatorName("compound_intersection").symbol("NBT{}.∩").interactName("intersection")
8✔
3643
            .function(variables -> {
1✔
3644
                ValueTypeNbt.ValueNbt valueNbt0 = variables.getValue(0, ValueTypes.NBT);
6✔
3645
                ValueTypeNbt.ValueNbt valueNbt1 = variables.getValue(1, ValueTypes.NBT);
6✔
3646
                if (valueNbt0.getRawValue().isPresent()
5!
3647
                        && valueNbt1.getRawValue().isPresent()
4!
3648
                        && valueNbt0.getRawValue().get() instanceof CompoundTag
5!
3649
                        && valueNbt1.getRawValue().get() instanceof CompoundTag) {
4!
3650
                    return ValueTypeNbt.ValueNbt.of(NbtHelpers.intersection((CompoundTag) valueNbt0.getRawValue().get(), (CompoundTag) valueNbt1.getRawValue().get()));
19✔
3651
                }
3652
                return ValueTypeNbt.ValueNbt.of();
×
3653
            }).build());
1✔
3654

3655
    /**
3656
     * The difference of the given NBT compound tags. Nested tags will be subtracted recusively.
3657
     */
3658
    public static final IOperator NBT_COMPOUND_MINUS = REGISTRY.register(OperatorBuilders.NBT_2_NBT
5✔
3659
            .output(ValueTypes.NBT).operatorName("compound_minus").symbol("NBT{}.∖").interactName("minus")
8✔
3660
            .function(variables -> {
1✔
3661
                ValueTypeNbt.ValueNbt valueNbt0 = variables.getValue(0, ValueTypes.NBT);
6✔
3662
                ValueTypeNbt.ValueNbt valueNbt1 = variables.getValue(1, ValueTypes.NBT);
6✔
3663
                if (valueNbt0.getRawValue().isPresent()
5!
3664
                        && valueNbt1.getRawValue().isPresent()
4!
3665
                        && valueNbt0.getRawValue().get() instanceof CompoundTag
5!
3666
                        && valueNbt1.getRawValue().get() instanceof CompoundTag) {
4!
3667
                    return ValueTypeNbt.ValueNbt.of(NbtHelpers.minus((CompoundTag) valueNbt0.getRawValue().get(), (CompoundTag) valueNbt1.getRawValue().get()));
11✔
3668
                }
3669
                return ValueTypeNbt.ValueNbt.of();
×
3670
            }).build());
1✔
3671

3672
    /**
3673
     * The boolean value of an NBT value
3674
     */
3675
    public static final IOperator NBT_AS_BOOLEAN = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3676
            .output(ValueTypes.BOOLEAN).operatorName("as_boolean").symbol("NBT.as_boolean").interactName("asBoolean")
9✔
3677
            .function(OperatorBuilders.FUNCTION_NBT_TO_BOOLEAN.build(
2✔
3678
                    o -> o.flatMap(Tag::asBoolean).orElse(false)
8✔
3679
            )).build());
1✔
3680

3681
    /**
3682
     * The byte value of an NBT value
3683
     */
3684
    public static final IOperator NBT_AS_BYTE = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3685
            .output(ValueTypes.INTEGER).operatorName("as_byte").symbol("NBT.as_byte").interactName("asByte")
9✔
3686
            .function(OperatorBuilders.FUNCTION_NBT_TO_INT.build(
2✔
3687
                    o -> o.flatMap(Tag::asByte).map(s -> (int) s).orElse(0)
14✔
3688
            )).build());
1✔
3689

3690
    /**
3691
     * The short value of an NBT value
3692
     */
3693
    public static final IOperator NBT_AS_SHORT = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3694
            .output(ValueTypes.INTEGER).operatorName("as_short").symbol("NBT.as_short").interactName("asShort")
9✔
3695
            .function(OperatorBuilders.FUNCTION_NBT_TO_INT.build(
2✔
3696
                    o -> o.flatMap(Tag::asShort).map(s -> (int) s).orElse(0)
14✔
3697
            )).build());
1✔
3698

3699
    /**
3700
     * The int value of an NBT value
3701
     */
3702
    public static final IOperator NBT_AS_INT = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3703
            .output(ValueTypes.INTEGER).operatorName("as_int").symbol("NBT.as_int").interactName("asInt")
9✔
3704
            .function(OperatorBuilders.FUNCTION_NBT_TO_INT.build(
2✔
3705
                    o -> o.flatMap(Tag::asInt).orElse(0)
8✔
3706
            )).build());
1✔
3707

3708
    /**
3709
     * The long value of an NBT value
3710
     */
3711
    public static final IOperator NBT_AS_LONG = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3712
            .output(ValueTypes.LONG).operatorName("as_long").symbol("NBT.as_long").interactName("asLong")
9✔
3713
            .function(OperatorBuilders.FUNCTION_NBT_TO_LONG.build(
2✔
3714
                    o -> o.flatMap(Tag::asLong).orElse(0L)
8✔
3715
            )).build());
1✔
3716

3717
    /**
3718
     * The double value of an NBT value
3719
     */
3720
    public static final IOperator NBT_AS_DOUBLE = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3721
            .output(ValueTypes.DOUBLE).operatorName("as_double").symbol("NBT.as_double").interactName("asDouble")
9✔
3722
            .function(OperatorBuilders.FUNCTION_NBT_TO_DOUBLE.build(
2✔
3723
                    o -> o.flatMap(Tag::asDouble).orElse(0D)
8✔
3724
            )).build());
1✔
3725

3726
    /**
3727
     * The float value of an NBT value
3728
     */
3729
    public static final IOperator NBT_AS_FLOAT = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3730
            .output(ValueTypes.DOUBLE).operatorName("as_float").symbol("NBT.as_float").interactName("asFloat")
9✔
3731
            .function(OperatorBuilders.FUNCTION_NBT_TO_DOUBLE.build(
2✔
3732
                    o -> o.flatMap(Tag::asFloat).map(f -> (double) f).orElse(0D)
15✔
3733
            )).build());
1✔
3734

3735
    /**
3736
     * The string value of an NBT value
3737
     */
3738
    public static final IOperator NBT_AS_STRING = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3739
            .output(ValueTypes.STRING).operatorName("as_string").symbol("NBT.as_string").interactName("asString")
9✔
3740
            .function(OperatorBuilders.FUNCTION_NBT_TO_STRING.build(
2✔
3741
                    o -> o.flatMap(Tag::asString).orElse("")
7✔
3742
            )).build());
1✔
3743

3744
    /**
3745
     * The tag list value of an NBT value
3746
     */
3747
    public static final IOperator NBT_AS_TAG_LIST = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3748
            .output(ValueTypes.LIST).operatorName("as_tag_list").symbol("NBT.as_tag_list").interactName("asTagList")
8✔
3749
            .function(variables -> {
1✔
3750
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3751
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtAsListTag(value.getRawValue()));
7✔
3752
            }).build());
1✔
3753

3754
    /**
3755
     * The byte list value of an NBT value
3756
     */
3757
    public static final IOperator NBT_AS_BYTE_LIST = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3758
            .output(ValueTypes.LIST).operatorName("as_byte_list").symbol("NBT.as_byte_list").interactName("asByteList")
8✔
3759
            .function(variables -> {
1✔
3760
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3761
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtAsListByte(value.getRawValue()));
7✔
3762
            }).build());
1✔
3763

3764
    /**
3765
     * The int list value of an NBT value
3766
     */
3767
    public static final IOperator NBT_AS_INT_LIST = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3768
            .output(ValueTypes.LIST).operatorName("as_int_list").symbol("NBT.as_int_list").interactName("asIntList")
8✔
3769
            .function(variables -> {
1✔
3770
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3771
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtAsListInt(value.getRawValue()));
7✔
3772
            }).build());
1✔
3773

3774
    /**
3775
     * The long list value of an NBT value
3776
     */
3777
    public static final IOperator NBT_AS_LONG_LIST = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3778
            .output(ValueTypes.LIST).operatorName("as_long_list").symbol("NBT.as_long_list").interactName("asLongList")
8✔
3779
            .function(variables -> {
1✔
3780
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3781
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtAsListLong(value.getRawValue()));
7✔
3782
            }).build());
1✔
3783

3784
    /**
3785
     * The NBT value of a boolean value
3786
     */
3787
    public static final IOperator NBT_FROM_BOOLEAN = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3788
            .inputType(ValueTypes.BOOLEAN).output(ValueTypes.NBT)
4✔
3789
            .operatorName("from_boolean").symbol("NBT.from_boolean").interactName("asNbt")
6✔
3790
            .function(variables -> {
1✔
3791
                ValueTypeBoolean.ValueBoolean value = variables.getValue(0, ValueTypes.BOOLEAN);
6✔
3792
                return ValueTypeNbt.ValueNbt.of(ByteTag.valueOf(value.getRawValue()));
5✔
3793
            }).build());
1✔
3794

3795
    /**
3796
     * The NBT value of a short value
3797
     */
3798
    public static final IOperator NBT_FROM_SHORT = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3799
            .inputType(ValueTypes.INTEGER).output(ValueTypes.NBT)
4✔
3800
            .operatorName("from_short").symbol("NBT.from_short").interactName("asNbt", "short", true)
8✔
3801
            .function(variables -> {
1✔
3802
                ValueTypeInteger.ValueInteger value = variables.getValue(0, ValueTypes.INTEGER);
6✔
3803
                return ValueTypeNbt.ValueNbt.of(ShortTag.valueOf((short) value.getRawValue()));
6✔
3804
            }).build());
1✔
3805

3806
    /**
3807
     * The NBT value of a byte value
3808
     */
3809
    public static final IOperator NBT_FROM_BYTE = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3810
            .inputType(ValueTypes.INTEGER).output(ValueTypes.NBT)
4✔
3811
            .operatorName("from_byte").symbol("NBT.from_byte").interactName("asNbt", "byte", true)
8✔
3812
            .function(variables -> {
1✔
3813
                ValueTypeInteger.ValueInteger value = variables.getValue(0, ValueTypes.INTEGER);
6✔
3814
                return ValueTypeNbt.ValueNbt.of(ByteTag.valueOf((byte) value.getRawValue()));
6✔
3815
            }).build());
1✔
3816

3817
    /**
3818
     * The NBT value of an int value
3819
     */
3820
    public static final IOperator NBT_FROM_INT = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3821
            .inputType(ValueTypes.INTEGER).output(ValueTypes.NBT)
4✔
3822
            .operatorName("from_int").symbol("NBT.from_int").interactName("asNbt")
6✔
3823
            .function(variables -> {
1✔
3824
                ValueTypeInteger.ValueInteger value = variables.getValue(0, ValueTypes.INTEGER);
6✔
3825
                return ValueTypeNbt.ValueNbt.of(IntTag.valueOf(value.getRawValue()));
5✔
3826
            }).build());
1✔
3827

3828
    /**
3829
     * The NBT value of a long value
3830
     */
3831
    public static final IOperator NBT_FROM_LONG = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3832
            .inputType(ValueTypes.LONG).output(ValueTypes.NBT)
4✔
3833
            .operatorName("from_long").symbol("NBT.from_long").interactName("asNbt")
6✔
3834
            .function(variables -> {
1✔
3835
                ValueTypeLong.ValueLong value = variables.getValue(0, ValueTypes.LONG);
6✔
3836
                return ValueTypeNbt.ValueNbt.of(LongTag.valueOf(value.getRawValue()));
5✔
3837
            }).build());
1✔
3838

3839
    /**
3840
     * The NBT value of a double value
3841
     */
3842
    public static final IOperator NBT_FROM_DOUBLE = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3843
            .inputType(ValueTypes.DOUBLE).output(ValueTypes.NBT)
4✔
3844
            .operatorName("from_double").symbol("NBT.from_double").interactName("asNbt")
6✔
3845
            .function(variables -> {
1✔
3846
                ValueTypeDouble.ValueDouble value = variables.getValue(0, ValueTypes.DOUBLE);
6✔
3847
                return ValueTypeNbt.ValueNbt.of(DoubleTag.valueOf(value.getRawValue()));
5✔
3848
            }).build());
1✔
3849

3850
    /**
3851
     * The NBT value of a float value
3852
     */
3853
    public static final IOperator NBT_FROM_FLOAT = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3854
            .inputType(ValueTypes.DOUBLE).output(ValueTypes.NBT)
4✔
3855
            .operatorName("from_float").symbol("NBT.from_float").interactName("asNbt", "float", true)
8✔
3856
            .function(variables -> {
1✔
3857
                ValueTypeDouble.ValueDouble value = variables.getValue(0, ValueTypes.DOUBLE);
6✔
3858
                return ValueTypeNbt.ValueNbt.of(FloatTag.valueOf((float) value.getRawValue()));
6✔
3859
            }).build());
1✔
3860

3861
    /**
3862
     * The NBT value of a string value
3863
     */
3864
    public static final IOperator NBT_FROM_STRING = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3865
            .inputType(ValueTypes.STRING).output(ValueTypes.NBT)
4✔
3866
            .operatorName("from_string").symbol("NBT.from_string").interactName("asNbt")
6✔
3867
            .function(variables -> {
1✔
3868
                ValueTypeString.ValueString value = variables.getValue(0, ValueTypes.STRING);
6✔
3869
                return ValueTypeNbt.ValueNbt.of(StringTag.valueOf(value.getRawValue()));
5✔
3870
            }).build());
1✔
3871

3872
    /**
3873
     * The NBT value of a tag list value
3874
     */
3875
    public static final IOperator NBT_FROM_TAG_LIST = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3876
            .inputType(ValueTypes.LIST).output(ValueTypes.NBT)
4✔
3877
            .operatorName("from_tag_list").symbol("NBT.from_tag_list").interactName("asNbt", "tagList", true)
10✔
3878
            .function(new OperatorBase.IFunction() {
4✔
3879
                @Override
3880
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
3881
                    ValueTypeList.ValueList value = variables.getValue(0, ValueTypes.LIST);
6✔
3882
                    return ValueTypeNbt.ValueNbt.of(NbtHelpers.getListNbtTag(value, NBT_FROM_TAG_LIST.getLocalizedNameFull()));
6✔
3883
                }
3884
            }).build());
1✔
3885

3886
    /**
3887
     * The NBT value of a byte list value
3888
     */
3889
    public static final IOperator NBT_FROM_BYTE_LIST = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3890
            .inputType(ValueTypes.LIST).output(ValueTypes.NBT)
4✔
3891
            .operatorName("from_byte_list").symbol("NBT.from_byte_list").interactName("asNbt", "byteList", true)
10✔
3892
            .function(new OperatorBase.IFunction() {
4✔
3893
                @Override
3894
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
3895
                    ValueTypeList.ValueList value = variables.getValue(0, ValueTypes.LIST);
6✔
3896
                    return ValueTypeNbt.ValueNbt.of(NbtHelpers.getListNbtByte(value, NBT_FROM_BYTE_LIST.getLocalizedNameFull()));
6✔
3897
                }
3898
            }).build());
1✔
3899

3900
    /**
3901
     * The NBT value of a int list value
3902
     */
3903
    public static final IOperator NBT_FROM_INT_LIST = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3904
            .inputType(ValueTypes.LIST).output(ValueTypes.NBT)
4✔
3905
            .operatorName("from_int_list").symbol("NBT.from_int_list").interactName("asNbt", "intList", true)
10✔
3906
            .function(new OperatorBase.IFunction() {
4✔
3907
                @Override
3908
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
3909
                    ValueTypeList.ValueList value = variables.getValue(0, ValueTypes.LIST);
6✔
3910
                    return ValueTypeNbt.ValueNbt.of(NbtHelpers.getListNbtInt(value, NBT_FROM_INT_LIST.getLocalizedNameFull()));
6✔
3911
                }
3912
            }).build());
1✔
3913

3914
    /**
3915
     * The NBT value of a long list value
3916
     */
3917
    public static final IOperator NBT_FROM_LONG_LIST = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3918
            .inputType(ValueTypes.LIST).output(ValueTypes.NBT)
4✔
3919
            .operatorName("from_long_list").symbol("NBT.from_long_list").interactName("asNbt", "longList", true)
10✔
3920
            .function(new OperatorBase.IFunction() {
4✔
3921
                @Override
3922
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
3923
                    ValueTypeList.ValueList value = variables.getValue(0, ValueTypes.LIST);
6✔
3924
                    return ValueTypeNbt.ValueNbt.of(NbtHelpers.getListNbtLong(value, NBT_FROM_LONG_LIST.getLocalizedNameFull()));
6✔
3925
                }
3926
            }).build());
1✔
3927

3928
    /**
3929
     * Apply the given NBT path expression on the given NBT value and get the first result.
3930
     */
3931
    public static final IOperator NBT_PATH_MATCH_FIRST = REGISTRY.register(OperatorBuilders.NBT_2
14✔
3932
            .inputTypes(ValueTypes.STRING, ValueTypes.NBT).output(ValueTypes.NBT)
4✔
3933
            .operatorName("path_match_first").symbol("NBT.path_match_first").interactName("nbtPathMatchFirst")
6✔
3934
            .function(variables -> {
1✔
3935
                ValueTypeString.ValueString string = variables.getValue(0, ValueTypes.STRING);
6✔
3936
                ValueTypeNbt.ValueNbt nbt = variables.getValue(1, ValueTypes.NBT);
6✔
3937
                INbtPathExpression expression = null;
2✔
3938
                try {
3939
                    expression = NbtPath.parse(string.getRawValue());
4✔
3940
                } catch (NbtParseException e) {
×
3941
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_NBT_PATH_EXPRESSION,
×
3942
                            string.getRawValue(),
×
3943
                            e.getMessage()));
×
3944
                }
1✔
3945
                if (!nbt.getRawValue().isPresent()) {
4!
3946
                    return ValueTypeNbt.ValueNbt.of();
×
3947
                }
3948
                return ValueTypeNbt.ValueNbt.of(expression.match(nbt.getRawValue().get()).getMatches().findAny());
10✔
3949
            }).build());
1✔
3950

3951
    /**
3952
     * Apply the given NBT path expression on the given NBT value and get all results.
3953
     */
3954
    public static final IOperator NBT_PATH_MATCH_ALL = REGISTRY.register(OperatorBuilders.NBT_2
14✔
3955
            .inputTypes(ValueTypes.STRING, ValueTypes.NBT).output(ValueTypes.LIST)
4✔
3956
            .operatorName("path_match_all").symbol("NBT.path_match_all").interactName("nbtPathMatchAll")
6✔
3957
            .function(variables -> {
1✔
3958
                ValueTypeString.ValueString string = variables.getValue(0, ValueTypes.STRING);
6✔
3959
                ValueTypeNbt.ValueNbt nbt = variables.getValue(1, ValueTypes.NBT);
6✔
3960
                INbtPathExpression expression = null;
2✔
3961
                try {
3962
                    expression = NbtPath.parse(string.getRawValue());
4✔
3963
                } catch (NbtParseException e) {
×
3964
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_NBT_PATH_EXPRESSION,
×
3965
                            string.getRawValue(),
×
3966
                            e.getMessage()));
×
3967
                }
1✔
3968
                if (!nbt.getRawValue().isPresent()) {
4!
3969
                    return ValueTypeList.ValueList.ofAll(ValueTypes.NBT);
×
3970
                }
3971
                List<ValueTypeNbt.ValueNbt> matches = expression.match(nbt.getRawValue().get()).getMatches()
8✔
3972
                        .map(ValueTypeNbt.ValueNbt::of)
1✔
3973
                        .collect(Collectors.toList());
4✔
3974
                return ValueTypeList.ValueList.ofList(ValueTypes.NBT, matches);
4✔
3975
            }).build());
1✔
3976

3977
    /**
3978
     * Test the given NBT path expression on the given NBT value.
3979
     */
3980
    public static final IOperator NBT_PATH_TEST = REGISTRY.register(OperatorBuilders.NBT_2
14✔
3981
            .inputTypes(ValueTypes.STRING, ValueTypes.NBT).output(ValueTypes.BOOLEAN)
4✔
3982
            .operatorName("path_test").symbol("NBT.path_test").interactName("nbtPathTest")
6✔
3983
            .function(variables -> {
1✔
3984
                ValueTypeString.ValueString string = variables.getValue(0, ValueTypes.STRING);
6✔
3985
                ValueTypeNbt.ValueNbt nbt = variables.getValue(1, ValueTypes.NBT);
6✔
3986
                INbtPathExpression expression = null;
2✔
3987
                try {
3988
                    expression = NbtPath.parse(string.getRawValue());
4✔
3989
                } catch (NbtParseException e) {
×
3990
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_NBT_PATH_EXPRESSION,
×
3991
                            string.getRawValue(),
×
3992
                            e.getMessage()));
×
3993
                }
1✔
3994
                if (!nbt.getRawValue().isPresent()) {
4!
3995
                    return ValueTypeBoolean.ValueBoolean.of(false);
×
3996
                }
3997
                return ValueTypeBoolean.ValueBoolean.of(expression.test(nbt.getRawValue().get()));
8✔
3998
            }).build());
1✔
3999

4000
    /**
4001
     * ----------------------------------- INGREDIENTS OPERATORS -----------------------------------
4002
     */
4003

4004
    /**
4005
     * The list of items.
4006
     */
4007
    public static final IOperator INGREDIENTS_ITEMS = REGISTRY.register(OperatorBuilders.INGREDIENTS_1_PREFIX_LONG
5✔
4008
            .output(ValueTypes.LIST).operatorInteract("items").symbol("Ingr.items")
6✔
4009
            .function(OperatorBuilders.createFunctionIngredientsList(() -> IngredientComponent.ITEMSTACK))
4✔
4010
            .build());
1✔
4011

4012
    /**
4013
     * The list of fluids
4014
     */
4015
    public static final IOperator INGREDIENTS_FLUIDS = REGISTRY.register(OperatorBuilders.INGREDIENTS_1_PREFIX_LONG
5✔
4016
            .output(ValueTypes.LIST).operatorInteract("fluids").symbol("Ingr.fluids")
6✔
4017
            .function(OperatorBuilders.createFunctionIngredientsList(() -> IngredientComponent.FLUIDSTACK))
4✔
4018
            .build());
1✔
4019

4020
    /**
4021
     * The list of fluids
4022
     */
4023
    public static final IOperator INGREDIENTS_ENERGIES = REGISTRY.register(OperatorBuilders.INGREDIENTS_1_PREFIX_LONG
5✔
4024
            .output(ValueTypes.LIST).operatorInteract("energies").symbol("Ingr.energies")
6✔
4025
            .function(OperatorBuilders.createFunctionIngredientsList(() -> IngredientComponent.ENERGY))
4✔
4026
            .build());
1✔
4027

4028
    /**
4029
     * Set an ingredient item
4030
     */
4031
    public static final IOperator INGREDIENTS_WITH_ITEM = REGISTRY.register(OperatorBuilders.INGREDIENTS_3_ITEMSTACK
5✔
4032
            .operatorName("with_item").symbol("Ingr.with_item").interactName("withItem")
6✔
4033
            .function(variables -> {
1✔
4034
                ValueObjectTypeIngredients.ValueIngredients value = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
6✔
4035
                ValueTypeInteger.ValueInteger index = variables.getValue(1, ValueTypes.INTEGER);
6✔
4036
                ValueObjectTypeItemStack.ValueItemStack itemStack = variables.getValue(2, ValueTypes.OBJECT_ITEMSTACK);
6✔
4037
                if (value.getRawValue().isEmpty()) {
4!
4038
                    value = ValueObjectTypeIngredients.ValueIngredients.of(new MixedIngredients(Maps.newIdentityHashMap()));
×
4039
                }
4040
                IMixedIngredients baseIngredients = value.getRawValue().get();
5✔
4041
                return ValueObjectTypeIngredients.ValueIngredients.of(new ExtendedIngredientsSingle<>(baseIngredients,
6✔
4042
                        index.getRawValue(), IngredientComponent.ITEMSTACK, itemStack.getRawValue()));
5✔
4043
            }).build());
1✔
4044

4045
    /**
4046
     * Set an ingredient fluid
4047
     */
4048
    public static final IOperator INGREDIENTS_WITH_FLUID = REGISTRY.register(OperatorBuilders.INGREDIENTS_3_FLUIDSTACK
5✔
4049
            .operatorName("with_fluid").symbol("Ingr.with_fluid").interactName("withFluid")
6✔
4050
            .function(variables -> {
1✔
4051
                ValueObjectTypeIngredients.ValueIngredients value = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
6✔
4052
                ValueTypeInteger.ValueInteger index = variables.getValue(1, ValueTypes.INTEGER);
6✔
4053
                ValueObjectTypeFluidStack.ValueFluidStack fluidStack = variables.getValue(2, ValueTypes.OBJECT_FLUIDSTACK);
6✔
4054
                if (value.getRawValue().isEmpty()) {
4!
4055
                    value = ValueObjectTypeIngredients.ValueIngredients.of(new MixedIngredients(Maps.newIdentityHashMap()));
×
4056
                }
4057
                IMixedIngredients baseIngredients = value.getRawValue().get();
5✔
4058
                return ValueObjectTypeIngredients.ValueIngredients.of(new ExtendedIngredientsSingle<>(baseIngredients,
6✔
4059
                        index.getRawValue(), IngredientComponent.FLUIDSTACK, fluidStack.getRawValue()));
5✔
4060
            }).build());
1✔
4061

4062
    /**
4063
     * Set an ingredient energy
4064
     */
4065
    public static final IOperator INGREDIENTS_WITH_ENERGY = REGISTRY.register(OperatorBuilders.INGREDIENTS_3_LONG
5✔
4066
            .operatorName("with_energy").symbol("Ingr.with_energy").interactName("withEnergy")
6✔
4067
            .function(variables -> {
1✔
4068
                ValueObjectTypeIngredients.ValueIngredients value = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
6✔
4069
                ValueTypeInteger.ValueInteger index = variables.getValue(1, ValueTypes.INTEGER);
6✔
4070
                ValueTypeLong.ValueLong energy = variables.getValue(2, ValueTypes.LONG);
6✔
4071
                if (value.getRawValue().isEmpty()) {
4!
4072
                    value = ValueObjectTypeIngredients.ValueIngredients.of(new MixedIngredients(Maps.newIdentityHashMap()));
×
4073
                }
4074
                IMixedIngredients baseIngredients = value.getRawValue().get();
5✔
4075
                return ValueObjectTypeIngredients.ValueIngredients.of(new ExtendedIngredientsSingle<>(baseIngredients,
6✔
4076
                        index.getRawValue(), IngredientComponent.ENERGY, energy.getRawValue()));
6✔
4077
            }).build());
1✔
4078

4079
    /**
4080
     * Set the list of items
4081
     */
4082
    public static final IOperator INGREDIENTS_WITH_ITEMS = REGISTRY.register(OperatorBuilders.INGREDIENTS_2_LIST
5✔
4083
            .operatorName("with_items").symbol("Ingr.with_items").interactName("withItems")
6✔
4084
            .function(variables -> {
1✔
4085
                ValueObjectTypeIngredients.ValueIngredients valueIngredients = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
6✔
4086
                ValueTypeList.ValueList<ValueObjectTypeItemStack, ValueObjectTypeItemStack.ValueItemStack> list = variables.getValue(1, ValueTypes.LIST);
6✔
4087
                if (valueIngredients.getRawValue().isEmpty()) {
4!
4088
                    valueIngredients = ValueObjectTypeIngredients.ValueIngredients.of(new MixedIngredients(Maps.newIdentityHashMap()));
×
4089
                }
4090
                IMixedIngredients baseIngredients = valueIngredients.getRawValue().get();
5✔
4091
                return ValueObjectTypeIngredients.ValueIngredients.of(new ExtendedIngredientsList<>(baseIngredients,
8✔
4092
                        IngredientComponent.ITEMSTACK, OperatorBuilders.unwrapIngredientComponentList(IngredientComponent.ITEMSTACK, list)));
2✔
4093
            }).build());
1✔
4094

4095
    /**
4096
     * Set the list of fluids
4097
     */
4098
    public static final IOperator INGREDIENTS_WITH_FLUIDS = REGISTRY.register(OperatorBuilders.INGREDIENTS_2_LIST
5✔
4099
            .operatorName("with_fluids").symbol("Ingr.with_fluids").interactName("withFluids")
6✔
4100
            .function(variables -> {
1✔
4101
                ValueObjectTypeIngredients.ValueIngredients valueIngredients = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
6✔
4102
                ValueTypeList.ValueList<ValueObjectTypeFluidStack, ValueObjectTypeFluidStack.ValueFluidStack> list = variables.getValue(1, ValueTypes.LIST);
6✔
4103
                if (valueIngredients.getRawValue().isEmpty()) {
4!
4104
                    valueIngredients = ValueObjectTypeIngredients.ValueIngredients.of(new MixedIngredients(Maps.newIdentityHashMap()));
×
4105
                }
4106
                IMixedIngredients baseIngredients = valueIngredients.getRawValue().get();
5✔
4107
                return ValueObjectTypeIngredients.ValueIngredients.of(new ExtendedIngredientsList<>(baseIngredients,
8✔
4108
                        IngredientComponent.FLUIDSTACK, OperatorBuilders.unwrapIngredientComponentList(IngredientComponent.FLUIDSTACK, list)));
2✔
4109
            }).build());
1✔
4110

4111
    /**
4112
     * Set the list of energies
4113
     */
4114
    public static final IOperator INGREDIENTS_WITH_ENERGIES = REGISTRY.register(OperatorBuilders.INGREDIENTS_2_LIST
5✔
4115
            .renderPattern(IConfigRenderPattern.INFIX_VERYLONG)
2✔
4116
            .operatorName("with_energies").symbol("Ingr.with_energies").interactName("withEnergies")
6✔
4117
            .function(variables -> {
1✔
4118
                ValueObjectTypeIngredients.ValueIngredients valueIngredients = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
6✔
4119
                ValueTypeList.ValueList<ValueTypeInteger, ValueTypeInteger.ValueInteger> list = variables.getValue(1, ValueTypes.LIST);
6✔
4120
                if (valueIngredients.getRawValue().isEmpty()) {
4!
4121
                    valueIngredients = ValueObjectTypeIngredients.ValueIngredients.of(new MixedIngredients(Maps.newIdentityHashMap()));
×
4122
                }
4123
                IMixedIngredients baseIngredients = valueIngredients.getRawValue().get();
5✔
4124
                return ValueObjectTypeIngredients.ValueIngredients.of(new ExtendedIngredientsList<>(baseIngredients,
8✔
4125
                        IngredientComponent.ENERGY, OperatorBuilders.unwrapIngredientComponentList(IngredientComponent.ENERGY, list)));
2✔
4126
            }).build());
1✔
4127

4128
    /**
4129
     * ----------------------------------- RECIPE OPERATORS -----------------------------------
4130
     */
4131

4132
    /**
4133
     * The input ingredients of a recipe
4134
     */
4135
    public static final IOperator RECIPE_INPUT = REGISTRY.register(OperatorBuilders.RECIPE_1_SUFFIX_LONG
5✔
4136
            .output(ValueTypes.OBJECT_INGREDIENTS)
2✔
4137
            .operatorInteract("input").symbol("recipe_in")
4✔
4138
            .function(variables -> {
1✔
4139
                ValueObjectTypeRecipe.ValueRecipe value = variables.getValue(0, ValueTypes.OBJECT_RECIPE);
6✔
4140
                if (value.getRawValue().isPresent()) {
4!
4141
                    return ValueObjectTypeIngredients.ValueIngredients.of(MixedIngredients.fromRecipeInput(value.getRawValue().get()));
7✔
4142
                }
4143
                return ValueObjectTypeIngredients.ValueIngredients.of(null);
×
4144
            }).build());
1✔
4145

4146
    /**
4147
     * The output ingredients of a recipe
4148
     */
4149
    public static final IOperator RECIPE_OUTPUT = REGISTRY.register(OperatorBuilders.RECIPE_1_SUFFIX_LONG
5✔
4150
            .output(ValueTypes.OBJECT_INGREDIENTS)
2✔
4151
            .operatorInteract("output").symbol("recipe_out")
4✔
4152
            .function(variables -> {
1✔
4153
                ValueObjectTypeRecipe.ValueRecipe value = variables.getValue(0, ValueTypes.OBJECT_RECIPE);
6✔
4154
                if (value.getRawValue().isPresent()) {
4!
4155
                    return ValueObjectTypeIngredients.ValueIngredients.of(value.getRawValue().get().getOutput());
7✔
4156
                }
4157
                return ValueObjectTypeIngredients.ValueIngredients.of(null);
×
4158
            }).build());
1✔
4159

4160
    /**
4161
     * Set the input ingredients of a recipe
4162
     */
4163
    public static final IOperator RECIPE_WITH_INPUT = REGISTRY.register(OperatorBuilders.RECIPE_2_INFIX
5✔
4164
            .output(ValueTypes.OBJECT_RECIPE)
2✔
4165
            .operatorName("with_input").symbol("Recipe.with_in").interactName("withInput")
6✔
4166
            .function(variables -> {
1✔
4167
                ValueObjectTypeRecipe.ValueRecipe valueRecipe = variables.getValue(0, ValueTypes.OBJECT_RECIPE);
6✔
4168
                ValueObjectTypeIngredients.ValueIngredients valueIngredients = variables.getValue(1, ValueTypes.OBJECT_INGREDIENTS);
6✔
4169
                if (valueRecipe.getRawValue().isPresent() && valueIngredients.getRawValue().isPresent()) {
8!
4170
                    IMixedIngredients ingredients = valueIngredients.getRawValue().get();
5✔
4171
                    Map<IngredientComponent<?, ?>, List<IPrototypedIngredientAlternatives<?, ?>>> inputs = Maps.newIdentityHashMap();
2✔
4172
                    for (IngredientComponent<?, ?> component : ingredients.getComponents()) {
11✔
4173
                        IIngredientMatcher matcher = component.getMatcher();
3✔
4174
                        inputs.put(component, (List) ingredients.getInstances(component)
7✔
4175
                                .stream()
4✔
4176
                                .map(instance -> new PrototypedIngredientAlternativesList(Collections.singletonList(new PrototypedIngredient(component, instance, matcher.getExactMatchCondition()))))
13✔
4177
                                .collect(Collectors.toList()));
3✔
4178
                    }
1✔
4179
                    return ValueObjectTypeRecipe.ValueRecipe.of(new RecipeDefinition(
6✔
4180
                            inputs,
4181
                            valueRecipe.getRawValue().get().getOutput()
5✔
4182
                    ));
4183
                }
4184
                return ValueObjectTypeRecipe.ValueRecipe.of(null);
×
4185
            }).build());
1✔
4186

4187
    /**
4188
     * Set the output ingredients of a recipe
4189
     */
4190
    public static final IOperator RECIPE_WITH_OUTPUT = REGISTRY.register(OperatorBuilders.RECIPE_2_INFIX
5✔
4191
            .output(ValueTypes.OBJECT_RECIPE)
2✔
4192
            .operatorName("with_output").symbol("Recipe.with_out").interactName("withOutput")
6✔
4193
            .function(variables -> {
1✔
4194
                ValueObjectTypeRecipe.ValueRecipe valueRecipe = variables.getValue(0, ValueTypes.OBJECT_RECIPE);
6✔
4195
                ValueObjectTypeIngredients.ValueIngredients valueIngredients = variables.getValue(1, ValueTypes.OBJECT_INGREDIENTS);
6✔
4196
                if (valueRecipe.getRawValue().isPresent() && valueIngredients.getRawValue().isPresent()) {
8!
4197
                    IRecipeDefinition recipe = valueRecipe.getRawValue().get();
5✔
4198
                    Map<IngredientComponent<?, ?>, List<IPrototypedIngredientAlternatives<?, ?>>> inputs = Maps.newIdentityHashMap();
2✔
4199
                    for (IngredientComponent<?, ?> component : recipe.getInputComponents()) {
11✔
4200
                        inputs.put(component, (List) recipe.getInputs(component));
7✔
4201
                    }
1✔
4202
                    return ValueObjectTypeRecipe.ValueRecipe.of(new RecipeDefinition(
6✔
4203
                            inputs,
4204
                            valueIngredients.getRawValue().get()
4✔
4205
                    ));
4206
                }
4207
                return ValueObjectTypeRecipe.ValueRecipe.of(null);
×
4208
            }).build());
1✔
4209

4210
    /**
4211
     * Create a recipe from two the given I/O ingredients
4212
     */
4213
    public static final IOperator RECIPE_WITH_INPUT_OUTPUT = REGISTRY.register(OperatorBuilders.RECIPE_2_PREFIX
5✔
4214
            .output(ValueTypes.OBJECT_RECIPE)
2✔
4215
            .operatorName("with_input_output").symbol("Recipe.with_io").interactName("withInputOutput")
6✔
4216
            .function(variables -> {
1✔
4217
                ValueObjectTypeIngredients.ValueIngredients valueIn = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
6✔
4218
                ValueObjectTypeIngredients.ValueIngredients valueOut = variables.getValue(1, ValueTypes.OBJECT_INGREDIENTS);
6✔
4219
                if (valueIn.getRawValue().isPresent() && valueOut.getRawValue().isPresent()) {
8!
4220
                    IMixedIngredients ingredients = valueIn.getRawValue().get();
5✔
4221
                    Map<IngredientComponent<?, ?>, List<IPrototypedIngredientAlternatives<?, ?>>> inputs = Maps.newIdentityHashMap();
2✔
4222
                    for (IngredientComponent<?, ?> component : ingredients.getComponents()) {
11✔
4223
                        IIngredientMatcher matcher = component.getMatcher();
3✔
4224
                        inputs.put(component, (List) ingredients.getInstances(component)
7✔
4225
                                .stream()
4✔
4226
                                .map(instance -> new PrototypedIngredientAlternativesList(Collections.singletonList(new PrototypedIngredient(component, instance, matcher.getExactMatchCondition()))))
13✔
4227
                                .collect(Collectors.toList()));
3✔
4228
                    }
1✔
4229
                    try {
4230
                        return ValueObjectTypeRecipe.ValueRecipe.of(new RecipeDefinition(
6✔
4231
                                inputs,
4232
                                valueOut.getRawValue().get()
4✔
4233
                        ));
4234
                    } catch (IllegalArgumentException e) {
×
4235
                        throw new EvaluationException(Component.literal(e.getMessage()));
×
4236
                    }
4237
                }
4238
                return ValueObjectTypeRecipe.ValueRecipe.of(null);
×
4239
            }).build());
1✔
4240

4241
    /**
4242
     * ------------------------------------ PARSE OPERATORS ------------------------------------
4243
     */
4244

4245
    /**
4246
     * Boolean Parse operator which takes a string of form `/(F(alse)?|[+-]?(0x|#)?0+|)/i`.
4247
     */
4248
    public static final IOperator PARSE_BOOLEAN = Operators.REGISTRY.register(new ParseOperator<>(ValueTypes.BOOLEAN, v -> {
8✔
4249
      ValueTypeString.ValueString value = v.getValue(0, ValueTypes.STRING);
6✔
4250
      Pattern p = Pattern.compile("\\A(F(alse)?|[+-]?(0x|#)?0+|)\\z", Pattern.CASE_INSENSITIVE);
4✔
4251
      return ValueTypeBoolean.ValueBoolean.of(!p.matcher(value.getRawValue().trim()).matches());
12✔
4252
    }));
4253

4254
    /**
4255
     * Double Parse operator which takes a string of a form Double.parseDouble(),
4256
     * `/([+-]?)(Inf(inity)?|\u221E)/i`, or Long.decode() can consume.
4257
     */
4258
    public static final IOperator PARSE_DOUBLE = Operators.REGISTRY.register(new ParseOperator<>(ValueTypes.DOUBLE, v -> {
8✔
4259
      ValueTypeString.ValueString value = v.getValue(0, ValueTypes.STRING);
6✔
4260
      try {
4261
        return ValueTypeDouble.ValueDouble.of(Double.parseDouble(value.getRawValue()));
5✔
4262
      } catch (NumberFormatException e) {
1✔
4263
        try {
4264
          // \u221E = infinity symbol
4265
          Pattern p = Pattern.compile("\\A([+-]?)(Inf(inity)?|\u221E)\\z", Pattern.CASE_INSENSITIVE);
4✔
4266
          Matcher m = p.matcher(value.getRawValue().trim());
6✔
4267
          if (m.matches()){
3✔
4268
            if (m.group(1).equals("-")){
6✔
4269
              return ValueTypeDouble.ValueDouble.of(Double.NEGATIVE_INFINITY);
3✔
4270
            }
4271
            return ValueTypeDouble.ValueDouble.of(Double.POSITIVE_INFINITY);
3✔
4272
          }
4273
          // Try as a long
4274
          return ValueTypeDouble.ValueDouble.of((double) Long.decode(value.getRawValue()));
7✔
4275
        } catch (NumberFormatException e2) {
1✔
4276
            throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_PARSE, value.getRawValue(),
16✔
4277
                    Component.translatable(ValueTypes.DOUBLE.getTranslationKey())));
3✔
4278
        }
4279
      }
4280
    }));
4281

4282
    /**
4283
     * Integer Parse operator which takes a string of a form Integer.decode() can consume.
4284
     */
4285
    public static final IOperator PARSE_INTEGER = Operators.REGISTRY.register(new ParseOperator<>(ValueTypes.INTEGER, v -> {
8✔
4286
      ValueTypeString.ValueString value = v.getValue(0, ValueTypes.STRING);
6✔
4287
      try{
4288
        return ValueTypeInteger.ValueInteger.of(Integer.decode(value.getRawValue()));
6✔
4289
      } catch (NumberFormatException e) {
1✔
4290
          throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_PARSE, value.getRawValue(),
16✔
4291
                  Component.translatable(ValueTypes.INTEGER.getTranslationKey())));
3✔
4292
      }
4293
    }));
4294

4295
    /**
4296
     * Long Parse operator which takes a string of a form Long.decode() can consume.
4297
     */
4298
    public static final IOperator PARSE_LONG = Operators.REGISTRY.register(new ParseOperator<>(ValueTypes.LONG, v -> {
8✔
4299
      ValueTypeString.ValueString value = v.getValue(0, ValueTypes.STRING);
6✔
4300
      try {
4301
        return ValueTypeLong.ValueLong.of(Long.decode(value.getRawValue()));
6✔
4302
      } catch (NumberFormatException e) {
1✔
4303
          throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_PARSE, value.getRawValue(),
16✔
4304
                  Component.translatable(ValueTypes.LONG.getTranslationKey())));
3✔
4305
      }
4306
    }));
4307

4308
    /**
4309
     * NBT Parse operator which takes a string of a form ValueTypeNbt().deserialize() can consume.
4310
     */
4311
    public static final IOperator PARSE_NBT = Operators.REGISTRY.register(new ParseOperator<>(ValueTypes.NBT, v -> {
8✔
4312
      ValueTypeString.ValueString value = v.getValue(0, ValueTypes.STRING);
6✔
4313
      try {
4314
        return ValueTypeNbt.ValueNbt.of(Helpers.TAG_PARSER.parseFully(value.getRawValue()));
7✔
4315
      } catch (CommandSyntaxException e) {
1✔
4316
        throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_PARSE, value.getRawValue(),
16✔
4317
                Component.translatable(ValueTypes.NBT.getTranslationKey())));
3✔
4318
      }
4319
    }));
4320

4321
    /**
4322
     * ----------------------------------- GENERAL OPERATORS -----------------------------------
4323
     */
4324

4325
    /**
4326
     * Choice operator with one boolean input, two any inputs and one output any.
4327
     */
4328
    public static final GeneralOperator GENERAL_CHOICE = REGISTRY.register(new GeneralChoiceOperator("?", "choice", "choice"));
10✔
4329

4330
    /**
4331
     * Identity operator with one any input and one any output
4332
     */
4333
    public static final GeneralOperator GENERAL_IDENTITY = REGISTRY.register(new GeneralIdentityOperator("id", "identity", "identity"));
10✔
4334

4335
    /**
4336
     * Constant operator with two any inputs and one any output
4337
     */
4338
    public static final GeneralOperator GENERAL_CONSTANT = REGISTRY.register(new GeneralConstantOperator("K", "constant", "constant"));
11✔
4339

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