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

CyclopsMC / IntegratedDynamics / 19266698686

11 Nov 2025 01:11PM UTC coverage: 44.848% (-0.006%) from 44.854%
19266698686

push

github

rubensworks
Bump mod version

2582 of 8548 branches covered (30.21%)

Branch coverage included in aggregate %.

11789 of 23496 relevant lines covered (50.17%)

2.38 hits per line

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

85.49
/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 lombok.Lombok;
9
import net.minecraft.ResourceLocationException;
10
import net.minecraft.core.component.DataComponentPatch;
11
import net.minecraft.core.component.DataComponentType;
12
import net.minecraft.core.component.DataComponents;
13
import net.minecraft.core.component.TypedDataComponent;
14
import net.minecraft.core.registries.BuiltInRegistries;
15
import net.minecraft.nbt.*;
16
import net.minecraft.network.chat.Component;
17
import net.minecraft.network.chat.MutableComponent;
18
import net.minecraft.resources.ResourceLocation;
19
import net.minecraft.util.StringUtil;
20
import net.minecraft.world.entity.AgeableMob;
21
import net.minecraft.world.entity.Entity;
22
import net.minecraft.world.entity.LivingEntity;
23
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
24
import net.minecraft.world.entity.ai.attributes.Attributes;
25
import net.minecraft.world.entity.animal.Animal;
26
import net.minecraft.world.entity.decoration.ItemFrame;
27
import net.minecraft.world.entity.item.ItemEntity;
28
import net.minecraft.world.entity.monster.Enemy;
29
import net.minecraft.world.entity.player.Player;
30
import net.minecraft.world.entity.projectile.ProjectileUtil;
31
import net.minecraft.world.entity.vehicle.AbstractMinecart;
32
import net.minecraft.world.item.BlockItem;
33
import net.minecraft.world.item.Item;
34
import net.minecraft.world.item.ItemStack;
35
import net.minecraft.world.item.TooltipFlag;
36
import net.minecraft.world.item.crafting.RecipeType;
37
import net.minecraft.world.level.ClipContext;
38
import net.minecraft.world.level.block.Block;
39
import net.minecraft.world.level.block.SoundType;
40
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
41
import net.minecraft.world.level.block.state.BlockState;
42
import net.minecraft.world.level.block.state.properties.Property;
43
import net.minecraft.world.level.material.Fluid;
44
import net.minecraft.world.phys.*;
45
import net.neoforged.neoforge.capabilities.Capabilities;
46
import net.neoforged.neoforge.common.IShearable;
47
import net.neoforged.neoforge.common.SoundActions;
48
import net.neoforged.neoforge.energy.IEnergyStorage;
49
import net.neoforged.neoforge.event.EventHooks;
50
import net.neoforged.neoforge.fluids.FluidStack;
51
import net.neoforged.neoforge.items.IItemHandler;
52
import net.neoforged.neoforge.server.ServerLifecycleHooks;
53
import org.apache.commons.lang3.tuple.Pair;
54
import org.apache.commons.lang3.tuple.Triple;
55
import org.cyclops.commoncapabilities.api.capability.itemhandler.ItemMatch;
56
import org.cyclops.commoncapabilities.api.capability.recipehandler.IPrototypedIngredientAlternatives;
57
import org.cyclops.commoncapabilities.api.capability.recipehandler.IRecipeDefinition;
58
import org.cyclops.commoncapabilities.api.capability.recipehandler.PrototypedIngredientAlternativesList;
59
import org.cyclops.commoncapabilities.api.capability.recipehandler.RecipeDefinition;
60
import org.cyclops.commoncapabilities.api.ingredient.*;
61
import org.cyclops.cyclopscore.helper.BlockHelpers;
62
import org.cyclops.cyclopscore.helper.FluidHelpers;
63
import org.cyclops.cyclopscore.helper.MinecraftHelpers;
64
import org.cyclops.cyclopscore.nbt.path.INbtPathExpression;
65
import org.cyclops.cyclopscore.nbt.path.NbtParseException;
66
import org.cyclops.cyclopscore.nbt.path.NbtPath;
67
import org.cyclops.integrateddynamics.IntegratedDynamics;
68
import org.cyclops.integrateddynamics.api.evaluate.EvaluationException;
69
import org.cyclops.integrateddynamics.api.evaluate.operator.IOperator;
70
import org.cyclops.integrateddynamics.api.evaluate.operator.IOperatorRegistry;
71
import org.cyclops.integrateddynamics.api.evaluate.variable.*;
72
import org.cyclops.integrateddynamics.api.logicprogrammer.IConfigRenderPattern;
73
import org.cyclops.integrateddynamics.core.evaluate.IOperatorValuePropagator;
74
import org.cyclops.integrateddynamics.core.evaluate.OperatorBuilders;
75
import org.cyclops.integrateddynamics.core.evaluate.variable.*;
76
import org.cyclops.integrateddynamics.core.helper.Helpers;
77
import org.cyclops.integrateddynamics.core.helper.L10NValues;
78
import org.cyclops.integrateddynamics.core.helper.NbtHelpers;
79
import org.cyclops.integrateddynamics.core.ingredient.ExtendedIngredientsList;
80
import org.cyclops.integrateddynamics.core.ingredient.ExtendedIngredientsSingle;
81

82
import java.util.*;
83
import java.util.stream.Collectors;
84

85
/**
86
 * Collection of available operators.
87
 *
88
 * @author rubensworks
89
 */
90
public final class Operators {
×
91

92
    public static final IOperatorRegistry REGISTRY = constructRegistry();
2✔
93

94
    private static IOperatorRegistry constructRegistry() {
95
        // This also allows this registry to be used outside of a minecraft environment.
96
        if(MinecraftHelpers.isModdedEnvironment()) {
2✔
97
            return IntegratedDynamics._instance.getRegistryManager().getRegistry(IOperatorRegistry.class);
6✔
98
        } else {
99
            return OperatorRegistry.getInstance();
2✔
100
        }
101
    }
102

103
    public static void load() {}
1✔
104

105
    /**
106
     * ----------------------------------- LOGICAL OPERATORS -----------------------------------
107
     */
108

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

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

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

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

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

159
    /**
160
     * ----------------------------------- ARITHMETIC OPERATORS -----------------------------------
161
     */
162

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

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

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

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

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

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

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

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

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

235
    /**
236
     * ----------------------------------- INTEGER OPERATORS -----------------------------------
237
     */
238

239
     private static final ValueTypeInteger.ValueInteger ZERO = ValueTypeInteger.ValueInteger.of(0);
3✔
240

241
    /**
242
     * ----------------------------------- DOUBLE OPERATORS -----------------------------------
243
     */
244

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

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

264
    /**
265
     * ----------------------------------- RELATIONAL OPERATORS -----------------------------------
266
     */
267

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

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

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

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

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

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

347
    /**
348
     * ----------------------------------- BINARY OPERATORS -----------------------------------
349
     */
350

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

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

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

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

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

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

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

420
    /**
421
     * ----------------------------------- STRING OPERATORS -----------------------------------
422
     */
423

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

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

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

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

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

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

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

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

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

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

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

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

594

595
    /**
596
     * 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.
597
     */
598
    public static final IOperator STRING_REGEX_GROUP = REGISTRY.register(OperatorBuilders.STRING.symbolOperator("regex_group").interactName("regexGroup")
9✔
599
        .renderPattern(IConfigRenderPattern.PREFIX_3_LONG)
15✔
600
        .inputTypes(ValueTypes.STRING, ValueTypes.INTEGER, ValueTypes.STRING)
2✔
601
        .output(ValueTypes.STRING)
2✔
602
        .function(variables -> {
1✔
603
            ValueTypeString.ValueString pattern = variables.getValue(0, ValueTypes.STRING);
6✔
604
            ValueTypeInteger.ValueInteger group = variables.getValue(1, ValueTypes.INTEGER);
6✔
605
            ValueTypeString.ValueString str = variables.getValue(2, ValueTypes.STRING);
6✔
606
            if (group.getRawValue() < 0) {
3✔
607
                throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_GROUP_INDEXNEGATIVE));
6✔
608
            }
609
            try {
610
                Matcher m = Pattern.compile(pattern.getRawValue()).matcher(str.getRawValue());
7✔
611
                if (m.find()) {
3!
612
                    String result = m.group(group.getRawValue());
5✔
613
                    return ValueTypeString.ValueString.of(result == null ? "" : result);
5!
614
                } else {
615
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_GROUP_NOMATCH,
×
616
                            str.getRawValue(), pattern.getRawValue()));
×
617
                }
618
            } catch (PatternSyntaxException e) {
1✔
619
                throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_REGEX_INVALID,
11✔
620
                        pattern.getRawValue()));
2✔
621
            } catch (IndexOutOfBoundsException e) {
1✔
622
                throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_GROUP_NOMATCHGROUP,
11✔
623
                        str.getRawValue(), pattern.getRawValue(), group.getRawValue()));
13✔
624
            }
625
        }).build()
1✔
626
    );
627

628
    /**
629
     * 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.
630
     */
631
    public static final IOperator STRING_REGEX_GROUPS = REGISTRY.register(OperatorBuilders.STRING_2_LONG.symbolOperator("regex_groups").interactName("regexGroups")
9✔
632
        .output(ValueTypes.LIST)
2✔
633
        .function(variables -> {
1✔
634
            ValueTypeString.ValueString pattern = variables.getValue(0, ValueTypes.STRING);
6✔
635
            ValueTypeString.ValueString str = variables.getValue(1, ValueTypes.STRING);
6✔
636
            try {
637
                Matcher m = Pattern.compile(pattern.getRawValue()).matcher(str.getRawValue());
7✔
638
                if (m.find()) {
3✔
639
                    List<ValueTypeString.ValueString> values = Lists.newArrayList();
2✔
640
                    for (int i = 0; i <= m.groupCount(); i++) {
8✔
641
                        String result = m.group(i);
4✔
642
                        values.add(ValueTypeString.ValueString.of(result == null ? "" : result));
7!
643
                    }
644
                    return ValueTypeList.ValueList.ofList(ValueTypes.STRING, values);
4✔
645
                } else {
646
                    return ValueTypeList.ValueList.ofList(ValueTypes.STRING, Collections.<ValueTypeString.ValueString>emptyList());
4✔
647
                }
648
            } catch (PatternSyntaxException e) {
1✔
649
                throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_REGEX_INVALID,
11✔
650
                        pattern.getRawValue()));
2✔
651
            }
652
        }).build()
1✔
653
    );
654

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

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

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

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

747
                    // Don't allow joining on an infinite list
748
                    if (elements.getRawValue().isInfinite()) {
4✔
749
                        throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_INFINITELIST_ILLEGAL,
11✔
750
                                STRING_JOIN.getLocalizedNameFull()));
2✔
751
                    }
752

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

768
                    return ValueTypeString.ValueString.of(sb.toString());
4✔
769
                }
770
            }).build()
1✔
771
    );
772

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

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

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

802
    /**
803
     * ----------------------------------- NUMBER OPERATORS -----------------------------------
804
     */
805

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

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

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

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

842
    /**
843
     * ----------------------------------- NULLABLE OPERATORS -----------------------------------
844
     */
845

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

857
    /**
858
     * Check if something is not null
859
     */
860
    public static final IOperator NULLABLE_ISNOTNULL = REGISTRY.register(new CompositionalOperator.AppliedOperatorBuilder(LOGICAL_NOT)
13✔
861
            .apply(NULLABLE_ISNULL).build("∅", "isnotnull", "isNotNull", IConfigRenderPattern.PREFIX_1, "general"));
7✔
862

863
    /**
864
     * ----------------------------------- LIST OPERATORS -----------------------------------
865
     */
866

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

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

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

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

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

944
    /**
945
     * List contains operator that takes a list, a list element to look for and returns a boolean.
946
     */
947
    public static final IOperator LIST_CONTAINS = REGISTRY.register(OperatorBuilders.LIST
14✔
948
            .inputTypes(new IValueType[]{ValueTypes.LIST, ValueTypes.CATEGORY_ANY})
2✔
949
            .renderPattern(IConfigRenderPattern.PREFIX_2_LONG)
2✔
950
            .output(ValueTypes.BOOLEAN).symbolOperatorInteract("contains")
4✔
951
            .function(variables -> {
1✔
952
                ValueTypeList.ValueList valueList = variables.getValue(0, ValueTypes.LIST);
6✔
953
                IValueTypeListProxy<IValueType<IValue>, IValue> list = valueList.getRawValue();
3✔
954
                IValue input = variables.getValue(1);
4✔
955
                for (IValue value : list) {
10✔
956
                    if (value.equals(input)) {
4✔
957
                        return ValueTypeBoolean.ValueBoolean.of(true);
3✔
958
                    }
959
                }
1✔
960
                return ValueTypeBoolean.ValueBoolean.of(false);
3✔
961
            }).build());
1✔
962

963
    /**
964
     * List contains operator that takes a list, a predicate that maps a list element to a boolean, a list element and returns a boolean.
965
     */
966
    public static final IOperator LIST_CONTAINS_PREDICATE = REGISTRY.register(OperatorBuilders.LIST
14✔
967
            .inputTypes(new IValueType[]{ValueTypes.LIST, ValueTypes.OPERATOR})
2✔
968
            .renderPattern(IConfigRenderPattern.INFIX)
2✔
969
            .output(ValueTypes.BOOLEAN).symbolOperator("contains_p").interactName("containsPredicate")
6✔
970
            .function(variables -> {
1✔
971
                ValueTypeList.ValueList valueList = variables.getValue(0, ValueTypes.LIST);
6✔
972
                IValueTypeListProxy<IValueType<IValue>, IValue> list = valueList.getRawValue();
3✔
973
                IOperator operator = OperatorBuilders.getSafePredictate(variables.getValue(1, ValueTypes.OPERATOR));
7✔
974
                for (IValue value : list) {
10✔
975
                    IValue result = ValueHelpers.evaluateOperator(operator, value);
9✔
976
                    ValueHelpers.validatePredicateOutput(operator, result);
3✔
977
                    if (((ValueTypeBoolean.ValueBoolean) result).getRawValue()) {
4✔
978
                        return ValueTypeBoolean.ValueBoolean.of(true);
3✔
979
                    }
980
                }
1✔
981
                return ValueTypeBoolean.ValueBoolean.of(false);
3✔
982
            }).build());
1✔
983

984
    /**
985
     * List operator with one input list, and element and one output integer
986
     */
987
    public static final IOperator LIST_COUNT = REGISTRY.register(OperatorBuilders.LIST
14✔
988
            .inputTypes(new IValueType[]{ValueTypes.LIST, ValueTypes.CATEGORY_ANY})
2✔
989
            .renderPattern(IConfigRenderPattern.INFIX).output(ValueTypes.INTEGER)
4✔
990
            .symbolOperatorInteract("count")
4✔
991
            .function(new OperatorBase.IFunction() {
4✔
992
                @Override
993
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
994
                    ValueTypeList.ValueList valueList = variables.getValue(0, ValueTypes.LIST);
6✔
995
                    IValueTypeListProxy<IValueType<IValue>, IValue> list = valueList.getRawValue();
3✔
996
                    if (list.isInfinite()) {
3✔
997
                        throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_INFINITELIST_ILLEGAL,
11✔
998
                                LIST_COUNT.getLocalizedNameFull()));
2✔
999
                    }
1000
                    IValue value = variables.getValue(1);
4✔
1001
                    int count = 0;
2✔
1002
                    for (IValue listValue : list) {
10✔
1003
                        if (listValue.equals(value)) {
4✔
1004
                            count++;
1✔
1005
                        }
1006
                    }
1✔
1007
                    return ValueTypeInteger.ValueInteger.of(count);
3✔
1008
                }
1009
            }).build());
1✔
1010

1011
    /**
1012
     * List operator with one input list, a predicate and one output integer
1013
     */
1014
    public static final IOperator LIST_COUNT_PREDICATE = REGISTRY.register(OperatorBuilders.LIST
14✔
1015
            .inputTypes(new IValueType[]{ValueTypes.LIST, ValueTypes.OPERATOR})
2✔
1016
            .renderPattern(IConfigRenderPattern.INFIX).output(ValueTypes.INTEGER)
4✔
1017
            .symbolOperator("count_p").interactName("countPredicate")
6✔
1018
            .function(new OperatorBase.IFunction() {
4✔
1019
                @Override
1020
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
1021
                    ValueTypeList.ValueList valueList = variables.getValue(0, ValueTypes.LIST);
6✔
1022
                    IValueTypeListProxy<IValueType<IValue>, IValue> list = valueList.getRawValue();
3✔
1023
                    if (list.isInfinite()) {
3!
1024
                        throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_INFINITELIST_ILLEGAL,
×
1025
                                LIST_COUNT_PREDICATE.getLocalizedNameFull()));
×
1026
                    }
1027
                    IOperator operator = OperatorBuilders.getSafePredictate(variables.getValue(1, ValueTypes.OPERATOR));
7✔
1028
                    int count = 0;
2✔
1029
                    for (IValue listValue : list) {
10✔
1030
                        IValue result = ValueHelpers.evaluateOperator(operator, listValue);
9✔
1031
                        ValueHelpers.validatePredicateOutput(operator, result);
3✔
1032
                        if (((ValueTypeBoolean.ValueBoolean) result).getRawValue()) {
4✔
1033
                            count++;
1✔
1034
                        }
1035
                    }
1✔
1036
                    return ValueTypeInteger.ValueInteger.of(count);
3✔
1037
                }
1038
            }).build());
1✔
1039

1040
    /**
1041
     * Append an element to the given list
1042
     */
1043
    public static final IOperator LIST_APPEND = REGISTRY.register(OperatorBuilders.LIST
14✔
1044
            .inputTypes(new IValueType[]{ValueTypes.LIST, ValueTypes.CATEGORY_ANY})
2✔
1045
            .renderPattern(IConfigRenderPattern.INFIX).output(ValueTypes.LIST)
4✔
1046
            .symbolOperatorInteract("append")
2✔
1047
            .function(variables -> {
1✔
1048
                ValueTypeList.ValueList valueList = variables.getValue(0, ValueTypes.LIST);
6✔
1049
                IValueTypeListProxy a = valueList.getRawValue();
3✔
1050
                IValue value = variables.getValue(1);
4✔
1051
                if (!ValueHelpers.correspondsTo(a.getValueType(), value.getType())) {
6✔
1052
                    throw new EvaluationException(Component.translatable(
11✔
1053
                            L10NValues.VALUETYPE_ERROR_INVALIDLISTVALUETYPE,
1054
                            Component.translatable(a.getValueType().getTranslationKey()),
7✔
1055
                            Component.translatable(value.getType().getTranslationKey())));
4✔
1056
                }
1057
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyAppend(a, value));
7✔
1058
            }).build());
1✔
1059

1060
    /**
1061
     * Concatenate two lists
1062
     */
1063
    public static final IOperator LIST_CONCAT = REGISTRY.register(OperatorBuilders.LIST
14✔
1064
            .inputTypes(new IValueType[]{ValueTypes.LIST, ValueTypes.LIST})
2✔
1065
            .renderPattern(IConfigRenderPattern.INFIX).output(ValueTypes.LIST)
4✔
1066
            .symbolOperatorInteract("concat")
2✔
1067
            .function(variables -> {
1✔
1068
                ValueTypeList.ValueList valueList0 = variables.getValue(0, ValueTypes.LIST);
6✔
1069
                IValueTypeListProxy a = valueList0.getRawValue();
3✔
1070
                ValueTypeList.ValueList valueList1 = variables.getValue(1, ValueTypes.LIST);
6✔
1071
                IValueTypeListProxy b = valueList1.getRawValue();
3✔
1072
                if (!ValueHelpers.correspondsTo(a.getValueType(), b.getValueType())) {
6!
1073
                    throw new EvaluationException(Component.translatable(
×
1074
                            L10NValues.VALUETYPE_ERROR_INVALIDLISTVALUETYPE,
1075
                            Component.translatable(a.getValueType().getTranslationKey()),
×
1076
                            Component.translatable(b.getValueType().getTranslationKey())));
×
1077
                }
1078
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyConcat(a, b));
15✔
1079
            }).build());
1✔
1080

1081
    /**
1082
     * Build a list lazily using a start value and an operator that is applied to the previous element to get a next element.
1083
     */
1084
    public static final IOperator LIST_LAZYBUILT = REGISTRY.register(OperatorBuilders.LIST
14✔
1085
            .inputTypes(new IValueType[]{ValueTypes.CATEGORY_ANY, ValueTypes.OPERATOR})
2✔
1086
            .renderPattern(IConfigRenderPattern.INFIX).output(ValueTypes.LIST)
4✔
1087
            .symbolOperator("lazybuilt").interactName("lazyBuilt")
4✔
1088
            .function(variables -> {
1✔
1089
                IValue a = variables.getValue(0);
4✔
1090
                IOperator operator = OperatorBuilders.getSafeOperator(variables.getValue(1, ValueTypes.OPERATOR), a.getType());
9✔
1091
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyLazyBuilt<>(a, operator));
7✔
1092
            }).build());
1✔
1093

1094
    /**
1095
     * Get the first element of the given list.
1096
     */
1097
    public static final IOperator LIST_HEAD = REGISTRY.register(OperatorBuilders.LIST_1_PREFIX
10✔
1098
            .inputTypes(new IValueType[]{ValueTypes.LIST}).output(ValueTypes.CATEGORY_ANY)
4✔
1099
            .renderPattern(IConfigRenderPattern.PREFIX_1_LONG).symbolOperatorInteract("head")
4✔
1100
            .function(variables -> {
2✔
1101
                ValueTypeList.ValueList list = variables.getValue(0, ValueTypes.LIST);
6✔
1102
                IValueTypeListProxy a = list.getRawValue();
3✔
1103
                if (a.getLength() > 0) {
3!
1104
                    return a.get(0);
4✔
1105
                } else {
1106
                    throw new EvaluationException(Component.translatable(
×
1107
                            L10NValues.OPERATOR_ERROR_INDEXOUTOFBOUNDS, 0, a.getLength()));
×
1108
                }
1109
            }).conditionalOutputTypeDeriver((operator, input) -> {
1✔
1110
                try {
1111
                    IValueTypeListProxy a = ((ValueTypeList.ValueList) input[0].getValue()).getRawValue();
×
1112
                    return a.getValueType();
×
1113
                } catch (EvaluationException e) {
×
1114
                    return operator.getOutputType();
×
1115
                }
1116
            }).build());
1✔
1117

1118
    /**
1119
     * Append an element to the given list.
1120
     */
1121
    public static final IOperator LIST_TAIL = REGISTRY.register(OperatorBuilders.LIST
10✔
1122
            .inputTypes(new IValueType[]{ValueTypes.LIST})
2✔
1123
            .renderPattern(IConfigRenderPattern.PREFIX_1_LONG).output(ValueTypes.LIST)
4✔
1124
            .symbolOperatorInteract("tail")
2✔
1125
            .function(variables -> {
1✔
1126
                ValueTypeList.ValueList list = variables.getValue(0, ValueTypes.LIST);
6✔
1127
                IValueTypeListProxy a = list.getRawValue();
3✔
1128
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyTail(a));
6✔
1129
            }).build());
1✔
1130

1131
    /**
1132
     * Deduplicate the given list elements based on the given predicate.
1133
     */
1134
    public static final IOperator LIST_UNIQ_PREDICATE = REGISTRY.register(OperatorBuilders.LIST
14✔
1135
            .inputTypes(new IValueType[]{ValueTypes.LIST, ValueTypes.OPERATOR})
2✔
1136
            .renderPattern(IConfigRenderPattern.INFIX).output(ValueTypes.LIST)
4✔
1137
            .symbolOperator("uniq_p").interactName("uniquePredicate")
4✔
1138
            .function(variables -> {
1✔
1139
                ValueTypeList.ValueList valueList = variables.getValue(0, ValueTypes.LIST);
6✔
1140
                IValueTypeListProxy<IValueType<IValue>, IValue> list = valueList.getRawValue();
3✔
1141
                final IOperator operator = OperatorBuilders.getSafePredictate(variables.getValue(1, ValueTypes.OPERATOR));
7✔
1142
                List<IValue> values = new ArrayList<>();
4✔
1143
                outerLoop:
1144
                for(IValue value : list) {
10✔
1145
                    for(IValue existing : values) {
10✔
1146
                        IValue result;
1147
                        try {
1148
                            result = ValueHelpers.evaluateOperator(operator, value, existing);
13✔
1149
                            ValueHelpers.validatePredicateOutput(operator, result);
3✔
1150
                        } catch (EvaluationException e) {
×
1151
                            throw Lombok.sneakyThrow(e);
×
1152
                        }
1✔
1153
                        if(((ValueTypeBoolean.ValueBoolean) result).getRawValue()) continue outerLoop;
5✔
1154
                    }
1✔
1155
                    values.add(value);
4✔
1156
                }
1✔
1157
                return ValueTypeList.ValueList.ofList(list.getValueType(), values);
5✔
1158
            }).build());
1✔
1159

1160
    /**
1161
     * Deduplicate the given list elements.
1162
     */
1163
    public static final IOperator LIST_UNIQ = REGISTRY.register(OperatorBuilders.LIST
5✔
1164
            .inputType(ValueTypes.LIST)
2✔
1165
            .renderPattern(IConfigRenderPattern.PREFIX_1_LONG).output(ValueTypes.LIST)
4✔
1166
            .symbolOperator("uniq").interactName("unique")
4✔
1167
            .function(variables -> {
1✔
1168
                ValueTypeList.ValueList valueList =variables.getValue(0, ValueTypes.LIST);
6✔
1169
                IValueTypeListProxy<IValueType<IValue>, IValue> list = valueList.getRawValue();
3✔
1170
                return ValueTypeList.ValueList.ofList(list.getValueType(), new ArrayList<>(Sets.newLinkedHashSet(list)));
9✔
1171
            }).build());
1✔
1172

1173
    /**
1174
     * Take a subset of the given list from the given index (inclusive) to the given index (exclusive).
1175
     */
1176
    public static final IOperator LIST_SLICE = REGISTRY.register(OperatorBuilders.LIST
18✔
1177
            .inputTypes(ValueTypes.LIST, ValueTypes.INTEGER, ValueTypes.INTEGER)
2✔
1178
            .renderPattern(IConfigRenderPattern.PREFIX_3).output(ValueTypes.LIST)
4✔
1179
            .symbolOperatorInteract("slice")
2✔
1180
            .function(variables -> {
1✔
1181
                ValueTypeList.ValueList valueList =variables.getValue(0, ValueTypes.LIST);
6✔
1182
                IValueTypeListProxy<IValueType<IValue>, IValue> list = valueList.getRawValue();
3✔
1183
                ValueTypeInteger.ValueInteger from = variables.getValue(1, ValueTypes.INTEGER);
6✔
1184
                ValueTypeInteger.ValueInteger to = variables.getValue(2, ValueTypes.INTEGER);
6✔
1185
                if (from.getRawValue() >= to.getRawValue()) {
5✔
1186
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_SLICE_TOGREATERTHANFROM));
6✔
1187
                }
1188
                if (from.getRawValue() < 0 || to.getRawValue() < 0){
6!
1189
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_SLICE_INDEXNEGATIVE));
6✔
1190
                }
1191
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxySlice<>(list, from.getRawValue(), to.getRawValue()));
10✔
1192
            }).build());
1✔
1193

1194
    public static final IOperator LIST_INTERSECTION = REGISTRY.register(OperatorBuilders.LIST
14✔
1195
            .inputTypes(ValueTypes.LIST, ValueTypes.LIST)
2✔
1196
            .renderPattern(IConfigRenderPattern.INFIX).output(ValueTypes.LIST)
4✔
1197
            .symbol("∩").operatorInteract("intersection")
6✔
1198
            .function(new OperatorBase.IFunction() {
4✔
1199
                @Override
1200
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
1201
                    IValueTypeListProxy<IValueType<IValue>, IValue> rawList1 = variables.getValue(0, ValueTypes.LIST).getRawValue();
7✔
1202
                    IValueTypeListProxy<IValueType<IValue>, IValue> rawList2 = variables.getValue(1, ValueTypes.LIST).getRawValue();
7✔
1203
                    if (rawList1.isInfinite() || rawList2.isInfinite()) {
6!
1204
                        throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_INFINITELIST_ILLEGAL,
×
1205
                                LIST_INTERSECTION.getLocalizedNameFull()));
×
1206
                    }
1207
                    LinkedHashSet<IValue> result = Sets.newLinkedHashSet(rawList1);
3✔
1208
                    result.retainAll(Sets.newLinkedHashSet(rawList2));
5✔
1209

1210
                    return ValueTypeList.ValueList.ofList(rawList1.getValueType(), result.stream().toList());
7✔
1211
                }
1212
            }).build());
1✔
1213

1214
    /**
1215
     * Test list equality using set semantics.
1216
     */
1217
    public static final IOperator LIST_EQUALS_SET = REGISTRY.register(OperatorBuilders.LIST
14✔
1218
            .inputTypes(new IValueType[]{ValueTypes.LIST, ValueTypes.LIST})
2✔
1219
            .renderPattern(IConfigRenderPattern.INFIX).output(ValueTypes.BOOLEAN)
4✔
1220
            .symbol("=set=").operatorInteract("equals_set")
4✔
1221
            .function(variables -> {
1✔
1222
                ValueTypeList.ValueList valueList0 = variables.getValue(0, ValueTypes.LIST);
6✔
1223
                IValueTypeListProxy a = valueList0.getRawValue();
3✔
1224
                ValueTypeList.ValueList valueList1 = variables.getValue(1, ValueTypes.LIST);
6✔
1225
                IValueTypeListProxy b = valueList1.getRawValue();
3✔
1226
                if (!ValueHelpers.correspondsTo(a.getValueType(), b.getValueType())) {
6!
1227
                    throw new EvaluationException(Component.translatable(
×
1228
                            L10NValues.VALUETYPE_ERROR_INVALIDLISTVALUETYPE,
1229
                            Component.translatable(a.getValueType().getTranslationKey()),
×
1230
                            Component.translatable(b.getValueType().getTranslationKey())));
×
1231
                }
1232
                Set<Object> setA = Sets.newHashSet(a);
3✔
1233
                Set<Object> setB = Sets.newHashSet(b);
3✔
1234
                return ValueTypeBoolean.ValueBoolean.of(setA.equals(setB));
5✔
1235
            }).build());
1✔
1236

1237
    /**
1238
     * Test list equality using multiset semantics.
1239
     */
1240
    public static final IOperator LIST_EQUALS_MULTISET = REGISTRY.register(OperatorBuilders.LIST
14✔
1241
            .inputTypes(new IValueType[]{ValueTypes.LIST, ValueTypes.LIST})
2✔
1242
            .renderPattern(IConfigRenderPattern.INFIX).output(ValueTypes.BOOLEAN)
4✔
1243
            .symbol("=multiset=").operatorInteract("equals_multiset")
4✔
1244
            .function(variables -> {
1✔
1245
                ValueTypeList.ValueList valueList0 = variables.getValue(0, ValueTypes.LIST);
6✔
1246
                IValueTypeListProxy a = valueList0.getRawValue();
3✔
1247
                ValueTypeList.ValueList valueList1 = variables.getValue(1, ValueTypes.LIST);
6✔
1248
                IValueTypeListProxy b = valueList1.getRawValue();
3✔
1249
                if (!ValueHelpers.correspondsTo(a.getValueType(), b.getValueType())) {
6!
1250
                    throw new EvaluationException(Component.translatable(
×
1251
                            L10NValues.VALUETYPE_ERROR_INVALIDLISTVALUETYPE,
1252
                            Component.translatable(a.getValueType().getTranslationKey()),
×
1253
                            Component.translatable(b.getValueType().getTranslationKey())));
×
1254
                }
1255
                Multiset<Object> setA = HashMultiset.create(a);
3✔
1256
                Multiset<Object> setB = HashMultiset.create(b);
3✔
1257
                return ValueTypeBoolean.ValueBoolean.of(setA.equals(setB));
5✔
1258
            }).build());
1✔
1259

1260
    /**
1261
     * ----------------------------------- BLOCK OBJECT OPERATORS -----------------------------------
1262
     */
1263

1264
    /**
1265
     * Block isOpaque operator with one input block and one output boolean.
1266
     */
1267
    public static final IOperator OBJECT_BLOCK_OPAQUE = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG.output(ValueTypes.BOOLEAN).symbolOperator("opaque").interactName("isOpaque")
11✔
1268
            .function(variables -> {
1✔
1269
                ValueObjectTypeBlock.ValueBlock a = variables.getValue(0, ValueTypes.OBJECT_BLOCK);
6✔
1270
                return ValueTypeBoolean.ValueBoolean.of(a.getRawValue().isPresent() && a.getRawValue().get().isSolidRender(null, null));
17!
1271
            }).build());
1✔
1272

1273
    /**
1274
     * The itemstack representation of the block
1275
     */
1276
    public static final IOperator OBJECT_BLOCK_ITEMSTACK = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG.output(ValueTypes.OBJECT_ITEMSTACK).symbolOperator("itemstack").interactName("itemStack")
11✔
1277
            .function(variables -> {
1✔
1278
                ValueObjectTypeBlock.ValueBlock a = variables.getValue(0, ValueTypes.OBJECT_BLOCK);
6✔
1279
                return ValueObjectTypeItemStack.ValueItemStack.of(a.getRawValue().isPresent() ? BlockHelpers.getItemStackFromBlockState(a.getRawValue().get()) : ItemStack.EMPTY);
12!
1280
            }).build());
1✔
1281

1282
    /**
1283
     * The name of the mod owning this block
1284
     */
1285
    public static final IOperator OBJECT_BLOCK_MODNAME = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG.output(ValueTypes.STRING).symbolOperatorInteract("mod")
20✔
1286
            .function(new IterativeFunction(Lists.newArrayList(
3✔
1287
                    (OperatorBase.SafeVariablesGetter variables) -> {
1288
                        ValueObjectTypeBlock.ValueBlock a = variables.getValue(0, ValueTypes.OBJECT_BLOCK);
6✔
1289
                        return a.getRawValue().isPresent() ? BuiltInRegistries.BLOCK.getKey(a.getRawValue().get().getBlock()) : ResourceLocation.parse("");
13!
1290
                    },
1291
                    OperatorBuilders.PROPAGATOR_RESOURCELOCATION_MODNAME
1292
            ))).build());
1✔
1293

1294
    /**
1295
     * The breaksound of the block
1296
     */
1297
    public static final IOperator OBJECT_BLOCK_BREAKSOUND = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG.output(ValueTypes.STRING)
7✔
1298
            .symbol("break_sound").operatorName("breaksound").interactName("breakSound")
21✔
1299
            .function(new IterativeFunction(Lists.newArrayList(
3✔
1300
                    OperatorBuilders.BLOCK_SOUND,
1301
                    (Optional<SoundType> sound) -> sound.isPresent() ? sound.get().getBreakSound().getLocation().toString() : "",
11!
1302
                    OperatorBuilders.PROPAGATOR_STRING_VALUE
1303
            ))).build());
1✔
1304
    /**
1305
     * The placesound of the block
1306
     */
1307
    public static final IOperator OBJECT_BLOCK_PLACESOUND = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG.output(ValueTypes.STRING)
7✔
1308
            .symbol("place_sound").operatorName("placesound").interactName("placeSound")
21✔
1309
            .function(new IterativeFunction(Lists.newArrayList(
3✔
1310
                    OperatorBuilders.BLOCK_SOUND,
1311
                    (Optional<SoundType> sound) -> sound.isPresent() ? sound.get().getPlaceSound().getLocation().toString() : "",
11!
1312
                    OperatorBuilders.PROPAGATOR_STRING_VALUE
1313
            ))).build());
1✔
1314
    /**
1315
     * The stepsound of the block
1316
     */
1317
    public static final IOperator OBJECT_BLOCK_STEPSOUND = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG.output(ValueTypes.STRING)
7✔
1318
            .symbol("step_sound").operatorName("stepsound").interactName("stepSound")
21✔
1319
            .function(new IterativeFunction(Lists.newArrayList(
3✔
1320
                    OperatorBuilders.BLOCK_SOUND,
1321
                    (Optional<SoundType> sound) -> sound.isPresent() ? sound.get().getStepSound().getLocation().toString() : "",
11!
1322
                    OperatorBuilders.PROPAGATOR_STRING_VALUE
1323
            ))).build());
1✔
1324

1325
    /**
1326
     * If the block is shearable
1327
     */
1328
    public static final IOperator OBJECT_BLOCK_ISSHEARABLE = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG.output(ValueTypes.BOOLEAN)
7✔
1329
            .symbol("is_shearable").operatorName("isshearable").interactName("isShearable")
6✔
1330
            .function(variables -> {
1✔
1331
                ValueObjectTypeBlock.ValueBlock a = variables.getValue(0, ValueTypes.OBJECT_BLOCK);
6✔
1332
                return ValueTypeBoolean.ValueBoolean.of(a.getRawValue().isPresent()
7!
1333
                        && a.getRawValue().get().getBlock() instanceof IShearable
7✔
1334
                        && ((IShearable) a.getRawValue().get().getBlock()).isShearable(null, ItemStack.EMPTY, null, null));
14!
1335
            }).build());
1✔
1336

1337
    /**
1338
     * The block when this block is planted
1339
     */
1340
    public static final IOperator OBJECT_BLOCK_PLANTAGE = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG
5✔
1341
            .output(ValueTypes.INTEGER).symbol("plant_age").operatorName("plantage").interactName("plantAge")
8✔
1342
            .function(variables -> {
1✔
1343
                ValueObjectTypeBlock.ValueBlock a = variables.getValue(0, ValueTypes.OBJECT_BLOCK);
6✔
1344
                int age = 0;
2✔
1345
                if (a.getRawValue().isPresent()) {
4!
1346
                    for (Property<?> prop : a.getRawValue().get().getProperties()) {
14✔
1347
                        if (prop.getName().equals("age") && prop.getValueClass() == Integer.class) {
9!
1348
                            age = (Integer) a.getRawValue().get().getValue(prop);
9✔
1349
                        }
1350
                    }
1✔
1351
                }
1352
                return ValueTypeInteger.ValueInteger.of(age);
3✔
1353
            }).build());
1✔
1354

1355
    /**
1356
     * Get a block by name.
1357
     */
1358
    public static final IOperator OBJECT_BLOCK_BY_NAME = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG
5✔
1359
            .inputType(ValueTypes.STRING).output(ValueTypes.OBJECT_BLOCK)
4✔
1360
            .symbol("block_by_name").operatorName("blockbyname").interactName("blockByName")
7✔
1361
            .function(OperatorBuilders.FUNCTION_STRING_TO_RESOURCE_LOCATION
1✔
1362
                    .build(input -> {
1✔
1363
                        Block block = BuiltInRegistries.BLOCK.get(input);
5✔
1364
                        return ValueObjectTypeBlock.ValueBlock.of(block.defaultBlockState());
4✔
1365
                    })).build());
1✔
1366

1367
    /**
1368
     * Get the block properties as NBT compound tag.
1369
     */
1370
    public static final IOperator OBJECT_BLOCK_PROPERTIES = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG
5✔
1371
            .output(ValueTypes.NBT)
2✔
1372
            .symbol("block_props").operatorName("blockproperties").interactName("properties")
6✔
1373
            .function(variables -> {
1✔
1374
                ValueObjectTypeBlock.ValueBlock a = variables.getValue(0, ValueTypes.OBJECT_BLOCK);
6✔
1375
                return ValueTypeNbt.ValueNbt.of(a.getRawValue().map(blockState -> {
6✔
1376
                    CompoundTag tag = new CompoundTag();
4✔
1377
                    for (Property property : blockState.getProperties()) {
11✔
1378
                        Comparable<?> value = blockState.getValue(property);
4✔
1379
                        tag.putString(property.getName(), property.getName(value));
7✔
1380
                    }
1✔
1381
                    return tag;
2✔
1382
                }));
1383
            }).build());
1✔
1384

1385
    /**
1386
     * Get the given block applied with the given properties.
1387
     */
1388
    public static final IOperator OBJECT_BLOCK_WITH_PROPERTIES = REGISTRY.register(OperatorBuilders.BLOCK_INFIX_VERYLONG
14✔
1389
            .inputTypes(ValueTypes.OBJECT_BLOCK, ValueTypes.NBT).output(ValueTypes.OBJECT_BLOCK)
4✔
1390
            .symbol("block_with_props").operatorName("blockfromproperties").interactName("withProperties")
6✔
1391
            .function(variables -> {
1✔
1392
                ValueObjectTypeBlock.ValueBlock a = variables.getValue(0, ValueTypes.OBJECT_BLOCK);
6✔
1393
                ValueTypeNbt.ValueNbt b = variables.getValue(1, ValueTypes.NBT);
6✔
1394
                if (a.getRawValue().isPresent() && a.getRawValue().isPresent()) {
8!
1395
                    BlockState blockState = a.getRawValue().get();
5✔
1396
                    Tag tagRaw = b.getRawValue().get();
5✔
1397
                    if (tagRaw instanceof CompoundTag) {
3!
1398
                        CompoundTag tag = (CompoundTag) tagRaw;
3✔
1399
                        for (Property property : blockState.getProperties()) {
11✔
1400
                            if (tag.contains(property.getName(), Tag.TAG_STRING)) {
6!
1401
                                Optional<Comparable> valueOptional = property.getValue(tag.getString(property.getName()));
7✔
1402
                                if (valueOptional.isPresent()) {
3!
1403
                                    blockState = blockState.setValue(property, valueOptional.get());
8✔
1404
                                }
1405
                            }
1406
                        }
1✔
1407
                        return ValueObjectTypeBlock.ValueBlock.of(blockState);
3✔
1408
                    }
1409
                }
1410
                return a;
×
1411
            }).build());
1✔
1412

1413
    /**
1414
     * Get all possible block properties as NBT compound tag with list values.
1415
     */
1416
    public static final IOperator OBJECT_BLOCK_POSSIBLE_PROPERTIES = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG
5✔
1417
            .output(ValueTypes.NBT)
2✔
1418
            .symbol("block_all_props").operatorName("blockpossibleproperties").interactName("possibleProperties")
6✔
1419
            .function(variables -> {
1✔
1420
                ValueObjectTypeBlock.ValueBlock a = variables.getValue(0, ValueTypes.OBJECT_BLOCK);
6✔
1421
                return ValueTypeNbt.ValueNbt.of(a.getRawValue().map(blockState -> {
6✔
1422
                    CompoundTag tag = new CompoundTag();
4✔
1423
                    for (Property property : blockState.getProperties()) {
11✔
1424
                        ListTag list = new ListTag();
4✔
1425
                        for (Comparable value : (Collection<Comparable>) property.getPossibleValues()) {
11✔
1426
                            list.add(StringTag.valueOf(property.getName(value)));
7✔
1427
                        }
1✔
1428
                        tag.put(property.getName(), list);
6✔
1429
                    }
1✔
1430
                    return tag;
2✔
1431
                }));
1432
            }).build());
1✔
1433

1434
    /**
1435
     * The tag entries of the given block
1436
     */
1437
    public static final IOperator OBJECT_BLOCK_TAG = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG
5✔
1438
            .output(ValueTypes.LIST)
2✔
1439
            .symbol("block_tag_names").operatorName("tag").interactName("tags")
6✔
1440
            .function(variables -> {
1✔
1441
                ValueObjectTypeBlock.ValueBlock a = variables.getValue(0, ValueTypes.OBJECT_BLOCK);
6✔
1442
                ImmutableList.Builder<ValueTypeString.ValueString> builder = ImmutableList.builder();
2✔
1443
                if(!a.getRawValue().isEmpty()) {
4!
1444
                    a.getRawValue().get().getBlock().builtInRegistryHolder().tags()
9✔
1445
                            .forEach(owningTag -> builder.add(ValueTypeString.ValueString
6✔
1446
                                    .of(owningTag.location().toString())));
3✔
1447
                }
1448
                return ValueTypeList.ValueList.ofList(ValueTypes.STRING, builder.build());
5✔
1449
            }).build());
1✔
1450

1451
    /**
1452
     * Get a list of blocks that correspond to the given tag key.
1453
     */
1454
    public static final IOperator OBJECT_BLOCK_TAG_STACKS = REGISTRY.register(OperatorBuilders.STRING_1_PREFIX
5✔
1455
            .output(ValueTypes.LIST)
2✔
1456
            .symbol("block_tag_values").operatorName("blocktag").interactName("blocksByTag")
6✔
1457
            .inputType(ValueTypes.STRING).renderPattern(IConfigRenderPattern.SUFFIX_1_LONG)
4✔
1458
            .function(variables -> {
1✔
1459
                ValueTypeString.ValueString a = variables.getValue(0, ValueTypes.STRING);
6✔
1460
                ImmutableList.Builder<ValueObjectTypeBlock.ValueBlock> builder = ImmutableList.builder();
2✔
1461
                if (!StringUtil.isNullOrEmpty(a.getRawValue())) {
4!
1462
                    try {
1463
                        Helpers.getBlockTagValues(a.getRawValue())
4✔
1464
                                .map(ValueObjectTypeBlock.ValueBlock::of)
3✔
1465
                                .forEach(builder::add);
4✔
1466
                    } catch (ResourceLocationException e) {
×
1467
                        throw new EvaluationException(Component.translatable(e.getMessage()));
×
1468
                    }
1✔
1469
                }
1470
                return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_BLOCK, builder.build());
5✔
1471
            }).build());
1✔
1472

1473
    /**
1474
     * ----------------------------------- ITEM STACK OBJECT OPERATORS -----------------------------------
1475
     */
1476

1477
    /**
1478
     * Item Stack size operator with one input itemstack and one output integer.
1479
     */
1480
    public static final IOperator OBJECT_ITEMSTACK_SIZE = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1481
            .output(ValueTypes.INTEGER).symbolOperator("size").interactName("size")
7✔
1482
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_INT.build(
2✔
1483
                itemStack -> !itemStack.isEmpty() ? itemStack.getCount() : 0
8!
1484
            )).build());
1✔
1485

1486
    /**
1487
     * Item Stack maxsize operator with one input itemstack and one output integer.
1488
     */
1489
    public static final IOperator OBJECT_ITEMSTACK_MAXSIZE = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1490
            .output(ValueTypes.INTEGER).symbolOperator("maxsize").interactName("maxSize")
7✔
1491
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_INT.build(
2✔
1492
                itemStack -> !itemStack.isEmpty() ? itemStack.getMaxStackSize() : 0
8!
1493
            )).build());
1✔
1494

1495
    /**
1496
     * Item Stack isstackable operator with one input itemstack and one output boolean.
1497
     */
1498
    public static final IOperator OBJECT_ITEMSTACK_ISSTACKABLE = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1499
            .output(ValueTypes.BOOLEAN).symbolOperator("stackable").interactName("isStackable")
7✔
1500
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_BOOLEAN.build(
2✔
1501
                itemStack -> !itemStack.isEmpty() && itemStack.isStackable()
11!
1502
            )).build());
1✔
1503

1504
    /**
1505
     * Item Stack isdamageable operator with one input itemstack and one output boolean.
1506
     */
1507
    public static final IOperator OBJECT_ITEMSTACK_ISDAMAGEABLE = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1508
            .output(ValueTypes.BOOLEAN).symbolOperator("damageable").interactName("isDamageable")
7✔
1509
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_BOOLEAN.build(
2✔
1510
                itemStack -> !itemStack.isEmpty() && itemStack.isDamageableItem()
11!
1511
            )).build());
1✔
1512

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

1522
    /**
1523
     * Item Stack maxdamage operator with one input itemstack and one output integer.
1524
     */
1525
    public static final IOperator OBJECT_ITEMSTACK_MAXDAMAGE = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1526
            .output(ValueTypes.INTEGER).symbol("max_damage").operatorName("maxdamage").interactName("maxDamage")
9✔
1527
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_INT.build(
2✔
1528
                itemStack -> !itemStack.isEmpty() ? itemStack.getMaxDamage() : 0
8!
1529
            )).build());
1✔
1530

1531
    /**
1532
     * Item Stack isenchanted operator with one input itemstack and one output boolean.
1533
     */
1534
    public static final IOperator OBJECT_ITEMSTACK_ISENCHANTED = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1535
            .output(ValueTypes.BOOLEAN).symbolOperator("enchanted").interactName("isEnchanted")
7✔
1536
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_BOOLEAN.build(
2✔
1537
                itemStack -> !itemStack.isEmpty() && itemStack.isEnchanted()
11!
1538
            )).build());
1✔
1539

1540
    /**
1541
     * Item Stack isenchantable operator with one input itemstack and one output boolean.
1542
     */
1543
    public static final IOperator OBJECT_ITEMSTACK_ISENCHANTABLE = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1544
            .output(ValueTypes.BOOLEAN).symbolOperator("enchantable").interactName("isEnchantable")
7✔
1545
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_BOOLEAN.build(
2✔
1546
                itemStack -> !itemStack.isEmpty() && itemStack.isEnchantable()
11!
1547
            )).build());
1✔
1548

1549
    /**
1550
     * Item Stack repair cost with one input itemstack and one output integer.
1551
     */
1552
    public static final IOperator OBJECT_ITEMSTACK_REPAIRCOST = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1553
            .output(ValueTypes.INTEGER)
2✔
1554
            .symbol("repair_cost").operatorName("repaircost").interactName("repairCost")
7✔
1555
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_INT.build(
2✔
1556
                itemStack -> !itemStack.isEmpty() ? itemStack.get(DataComponents.REPAIR_COST) : 0
9!
1557
            )).build());
1✔
1558

1559
    /**
1560
     * Get the rarity of an itemstack.
1561
     */
1562
    public static final IOperator OBJECT_ITEMSTACK_RARITY = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1563
            .output(ValueTypes.STRING).symbolOperatorInteract("rarity")
4✔
1564
            .function(variables -> {
1✔
1565
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1566
                return ValueTypeString.ValueString.of(!a.getRawValue().isEmpty() ? a.getRawValue().getRarity().name() : "");
11!
1567
            }).build());
1✔
1568

1569
    /**
1570
     * Get the strength of an itemstack against a block as a double.
1571
     */
1572
    public static final IOperator OBJECT_ITEMSTACK_STRENGTH_VS_BLOCK = REGISTRY.register(OperatorBuilders.ITEMSTACK_2
14✔
1573
            .inputTypes(new IValueType[]{ValueTypes.OBJECT_ITEMSTACK, ValueTypes.OBJECT_BLOCK}).output(ValueTypes.DOUBLE)
4✔
1574
            .symbolOperatorInteract("strength")
2✔
1575
            .function(variables -> {
1✔
1576
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1577
                ValueObjectTypeBlock.ValueBlock b = variables.getValue(1, ValueTypes.OBJECT_BLOCK);
6✔
1578
                return ValueTypeDouble.ValueDouble.of(!a.getRawValue().isEmpty() && b.getRawValue().isPresent() ? a.getRawValue().getDestroySpeed(b.getRawValue().get()) : 0);
19!
1579
            }).build());
1✔
1580

1581
    /**
1582
     * If the given itemstack can be used to harvest the given block.
1583
     */
1584
    public static final IOperator OBJECT_ITEMSTACK_CAN_HARVEST_BLOCK = REGISTRY.register(OperatorBuilders.ITEMSTACK_2_LONG
14✔
1585
            .inputTypes(new IValueType[]{ValueTypes.OBJECT_ITEMSTACK, ValueTypes.OBJECT_BLOCK}).output(ValueTypes.BOOLEAN)
4✔
1586
            .symbol("can_harvest").operatorName("canharvest").interactName("canHarvest")
6✔
1587
            .function(variables -> {
1✔
1588
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1589
                ValueObjectTypeBlock.ValueBlock b = variables.getValue(1, ValueTypes.OBJECT_BLOCK);
6✔
1590
                return ValueTypeBoolean.ValueBoolean.of(!a.getRawValue().isEmpty() && b.getRawValue().isPresent() && a.getRawValue().isCorrectToolForDrops(b.getRawValue().get()));
21!
1591
            }).build());
1✔
1592

1593
    /**
1594
     * The block from the stack
1595
     */
1596
    public static final IOperator OBJECT_ITEMSTACK_BLOCK = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1597
            .output(ValueTypes.OBJECT_BLOCK).symbolOperatorInteract("block")
4✔
1598
            .function(variables -> {
1✔
1599
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1600
                return ValueObjectTypeBlock.ValueBlock.of((!a.getRawValue().isEmpty() && a.getRawValue().getItem() instanceof BlockItem) ? BlockHelpers.getBlockStateFromItemStack(a.getRawValue()) : null);
15!
1601
            }).build());
1✔
1602

1603
    /**
1604
     * If the given stack has a fluid.
1605
     */
1606
    public static final IOperator OBJECT_ITEMSTACK_ISFLUIDSTACK = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1607
            .output(ValueTypes.BOOLEAN)
2✔
1608
            .symbol("is_fluidstack").operatorName("isfluidstack").interactName("isFluidStack")
7✔
1609
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_BOOLEAN.build(
2✔
1610
                itemStack -> !itemStack.isEmpty() && !Helpers.getFluidStack(itemStack).isEmpty()
12!
1611
            )).build());
1✔
1612

1613
    /**
1614
     * The fluidstack from the stack
1615
     */
1616
    public static final IOperator OBJECT_ITEMSTACK_FLUIDSTACK = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1617
            .output(ValueTypes.OBJECT_FLUIDSTACK).symbolOperator("fluidstack").interactName("fluidStack")
6✔
1618
            .function(variables -> {
1✔
1619
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1620
                return ValueObjectTypeFluidStack.ValueFluidStack.of(!a.getRawValue().isEmpty() ? Helpers.getFluidStack(a.getRawValue()) : FluidStack.EMPTY);
11✔
1621
            }).build());
1✔
1622

1623
    /**
1624
     * The capacity of the fluidstack from the stack.
1625
     */
1626
    public static final IOperator OBJECT_ITEMSTACK_FLUIDSTACKCAPACITY = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1627
            .output(ValueTypes.INTEGER)
2✔
1628
            .symbol("fluidstack_capacity").operatorName("fluidstackcapacity").interactName("fluidCapacity")
7✔
1629
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_INT.build(
2✔
1630
                itemStack -> !itemStack.isEmpty() ? Helpers.getFluidStackCapacity(itemStack) : 0
8!
1631
            )).build());
1✔
1632

1633
    /**
1634
     * If the data components of the given stacks are equal.
1635
     */
1636
    public static final IOperator OBJECT_ITEMSTACK_ISDATAEQUAL = REGISTRY.register(OperatorBuilders.ITEMSTACK_2
5✔
1637
            .output(ValueTypes.BOOLEAN).symbol("=NBT=").operatorName("isnbtequal").interactName("isNbtEqual")
8✔
1638
            .function(variables -> {
1✔
1639
                ValueObjectTypeItemStack.ValueItemStack valueStack0 = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1640
                ValueObjectTypeItemStack.ValueItemStack valueStack1 = variables.getValue(1, ValueTypes.OBJECT_ITEMSTACK);
6✔
1641
                ItemStack a = valueStack0.getRawValue();
3✔
1642
                ItemStack b = valueStack1.getRawValue();
3✔
1643
                boolean equal = false;
2✔
1644
                if(!a.isEmpty() && !b.isEmpty()) {
6!
1645
                    equal = ItemStack.isSameItem(a, b) && ItemMatch.areItemStacksEqual(a, b, ItemMatch.DATA);
14✔
1646
                } else if(a.isEmpty() && b.isEmpty()) {
×
1647
                    equal = true;
×
1648
                }
1649
                return ValueTypeBoolean.ValueBoolean.of(equal);
3✔
1650
            }).build());
1✔
1651

1652
    /**
1653
     * If the raw items of the given stacks are equal, ignoring data components but including damage value.
1654
     */
1655
    public static final IOperator OBJECT_ITEMSTACK_ISITEMEQUALNODATA = REGISTRY.register(OperatorBuilders.ITEMSTACK_2
5✔
1656
            .output(ValueTypes.BOOLEAN).symbol("=NoNBT=").operatorName("isitemequalnonbt").interactName("isEqualNonNbt")
8✔
1657
            .function(variables -> {
1✔
1658
                ValueObjectTypeItemStack.ValueItemStack valueStack0 = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
×
1659
                ValueObjectTypeItemStack.ValueItemStack valueStack1 = variables.getValue(1, ValueTypes.OBJECT_ITEMSTACK);
×
1660
                ItemStack a = valueStack0.getRawValue();
×
1661
                ItemStack b = valueStack1.getRawValue();
×
1662
                boolean equal = false;
×
1663
                if(!a.isEmpty() && !b.isEmpty()) {
×
1664
                    equal = ItemMatch.areItemStacksEqual(a, b, ItemMatch.ITEM);
×
1665
                } else if(a.isEmpty() && b.isEmpty()) {
×
1666
                    equal = true;
×
1667
                }
1668
                return ValueTypeBoolean.ValueBoolean.of(equal);
×
1669
            }).build());
1✔
1670

1671
    /**
1672
     * If the raw items of the given stacks are equal, ignoring data components and damage value.
1673
     */
1674
    public static final IOperator OBJECT_ITEMSTACK_ISRAWITEMEQUAL = REGISTRY.register(OperatorBuilders.ITEMSTACK_2
5✔
1675
            .output(ValueTypes.BOOLEAN).symbol("=Raw=").operatorName("israwitemequal").interactName("isEqualRaw")
8✔
1676
            .function(variables -> {
1✔
1677
                ValueObjectTypeItemStack.ValueItemStack valueStack0 = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1678
                ValueObjectTypeItemStack.ValueItemStack valueStack1 = variables.getValue(1, ValueTypes.OBJECT_ITEMSTACK);
6✔
1679
                ItemStack a = valueStack0.getRawValue();
3✔
1680
                ItemStack b = valueStack1.getRawValue();
3✔
1681
                boolean equal = false;
2✔
1682
                if(!a.isEmpty() && !b.isEmpty()) {
6!
1683
                    equal = ItemMatch.areItemStacksEqual(a, b, ItemMatch.ITEM);
6✔
1684
                } else if(a.isEmpty() && b.isEmpty()) {
×
1685
                    equal = true;
×
1686
                }
1687
                return ValueTypeBoolean.ValueBoolean.of(equal);
3✔
1688
            }).build());
1✔
1689

1690
    /**
1691
     * The name of the mod owning this item
1692
     */
1693
    public static final IOperator OBJECT_ITEMSTACK_MODNAME = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG.output(ValueTypes.STRING)
7✔
1694
            .symbolOperatorInteract("mod")
13✔
1695
            .function(new IterativeFunction(Lists.newArrayList(
3✔
1696
                    (OperatorBase.SafeVariablesGetter variables) -> {
1697
                        ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1698
                        return !a.getRawValue().isEmpty() ? BuiltInRegistries.ITEM.getKey(a.getRawValue().getItem()) : ResourceLocation.parse("");
11!
1699
                    },
1700
                    OperatorBuilders.PROPAGATOR_RESOURCELOCATION_MODNAME
1701
            ))).build());
1✔
1702

1703
    /**
1704
     * The fuel burn time of the given item
1705
     */
1706
    public static final IOperator OBJECT_ITEMSTACK_FUELBURNTIME = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1707
            .output(ValueTypes.INTEGER)
2✔
1708
            .symbol("burn_time").operatorName("burntime").interactName("burnTime")
7✔
1709
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_INT.build(itemStack -> {
2✔
1710
                if (!itemStack.isEmpty()) {
3!
1711
                    int burnTime = itemStack.getBurnTime(null);
4✔
1712
                    return EventHooks.getItemBurnTime(itemStack, burnTime == -1
7!
1713
                            ? itemStack.getBurnTime(RecipeType.SMELTING)
×
1714
                            : burnTime, null);
2✔
1715
                }
1716
                return 0;
×
1717
            })).build());
1✔
1718

1719
    /**
1720
     * If the given item can be used as fuel
1721
     */
1722
    public static final IOperator OBJECT_ITEMSTACK_CANBURN = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1723
            .output(ValueTypes.BOOLEAN)
2✔
1724
            .symbol("can_burn").operatorName("canburn").interactName("canBurn")
7✔
1725
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_BOOLEAN
1✔
1726
                    .build(AbstractFurnaceBlockEntity::isFuel))
1✔
1727
            .build());
1✔
1728

1729
    /**
1730
     * The tag entries of the given item
1731
     */
1732
    public static final IOperator OBJECT_ITEMSTACK_TAG = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1733
            .output(ValueTypes.LIST)
2✔
1734
            .symbol("item_tag_names").operatorName("tag").interactName("tags")
6✔
1735
            .function(variables -> {
1✔
1736
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1737
                ImmutableList.Builder<ValueTypeString.ValueString> builder = ImmutableList.builder();
2✔
1738
                if(!a.getRawValue().isEmpty()) {
4!
1739
                    a.getRawValue().getItem().builtInRegistryHolder().tags()
7✔
1740
                            .forEach(owningTag -> builder.add(ValueTypeString.ValueString
6✔
1741
                                    .of(owningTag.location().toString())));
3✔
1742
                }
1743
                return ValueTypeList.ValueList.ofList(ValueTypes.STRING, builder.build());
5✔
1744
            }).build());
1✔
1745

1746
    /**
1747
     * Get a list of items that correspond to the given tag key.
1748
     */
1749
    public static final IOperator OBJECT_ITEMSTACK_TAG_STACKS = REGISTRY.register(OperatorBuilders.STRING_1_PREFIX
5✔
1750
            .output(ValueTypes.LIST)
2✔
1751
            .symbol("item_tag_values").operatorName("tag").interactName("itemsByTag")
6✔
1752
            .inputType(ValueTypes.STRING).renderPattern(IConfigRenderPattern.SUFFIX_1_LONG)
4✔
1753
            .function(variables -> {
1✔
1754
                ValueTypeString.ValueString a = variables.getValue(0, ValueTypes.STRING);
6✔
1755
                ImmutableList.Builder<ValueObjectTypeItemStack.ValueItemStack> builder = ImmutableList.builder();
2✔
1756
                if (!StringUtil.isNullOrEmpty(a.getRawValue())) {
4!
1757
                    try {
1758
                        Helpers.getTagValues(a.getRawValue())
4✔
1759
                                .map(ValueObjectTypeItemStack.ValueItemStack::of)
3✔
1760
                                .forEach(builder::add);
4✔
1761
                    } catch (ResourceLocationException e) {
×
1762
                        throw new EvaluationException(Component.translatable(e.getMessage()));
×
1763
                    }
1✔
1764
                }
1765
                return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_ITEMSTACK, builder.build());
5✔
1766
            }).build());
1✔
1767

1768
    /**
1769
     * ItemStack operator that applies the given stacksize to the given itemstack and creates a new ItemStack.
1770
     */
1771
    public static final IOperator OBJECT_ITEMSTACK_WITHSIZE = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_INTEGER_1
5✔
1772
            .output(ValueTypes.OBJECT_ITEMSTACK)
2✔
1773
            .symbol("with_size").operatorName("withsize").interactName("withSize")
6✔
1774
            .function(variables -> {
1✔
1775
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1776
                ValueTypeInteger.ValueInteger b = variables.getValue(1, ValueTypes.INTEGER);
6✔
1777
                if (!a.getRawValue().isEmpty()) {
4!
1778
                    ItemStack itemStack = a.getRawValue().copy();
4✔
1779
                    itemStack.setCount(b.getRawValue());
4✔
1780
                    return ValueObjectTypeItemStack.ValueItemStack.of(itemStack);
3✔
1781
                }
1782
                return a;
×
1783
            }).build());
1✔
1784

1785
    /**
1786
     * Check if the item is an RF container item
1787
     */
1788
    public static final IOperator OBJECT_ITEMSTACK_ISFECONTAINER = Operators.REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1789
            .output(ValueTypes.BOOLEAN)
2✔
1790
            .symbol("is_fe_container").operatorName("isfecontainer").interactName("isFeContainer")
7✔
1791
            .function(OperatorBuilders.FUNCTION_CONTAINERITEM_TO_BOOLEAN.build(
2✔
1792
                Objects::nonNull
1793
            )).build());
1✔
1794

1795
    /**
1796
     * Get the storage energy
1797
     */
1798
    public static final IOperator OBJECT_ITEMSTACK_STOREDFE = Operators.REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1799
            .output(ValueTypes.INTEGER)
2✔
1800
            .symbol("stored_fe").operatorName("storedfe").interactName("feStored")
7✔
1801
            .function(OperatorBuilders.FUNCTION_CONTAINERITEM_TO_INT.build(
2✔
1802
                input -> input != null ? input.getEnergyStored() : 0
8✔
1803
            )).build());
1✔
1804

1805
    /**
1806
     * Get the energy capacity
1807
     */
1808
    public static final IOperator OBJECT_ITEMSTACK_FECAPACITY = Operators.REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1809
            .output(ValueTypes.INTEGER)
2✔
1810
            .symbol("capacity_fe").operatorName("fecapacity").interactName("feCapacity")
7✔
1811
            .function(OperatorBuilders.FUNCTION_CONTAINERITEM_TO_INT.build(
2✔
1812
                input -> input != null ? input.getMaxEnergyStored() : 0
8✔
1813
            )).build());
1✔
1814

1815

1816
    /**
1817
     * If the given item has an inventory.
1818
     */
1819
    public static final IOperator OBJECT_ITEMSTACK_HASINVENTORY = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1820
            .output(ValueTypes.BOOLEAN)
2✔
1821
            .symbol("has_inventory").operatorName("hasinventory").interactName("hasInventory")
6✔
1822
            .function(variables -> {
1✔
1823
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1824
                return ValueTypeBoolean.ValueBoolean.of(!a.getRawValue().isEmpty() && a.getRawValue().getCapability(Capabilities.ItemHandler.ITEM) != null);
14!
1825
            }).build());
1✔
1826

1827

1828

1829

1830
    /**
1831
     * Retrieve the inventory size of the given item handler contents.
1832
     */
1833
    public static final IOperator OBJECT_ITEMSTACK_INVENTORYSIZE = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1834
            .output(ValueTypes.INTEGER)
2✔
1835
            .symbol("inventory_size").operatorName("inventorysize").interactName("inventorySize")
6✔
1836
            .function(variables -> {
1✔
1837
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1838
                IItemHandler itemHandler = a.getRawValue().getCapability(Capabilities.ItemHandler.ITEM);
6✔
1839
                return ValueTypeInteger.ValueInteger.of(itemHandler != null ? itemHandler.getSlots() : 0);
8✔
1840
            }).build());
1✔
1841

1842
    /**
1843
     * Retrieve the inventory of the given item handler contents.
1844
     */
1845
    public static final IOperator OBJECT_ITEMSTACK_INVENTORY = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1846
            .output(ValueTypes.LIST).symbolOperator("inventory").interactName("inventory")
6✔
1847
            .function(variables -> {
1✔
1848
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1849
                IItemHandler itemHandler = a.getRawValue().getCapability(Capabilities.ItemHandler.ITEM);
6✔
1850
                if (itemHandler != null) {
2✔
1851
                    List<ValueObjectTypeItemStack.ValueItemStack> values = Lists.newArrayListWithCapacity(itemHandler.getSlots());
4✔
1852
                    for (int i = 0; i < itemHandler.getSlots(); i++) {
8✔
1853
                        values.add(ValueObjectTypeItemStack.ValueItemStack.of(itemHandler.getStackInSlot(i)));
7✔
1854
                    }
1855
                    return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_ITEMSTACK, values);
4✔
1856
                }
1857
                return ValueTypes.LIST.getDefault();
3✔
1858
            }).build());
1✔
1859

1860
    /**
1861
     * Get an item by name.
1862
     */
1863
    public static final IOperator OBJECT_ITEMSTACK_BY_NAME = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_PREFIX_LONG
5✔
1864
            .inputType(ValueTypes.STRING).output(ValueTypes.OBJECT_ITEMSTACK)
4✔
1865
            .symbol("item_by_name").operatorName("itembyname").interactName("itemByName")
7✔
1866
            .function(OperatorBuilders.FUNCTION_STRING_TO_RESOURCE_LOCATION
1✔
1867
                    .build(input -> {
1✔
1868
                        Item item = BuiltInRegistries.ITEM.get(input);
5✔
1869
                        ItemStack itemStack = ItemStack.EMPTY;
2✔
1870
                        if (item != null) {
2!
1871
                            itemStack = new ItemStack(item);
5✔
1872
                        }
1873
                        return ValueObjectTypeItemStack.ValueItemStack.of(itemStack);
3✔
1874
                    })).build());
1✔
1875

1876
    /**
1877
     * Get the total item count of the given item in a list.
1878
     */
1879
    public static final IOperator OBJECT_ITEMSTACK_LIST_COUNT = REGISTRY.register(OperatorBuilders.ITEMSTACK_2_LONG
14✔
1880
            .inputTypes(ValueTypes.LIST, ValueTypes.OBJECT_ITEMSTACK)
2✔
1881
            .output(ValueTypes.INTEGER)
2✔
1882
            .symbol("item_list_count").operatorName("itemlistcount").interactName("itemListCount")
6✔
1883
            .function(variables -> {
1✔
1884
                ValueTypeList.ValueList<IValueType<IValue>, IValue> a = variables.getValue(0, ValueTypes.LIST);
6✔
1885
                ValueObjectTypeItemStack.ValueItemStack b = variables.getValue(1, ValueTypes.OBJECT_ITEMSTACK);
6✔
1886
                if (!ValueHelpers.correspondsTo(a.getRawValue().getValueType(), ValueTypes.OBJECT_ITEMSTACK)) {
6!
1887
                    MutableComponent error = Component.translatable(
×
1888
                            L10NValues.VALUETYPE_ERROR_INVALIDLISTVALUETYPE,
1889
                            Component.translatable(a.getRawValue().getValueType().getTranslationKey()),
×
1890
                            Component.translatable(ValueTypes.OBJECT_ITEMSTACK.getTranslationKey()));
×
1891
                    throw new EvaluationException(error);
×
1892
                }
1893

1894
                ItemStack itemStack = b.getRawValue();
3✔
1895
                int count = 0;
2✔
1896
                for (IValue listValueRaw : a.getRawValue()) {
11✔
1897
                    if (listValueRaw.getType().correspondsTo(ValueTypes.OBJECT_ITEMSTACK)) {
5!
1898
                        ValueObjectTypeItemStack.ValueItemStack listValue = (ValueObjectTypeItemStack.ValueItemStack) listValueRaw;
3✔
1899
                        if (!listValue.getRawValue().isEmpty()) {
4!
1900
                            ItemStack listItem = listValue.getRawValue();
3✔
1901
                            if (!itemStack.isEmpty()) {
3!
1902
                                if (ItemStack.isSameItemSameComponents(itemStack, listItem)) {
4✔
1903
                                    count += listItem.getCount();
6✔
1904
                                }
1905
                            } else {
1906
                                count += listItem.getCount();
×
1907
                            }
1908
                        }
1909
                    }
1910
                }
1✔
1911

1912
                return ValueTypeInteger.ValueInteger.of(count);
3✔
1913
            }).build());
1✔
1914

1915
    /**
1916
     * Item Stack size operator with one input itemstack and one output NBT tag.
1917
     */
1918
    public static final IOperator OBJECT_ITEMSTACK_DATA = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1919
            .output(ValueTypes.NBT).symbol("NBT()").operatorName("nbt").interactName("nbt")
8✔
1920
            .function(input -> {
1✔
1921
                ValueObjectTypeItemStack.ValueItemStack itemStack = input.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1922
                // Explicitly check for item emptiness first, because vanilla sometimes persists NBT when setting stacks to empty
1923
                return ValueTypeNbt.ValueNbt.of(itemStack.getRawValue().isEmpty() || itemStack.getRawValue().getComponents().isEmpty() ?
11!
1924
                        Optional.empty() :
2✔
1925
                        Optional.of(DataComponentPatch.CODEC.encodeStart(ServerLifecycleHooks.getCurrentServer().registryAccess().createSerializationContext(NbtOps.INSTANCE), itemStack.getRawValue().getComponentsPatch()).getOrThrow()));
12✔
1926
            }).build());
1✔
1927

1928
    /**
1929
     * Item Stack has_nbt operator with one input itemstack and one output boolean.
1930
     */
1931
    public static final IOperator OBJECT_ITEMSTACK_HASDATA = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_PREFIX_LONG
5✔
1932
            .output(ValueTypes.BOOLEAN).symbol("has_nbt").operatorName("hasnbt").interactName("hasNbt")
9✔
1933
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_BOOLEAN.build(
2✔
1934
                    itemStack -> !itemStack.isEmpty() && itemStack.getComponents().stream().anyMatch(t -> !t.type().isTransient())
21!
1935
            )).build());
1✔
1936

1937
    /**
1938
     * Get the data component keys of an itemstack.
1939
     */
1940
    public static final IOperator OBJECT_ITEMSTACK_DATA_KEYS = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1941
            .output(ValueTypes.LIST).symbol("data_keys").operatorName("datakeys").interactName("dataKeys")
8✔
1942
            .function(input -> {
1✔
1943
                ValueObjectTypeItemStack.ValueItemStack itemStack = input.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1944
                // Explicitly check for item emptiness first, because vanilla sometimes persists NBT when setting stacks to empty
1945
                return ValueTypeList.ValueList.ofList(ValueTypes.STRING,
3✔
1946
                        itemStack.getRawValue().isEmpty() ?
4!
1947
                                Lists.newArrayList() :
×
1948
                                itemStack.getRawValue().getComponents().keySet().stream()
5✔
1949
                                        .filter(c -> !c.isTransient())
8!
1950
                                        .map(c -> ValueTypeString.ValueString.of(BuiltInRegistries.DATA_COMPONENT_TYPE.getKey(c).toString()))
8✔
1951
                                        .sorted((o1, o2) -> o1.getRawValue().compareTo(o2.getRawValue()))
7✔
1952
                                        .toList());
2✔
1953
            }).build());
1✔
1954

1955
    /**
1956
     * Get the data component value by key
1957
     */
1958
    public static final IOperator OBJECT_ITEMSTACK_DATA_VALUE = REGISTRY.register(OperatorBuilders.ITEMSTACK_2_LONG
14✔
1959
            .inputTypes(ValueTypes.OBJECT_ITEMSTACK, ValueTypes.STRING)
2✔
1960
            .output(ValueTypes.NBT).symbol("data_value").operatorName("datavalue").interactName("dataValue")
8✔
1961
            .function(input -> {
1✔
1962
                ValueObjectTypeItemStack.ValueItemStack itemStack = input.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1963

1964
                // Determine data component type
1965
                DataComponentType<?> dataComponentType;
1966
                try {
1967
                    dataComponentType = BuiltInRegistries.DATA_COMPONENT_TYPE.get(ResourceLocation.parse(input.getValue(1, ValueTypes.STRING).getRawValue()));
11✔
1968
                } catch (ResourceLocationException e) {
×
1969
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
1970
                }
1✔
1971

1972
                // Fetch component value
1973
                TypedDataComponent<?> typedComponent = itemStack.getRawValue().getComponents().getTyped(dataComponentType);
6✔
1974
                if (typedComponent == null) {
2✔
1975
                    return ValueTypeNbt.ValueNbt.of((Tag) null);
4✔
1976
                }
1977

1978
                // Encode component value
1979
                try {
1980
                    Tag tag = typedComponent.encodeValue(ServerLifecycleHooks.getCurrentServer().registryAccess().createSerializationContext(NbtOps.INSTANCE)).getOrThrow();
9✔
1981
                    return ValueTypeNbt.ValueNbt.of(tag);
3✔
1982
                } catch (IllegalStateException e) {
×
1983
                    return ValueTypeNbt.ValueNbt.of((Tag) null);
×
1984
                }
1985
            }).build());
1✔
1986

1987
    /**
1988
     * Get the data component value by key
1989
     */
1990
    public static final IOperator OBJECT_ITEMSTACK_WITH_DATA = REGISTRY.register(OperatorBuilders.ITEMSTACK_3
18✔
1991
            .inputTypes(ValueTypes.OBJECT_ITEMSTACK, ValueTypes.STRING, ValueTypes.NBT)
2✔
1992
            .output(ValueTypes.NBT).symbol("with_data").operatorName("withdata").interactName("withData")
8✔
1993
            .function(input -> {
1✔
1994
                ValueObjectTypeItemStack.ValueItemStack itemStack = input.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
1995

1996
                // Skip further processing if input value is empty
1997
                Optional<Tag> tagOptional = input.getValue(2, ValueTypes.NBT).getRawValue();
7✔
1998
                if (!tagOptional.isPresent()) {
3!
1999
                    return itemStack;
×
2000
                }
2001

2002
                // Determine data component type
2003
                DataComponentType<?> dataComponentType;
2004
                try {
2005
                    dataComponentType = BuiltInRegistries.DATA_COMPONENT_TYPE.get(ResourceLocation.parse(input.getValue(1, ValueTypes.STRING).getRawValue()));
11✔
2006
                } catch (ResourceLocationException e) {
×
2007
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
2008
                }
1✔
2009

2010
                // Encode component value
2011
                try {
2012
                    Object value = dataComponentType.codec().decode(ServerLifecycleHooks.getCurrentServer().registryAccess().createSerializationContext(NbtOps.INSTANCE), tagOptional.get()).getOrThrow().getFirst();
14✔
2013
                    itemStack = ValueObjectTypeItemStack.ValueItemStack.of(itemStack.getRawValue().copy());
5✔
2014
                    itemStack.getRawValue().set((DataComponentType) dataComponentType, value);
6✔
2015
                    return itemStack;
2✔
2016
                } catch (IllegalStateException e) {
×
2017
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
2018
                }
2019
            }).build());
1✔
2020

2021
    /**
2022
     * Get the tooltip of an itemstack in list form.
2023
     */
2024
    public static final IOperator OBJECT_ITEMSTACK_TOOLTIP = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
2025
            .output(ValueTypes.LIST).symbol("tooltip").operatorName("tooltip").interactName("tooltip")
8✔
2026
            .function(input -> {
1✔
2027
                ValueObjectTypeItemStack.ValueItemStack itemStack = input.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
6✔
2028
                return ValueTypeList.ValueList.ofList(ValueTypes.STRING,
4✔
2029
                        itemStack.getRawValue().getTooltipLines(Item.TooltipContext.EMPTY, null, TooltipFlag.Default.NORMAL).stream()
7✔
2030
                                .map(c -> ValueTypeString.ValueString.of(c.getString()))
5✔
2031
                                .toList());
1✔
2032
            }).build());
1✔
2033
    /**
2034
     * Get the tooltip of an itemstack in list form, using the provided player entity as the player context.
2035
     */
2036
    public static final IOperator OBJECT_ITEMSTACK_ENTITY_TOOLTIP = REGISTRY.register(OperatorBuilders.ENTITY_1_ITEMSTACK_1
14✔
2037
            .inputTypes(ValueTypes.OBJECT_ENTITY, ValueTypes.OBJECT_ITEMSTACK)
2✔
2038
            .output(ValueTypes.LIST).symbol("entity_item_tooltip").operatorName("entityitemtooltip").interactName("entityItemTooltip")
8✔
2039
            .function(variables -> {
1✔
2040
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2041
                ValueObjectTypeItemStack.ValueItemStack itemStack = variables.getValue(1, ValueTypes.OBJECT_ITEMSTACK);
×
2042
                if(a.getRawValue().isPresent() && a.getRawValue().get() instanceof Player) {
×
2043
                    Player entity = (Player) a.getRawValue().get();
×
2044
                    return ValueTypeList.ValueList.ofList(ValueTypes.STRING,
×
2045
                            itemStack.getRawValue().getTooltipLines(Item.TooltipContext.of(entity.level()), entity, TooltipFlag.Default.NORMAL).stream()
×
2046
                                    .map(c -> ValueTypeString.ValueString.of(c.getString()))
×
2047
                                    .toList());
×
2048
                }
2049
                return ValueTypes.LIST.getDefault();
×
2050
            }).build());
1✔
2051

2052
    /**
2053
     * ----------------------------------- ENTITY OBJECT OPERATORS -----------------------------------
2054
     */
2055

2056
    /**
2057
     * If the entity is a mob
2058
     */
2059
    public static final IOperator OBJECT_ENTITY_ISMOB = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2060
            .output(ValueTypes.BOOLEAN).symbol("is_mob").operatorName("ismob").interactName("isMob")
9✔
2061
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2062
                entity -> entity instanceof Enemy
4✔
2063
            )).build());
1✔
2064

2065
    /**
2066
     * If the entity is an animal
2067
     */
2068
    public static final IOperator OBJECT_ENTITY_ISANIMAL = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2069
            .output(ValueTypes.BOOLEAN).symbol("is_animal").operatorName("isanimal").interactName("isAnimal")
9✔
2070
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2071
                entity -> entity instanceof Animal && !(entity instanceof Enemy)
11!
2072
            )).build());
1✔
2073

2074
    /**
2075
     * If the entity is an item
2076
     */
2077
    public static final IOperator OBJECT_ENTITY_ISITEM = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2078
            .output(ValueTypes.BOOLEAN).symbol("is_item").operatorName("isitem").interactName("isItem")
9✔
2079
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2080
                entity -> entity instanceof ItemEntity
4✔
2081
            )).build());
1✔
2082

2083
    /**
2084
     * If the entity is a player
2085
     */
2086
    public static final IOperator OBJECT_ENTITY_ISPLAYER = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2087
            .output(ValueTypes.BOOLEAN).symbol("is_player").operatorName("isplayer").interactName("isPlayer")
9✔
2088
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2089
                entity -> entity instanceof Player
4✔
2090
            )).build());
1✔
2091

2092
    /**
2093
     * If the entity is a minecart
2094
     */
2095
    public static final IOperator OBJECT_ENTITY_ISMINECART = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2096
            .output(ValueTypes.BOOLEAN).symbol("is_minecart").operatorName("isminecart").interactName("isMinecart")
9✔
2097
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2098
                entity -> entity instanceof AbstractMinecart
×
2099
            )).build());
1✔
2100

2101
    /**
2102
     * The itemstack from the entity
2103
     */
2104
    public static final IOperator OBJECT_ENTITY_ITEMSTACK = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX
5✔
2105
            .output(ValueTypes.OBJECT_ITEMSTACK).symbolOperatorInteract("item")
4✔
2106
            .function(variables -> {
1✔
2107
                ValueObjectTypeEntity.ValueEntity valueEntity = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2108
                Optional<Entity> a = valueEntity.getRawValue();
3✔
2109
                return ValueObjectTypeItemStack.ValueItemStack.of((a.isPresent() && a.get() instanceof ItemEntity) ? ((ItemEntity) a.get()).getItem() : ItemStack.EMPTY);
15!
2110
            }).build());
1✔
2111

2112
    /**
2113
     * The entity health
2114
     */
2115
    public static final IOperator OBJECT_ENTITY_HEALTH = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2116
            .output(ValueTypes.DOUBLE).symbolOperatorInteract("health")
5✔
2117
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_DOUBLE.build(
2✔
2118
                entity -> entity instanceof LivingEntity ? ((LivingEntity) entity).getHealth() : 0.0
11✔
2119
            )).build());
1✔
2120

2121
    /**
2122
     * The entity width
2123
     */
2124
    public static final IOperator OBJECT_ENTITY_WIDTH = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2125
            .output(ValueTypes.DOUBLE).symbolOperatorInteract("width")
5✔
2126
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_DOUBLE.build(
2✔
2127
                entity -> entity != null ? entity.getBbWidth() : 0.0
8!
2128
            )).build());
1✔
2129

2130
    /**
2131
     * The entity width
2132
     */
2133
    public static final IOperator OBJECT_ENTITY_HEIGHT = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2134
            .output(ValueTypes.DOUBLE).symbolOperatorInteract("height")
5✔
2135
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_DOUBLE.build(
2✔
2136
                entity -> entity != null ? entity.getBbHeight() : 0.0
8!
2137
            )).build());
1✔
2138

2139
    /**
2140
     * If the entity is burning
2141
     */
2142
    public static final IOperator OBJECT_ENTITY_ISBURNING = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2143
            .output(ValueTypes.BOOLEAN).symbol("is_burning").operatorName("isburning").interactName("entityIsBurning")
9✔
2144
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2145
                entity -> entity != null && entity.isOnFire()
10!
2146
            )).build());
1✔
2147

2148
    /**
2149
     * If the entity is wet
2150
     */
2151
    public static final IOperator OBJECT_ENTITY_ISWET = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2152
            .output(ValueTypes.BOOLEAN).symbol("is_wet").operatorName("iswet").interactName("isWet")
9✔
2153
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2154
                entity -> entity != null && entity.isInWaterOrRain()
10!
2155
            )).build());
1✔
2156

2157
    /**
2158
     * If the entity is crouching
2159
     */
2160
    public static final IOperator OBJECT_ENTITY_ISCROUCHING = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2161
            .output(ValueTypes.BOOLEAN).symbol("is_crouching").operatorName("iscrouching").interactName("isCrouching")
9✔
2162
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2163
                entity -> entity != null && entity.isCrouching()
10!
2164
            )).build());
1✔
2165

2166
    /**
2167
     * If the entity is eating
2168
     */
2169
    public static final IOperator OBJECT_ENTITY_ISEATING = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2170
            .output(ValueTypes.BOOLEAN).symbol("is_eating").operatorName("iseating").interactName("isEating")
9✔
2171
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2172
                entity -> entity instanceof LivingEntity && ((LivingEntity) entity).getUseItemRemainingTicks() > 0
12!
2173
            )).build());
1✔
2174

2175
    /**
2176
     * The list of armor itemstacks from an entity
2177
     */
2178
    public static final IOperator OBJECT_ENTITY_ARMORINVENTORY = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2179
            .output(ValueTypes.LIST).symbol("armor_inventory").operatorName("armorinventory").interactName("armorInventory")
8✔
2180
            .function(variables -> {
1✔
2181
                ValueObjectTypeEntity.ValueEntity valueEntity = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2182
                Optional<Entity> a = valueEntity.getRawValue();
×
2183
                if(a.isPresent()) {
×
2184
                    Entity entity = a.get();
×
2185
                    return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyEntityArmorInventory(entity.level(), entity));
×
2186
                } else {
2187
                    return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_ITEMSTACK, Collections.<ValueObjectTypeItemStack.ValueItemStack>emptyList());
×
2188
                }
2189
            }).build());
1✔
2190

2191
    /**
2192
     * The list of itemstacks from an entity
2193
     */
2194
    public static final IOperator OBJECT_ENTITY_INVENTORY = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2195
            .output(ValueTypes.LIST).symbolOperator("inventory").interactName("inventory")
6✔
2196
            .function(variables -> {
1✔
2197
                ValueObjectTypeEntity.ValueEntity valueEntity = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2198
                Optional<Entity> a = valueEntity.getRawValue();
×
2199
                if(a.isPresent()) {
×
2200
                    Entity entity = a.get();
×
2201
                    return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyEntityInventory(entity.level(), entity));
×
2202
                } else {
2203
                    return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_ITEMSTACK, Collections.<ValueObjectTypeItemStack.ValueItemStack>emptyList());
×
2204
                }
2205
            }).build());
1✔
2206

2207
    /**
2208
     * The name of the mod owning this entity
2209
     */
2210
    public static final IOperator OBJECT_ENTITY_MODNAME = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.STRING)
7✔
2211
            .symbolOperatorInteract("mod")
13✔
2212
            .function(new IterativeFunction(Lists.newArrayList(
3✔
2213
                    (OperatorBase.SafeVariablesGetter variables) -> {
2214
                        ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2215
                        if(a.getRawValue().isPresent()) {
4!
2216
                            Entity entity = a.getRawValue().get();
5✔
2217
                            return BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType());
5✔
2218
                        }
2219
                        return ResourceLocation.parse("");
×
2220
                    },
2221
                    OperatorBuilders.PROPAGATOR_RESOURCELOCATION_MODNAME
2222
            )))
2223
            .build());
1✔
2224

2225
    /**
2226
     * The block the given player is currently looking at.
2227
     */
2228
    public static final IOperator OBJECT_PLAYER_TARGETBLOCK = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.OBJECT_BLOCK)
7✔
2229
            .symbol("target_block").operatorName("targetblock").interactName("targetBlock")
6✔
2230
            .function(variables -> {
1✔
2231
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2232
                BlockState blockState = null;
×
2233
                if(a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
×
2234
                    LivingEntity entity = (LivingEntity) a.getRawValue().get();
×
2235
                    AttributeInstance reachDistanceAttribute = entity.getAttribute(Attributes.BLOCK_INTERACTION_RANGE);
×
2236
                    double reachDistance = reachDistanceAttribute == null ? 5 : reachDistanceAttribute.getValue();
×
2237
                    double eyeHeight = entity.getEyeHeight();
×
2238
                    Vec3 lookVec = entity.getLookAngle();
×
2239
                    Vec3 origin = new Vec3(entity.getX(), entity.getY() + eyeHeight, entity.getZ());
×
2240
                    Vec3 direction = origin.add(lookVec.x * reachDistance, lookVec.y * reachDistance, lookVec.z * reachDistance);
×
2241

2242
                    ClipContext rayTraceContext = new ClipContext(origin, direction, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity);
×
2243
                    BlockHitResult mop = entity.level().clip(rayTraceContext);
×
2244
                    if(mop != null && mop.getType() == HitResult.Type.BLOCK) {
×
2245
                        blockState = entity.level().getBlockState(mop.getBlockPos());
×
2246
                    }
2247
                }
2248
                return ValueObjectTypeBlock.ValueBlock.of(blockState);
×
2249
            }).build());
1✔
2250

2251
    /**
2252
     * The entity the given player is currently looking at.
2253
     */
2254
    public static final IOperator OBJECT_PLAYER_TARGETENTITY = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.OBJECT_ENTITY)
7✔
2255
            .symbol("target_entity").operatorName("targetentity").interactName("targetEntity")
6✔
2256
            .function(variables -> {
1✔
2257
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2258
                Entity entityOut = null;
×
2259
                if(a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
×
2260
                    LivingEntity entity = (LivingEntity) a.getRawValue().get();
×
2261
                    AttributeInstance reachDistanceAttribute = entity.getAttribute(Attributes.ENTITY_INTERACTION_RANGE);
×
2262
                    double reachDistance = reachDistanceAttribute == null ? 5 : reachDistanceAttribute.getValue();
×
2263

2264
                    // Copied and modified from GameRenderer#getMouseOver
2265
                    Vec3 origin = entity.getEyePosition(1.0F);
×
2266
                    double reachDistanceSquared = reachDistance * reachDistance;
×
2267

2268
                    Vec3 lookVec = entity.getViewVector(1.0F);
×
2269
                    Vec3 direction = origin.add(lookVec.x * reachDistance, lookVec.y * reachDistance, lookVec.z * reachDistance);
×
2270
                    AABB boundingBox = entity.getBoundingBox()
×
2271
                            .expandTowards(lookVec.scale(reachDistance))
×
2272
                            .inflate(1.0D, 1.0D, 1.0D);
×
2273
                    EntityHitResult entityraytraceresult = ProjectileUtil.getEntityHitResult(entity, origin, direction,
×
2274
                            boundingBox, e -> !e.isSpectator() && e.isPickable(), reachDistanceSquared);
×
2275
                    if (entityraytraceresult != null) {
×
2276
                        Entity entity1 = entityraytraceresult.getEntity();
×
2277
                        Vec3 vec3d3 = entityraytraceresult.getLocation();
×
2278
                        double distanceSquared = origin.distanceToSqr(vec3d3);
×
2279
                        if (distanceSquared < reachDistanceSquared
×
2280
                                && (entity1 instanceof LivingEntity || entity1 instanceof ItemFrame)) {
2281
                            entityOut = entity1;
×
2282
                        }
2283
                    }
2284
                }
2285
                return ValueObjectTypeEntity.ValueEntity.of(entityOut);
×
2286
            }).build());
1✔
2287

2288
    /**
2289
     * If the given player has an external gui open.
2290
     */
2291
    public static final IOperator OBJECT_PLAYER_HASGUIOPEN = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.BOOLEAN)
7✔
2292
            .symbol("has_gui_open").operatorName("hasguiopen").interactName("hasGuiOpen")
6✔
2293
            .function(variables -> {
1✔
2294
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2295
                if(a.getRawValue().isPresent() && a.getRawValue().get() instanceof Player) {
×
2296
                    Player entity = (Player) a.getRawValue().get();
×
2297
                    return ValueTypeBoolean.ValueBoolean.of(entity.containerMenu != entity.inventoryMenu);
×
2298
                }
2299
                return ValueTypeBoolean.ValueBoolean.of(false);
×
2300
            }).build());
1✔
2301

2302
    /**
2303
     * The item the given entity is currently holding in its main hand.
2304
     */
2305
    public static final IOperator OBJECT_ENTITY_HELDITEM_MAIN = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.OBJECT_ITEMSTACK)
7✔
2306
            .symbol("held_item_1").operatorName("helditem").interactName("heldItem")
6✔
2307
            .function(variables -> {
1✔
2308
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2309
                ItemStack itemStack = ItemStack.EMPTY;
2✔
2310
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
9!
2311
                    itemStack = ((LivingEntity) a.getRawValue().get()).getMainHandItem();
6✔
2312
                }
2313
                return ValueObjectTypeItemStack.ValueItemStack.of(itemStack);
3✔
2314
            }).build());
1✔
2315

2316
    /**
2317
     * The item the given entity is currently holding in its off hand.
2318
     */
2319
    public static final IOperator OBJECT_ENTITY_HELDITEM_OFF = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.OBJECT_ITEMSTACK)
7✔
2320
            .symbol("held_item_2").operatorName("helditemoffhand").interactName("heldItemOffHand")
6✔
2321
            .function(variables -> {
1✔
2322
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2323
                ItemStack itemStack = ItemStack.EMPTY;
2✔
2324
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
9!
2325
                    itemStack = ((LivingEntity) a.getRawValue().get()).getOffhandItem();
6✔
2326
                }
2327
                return ValueObjectTypeItemStack.ValueItemStack.of(itemStack);
3✔
2328
            }).build());
1✔
2329

2330
    /**
2331
     * The entity's mounted entity
2332
     */
2333
    public static final IOperator OBJECT_ENTITY_MOUNTED = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.LIST)
7✔
2334
            .symbolOperator("mounted").interactName("mounted")
4✔
2335
            .function(variables -> {
1✔
2336
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2337
                List<ValueObjectTypeEntity.ValueEntity> passengers = Lists.newArrayList();
2✔
2338
                if(a.getRawValue().isPresent()) {
4!
2339
                    for (Entity passenger : a.getRawValue().get().getPassengers()) {
14✔
2340
                        passengers.add(ValueObjectTypeEntity.ValueEntity.of(passenger));
5✔
2341
                    }
1✔
2342
                }
2343
                return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_ENTITY, passengers);
4✔
2344
            }).build());
1✔
2345

2346
    /**
2347
     * The item frame's contents
2348
     */
2349
    public static final IOperator OBJECT_ITEMFRAME_CONTENTS = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.OBJECT_ITEMSTACK)
7✔
2350
            .symbol("itemframe_contents").operatorName("itemframecontents").interactName("itemFrameContents")
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 ItemFrame) {
9!
2355
                    itemStack = ((ItemFrame) a.getRawValue().get()).getItem();
6✔
2356
                }
2357
                return ValueObjectTypeItemStack.ValueItemStack.of(itemStack);
3✔
2358
            }).build());
1✔
2359

2360
    /**
2361
     * The item frame's rotation
2362
     */
2363
    public static final IOperator OBJECT_ITEMFRAME_ROTATION = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.INTEGER)
7✔
2364
            .symbol("itemframe_rotation").operatorName("itemframerotation").interactName("itemFrameRotation")
6✔
2365
            .function(variables -> {
1✔
2366
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2367
                Integer rotation = 0;
3✔
2368
                if(a.getRawValue().isPresent() && a.getRawValue().get() instanceof ItemFrame) {
9!
2369
                    rotation = ((ItemFrame) a.getRawValue().get()).getRotation();
7✔
2370
                }
2371
                return ValueTypeInteger.ValueInteger.of(rotation);
4✔
2372
            }).build());
1✔
2373

2374
    /**
2375
     * The hurtsound of this entity.
2376
     */
2377
    public static final IOperator OBJECT_ENTITY_HURTSOUND = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.STRING)
7✔
2378
            .symbolOperator("hurtsound").interactName("hurtSound")
4✔
2379
            .function(variables -> {
1✔
2380
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2381
                String hurtSound = "";
2✔
2382
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
9!
2383
                    String sound = ((LivingEntity) a.getRawValue().get()).getHurtSound(a.getRawValue().get().damageSources().generic()).getLocation().toString();
14✔
2384
                    if (sound != null) {
2!
2385
                        hurtSound = sound;
2✔
2386
                    }
2387
                }
2388
                return ValueTypeString.ValueString.of(hurtSound);
3✔
2389
            }).build());
1✔
2390

2391
    /**
2392
     * The deathsound of this entity.
2393
     */
2394
    public static final IOperator OBJECT_ENTITY_DEATHSOUND = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.STRING)
7✔
2395
            .symbolOperator("deathsound").interactName("deathSound")
4✔
2396
            .function(variables -> {
1✔
2397
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2398
                String hurtSound = "";
2✔
2399
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
9!
2400
                    String sound = ((LivingEntity) a.getRawValue().get()).getDeathSound().getLocation().toString();
8✔
2401
                    if (sound != null) {
2!
2402
                        hurtSound = sound;
2✔
2403
                    }
2404
                }
2405
                return ValueTypeString.ValueString.of(hurtSound);
3✔
2406
            }).build());
1✔
2407

2408
    /**
2409
     * The age of this entity.
2410
     */
2411
    public static final IOperator OBJECT_ENTITY_AGE = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.INTEGER)
7✔
2412
            .symbolOperatorInteract("age")
2✔
2413
            .function(variables -> {
1✔
2414
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2415
                int age = 0;
2✔
2416
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
9!
2417
                    age = ((LivingEntity) a.getRawValue().get()).getNoActionTime();
6✔
2418
                }
2419
                return ValueTypeInteger.ValueInteger.of(age);
3✔
2420
            }).build());
1✔
2421

2422
    /**
2423
     * If the entity is a child.
2424
     */
2425
    public static final IOperator OBJECT_ENTITY_ISCHILD = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.BOOLEAN)
7✔
2426
            .symbol("is_child").operatorName("ischild").interactName("isChild")
6✔
2427
            .function(variables -> {
1✔
2428
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2429
                boolean child = false;
2✔
2430
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
9!
2431
                    child = ((LivingEntity) a.getRawValue().get()).isBaby();
6✔
2432
                }
2433
                return ValueTypeBoolean.ValueBoolean.of(child);
3✔
2434
            }).build());
1✔
2435

2436
    /**
2437
     * If the entity can be bred.
2438
     */
2439
    public static final IOperator OBJECT_ENTITY_CANBREED = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.BOOLEAN)
7✔
2440
            .symbol("canbreed").operatorName("canbreed").interactName("canBreed")
6✔
2441
            .function(variables -> {
1✔
2442
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2443
                boolean canBreed = false;
2✔
2444
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof AgeableMob) {
9!
2445
                    canBreed = ((AgeableMob) a.getRawValue().get()).getAge() == 0;
10✔
2446
                }
2447
                return ValueTypeBoolean.ValueBoolean.of(canBreed);
3✔
2448
            }).build());
1✔
2449

2450
    /**
2451
     * If the entity is in love.
2452
     */
2453
    public static final IOperator OBJECT_ENTITY_ISINLOVE = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.BOOLEAN)
7✔
2454
            .symbol("is_in_love").operatorName("isinlove").interactName("isInLove")
6✔
2455
            .function(variables -> {
1✔
2456
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2457
                boolean inLove = false;
2✔
2458
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof Animal) {
9!
2459
                    inLove = ((Animal) a.getRawValue().get()).isInLove();
6✔
2460
                }
2461
                return ValueTypeBoolean.ValueBoolean.of(inLove);
3✔
2462
            }).build());
1✔
2463

2464
    /**
2465
     * If the entity can be bred with the given item.
2466
     */
2467
    public static final IOperator OBJECT_ENTITY_CANBREEDWITH = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
14✔
2468
            .inputTypes(ValueTypes.OBJECT_ENTITY, ValueTypes.OBJECT_ITEMSTACK)
2✔
2469
            .output(ValueTypes.BOOLEAN)
2✔
2470
            .symbol("can_breed_with").operatorName("canbreedwith").interactName("canBreedWith")
6✔
2471
            .renderPattern(IConfigRenderPattern.INFIX_LONG)
2✔
2472
            .function(variables -> {
1✔
2473
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2474
                ValueObjectTypeItemStack.ValueItemStack b = variables.getValue(1, ValueTypes.OBJECT_ITEMSTACK);
6✔
2475
                boolean canBreedWith = false;
2✔
2476
                if (a.getRawValue().isPresent() && !b.getRawValue().isEmpty() && a.getRawValue().get() instanceof Animal) {
13!
2477
                    canBreedWith = ((Animal) a.getRawValue().get()).isFood(b.getRawValue());
8✔
2478
                }
2479
                return ValueTypeBoolean.ValueBoolean.of(canBreedWith);
3✔
2480
            }).build());
1✔
2481

2482
    /**
2483
     * If the entity is shearable.
2484
     */
2485
    public static final IOperator OBJECT_ENTITY_ISSHEARABLE = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.BOOLEAN)
7✔
2486
            .symbol("is_shearable").operatorName("isshearable").interactName("isShearable")
6✔
2487
            .function(variables -> {
1✔
2488
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2489
                return ValueTypeBoolean.ValueBoolean.of(a.getRawValue().isPresent()
7!
2490
                        && a.getRawValue().get() instanceof IShearable
5✔
2491
                        && ((IShearable) a.getRawValue().get()).isShearable(null, ItemStack.EMPTY, null, null));
12✔
2492
            }).build());
1✔
2493

2494
    /**
2495
     * The entity serialized to NBT.
2496
     */
2497
    public static final IOperator OBJECT_ENTITY_NBT = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2498
            .output(ValueTypes.NBT).symbol("NBT()").operatorInteract("nbt")
6✔
2499
            .function(input -> {
1✔
2500
                ValueObjectTypeEntity.ValueEntity entity = input.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2501
                try {
2502
                    if (entity.getRawValue().isPresent()) {
4!
2503
                        return ValueTypeNbt.ValueNbt.of(entity.getRawValue().get().serializeNBT(ServerLifecycleHooks.getCurrentServer().registryAccess()));
9✔
2504
                    }
2505
                } catch (Exception e) {
×
2506
                    // Catch possible errors during NBT writing
2507
                }
×
2508
                return ValueTypes.NBT.getDefault();
×
2509
            }).build());
1✔
2510

2511
    /**
2512
     * The entity type.
2513
     */
2514
    public static final IOperator OBJECT_ENTITY_TYPE = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2515
            .output(ValueTypes.STRING).symbol("entity_type").operatorName("entitytype").interactName("type")
8✔
2516
            .function(input -> {
1✔
2517
                ValueObjectTypeEntity.ValueEntity entity = input.getValue(0, ValueTypes.OBJECT_ENTITY);
6✔
2518
                String entityType = "";
2✔
2519
                if (entity.getRawValue().isPresent()) {
4!
2520
                    Entity e = entity.getRawValue().get();
5✔
2521
                    entityType = BuiltInRegistries.ENTITY_TYPE.getKey(e.getType()).toString();
6✔
2522
                }
2523
                return ValueTypeString.ValueString.of(entityType);
3✔
2524
            }).build());
1✔
2525

2526
    /**
2527
     * The entity items.
2528
     */
2529
    public static final IOperator OBJECT_ENTITY_ITEMS = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2530
            .output(ValueTypes.LIST).symbol("entity_items").operatorName("entityitems").interactName("items")
8✔
2531
            .function(input -> {
1✔
2532
                ValueObjectTypeEntity.ValueEntity valueEntity = input.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2533
                Optional<Entity> a = valueEntity.getRawValue();
×
2534
                if(a.isPresent()) {
×
2535
                    Entity entity = a.get();
×
2536
                    return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyEntityItems(entity.level(), entity, null));
×
2537
                } else {
2538
                    return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_ITEMSTACK, Collections.emptyList());
×
2539
                }
2540
            }).build());
1✔
2541

2542
    /**
2543
     * The entity fluids.
2544
     */
2545
    public static final IOperator OBJECT_ENTITY_FLUIDS = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2546
            .output(ValueTypes.LIST).symbol("entity_fluids").operatorName("entityfluids").interactName("fluids")
8✔
2547
            .function(input -> {
1✔
2548
                ValueObjectTypeEntity.ValueEntity valueEntity = input.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2549
                Optional<Entity> a = valueEntity.getRawValue();
×
2550
                if(a.isPresent()) {
×
2551
                    Entity entity = a.get();
×
2552
                    return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyEntityFluids(entity.level(), entity, null));
×
2553
                } else {
2554
                    return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_FLUIDSTACK, Collections.emptyList());
×
2555
                }
2556
            }).build());
1✔
2557

2558
    /**
2559
     * The entity energy stored.
2560
     */
2561
    public static final IOperator OBJECT_ENTITY_ENERGY_STORED = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2562
            .output(ValueTypes.INTEGER).symbol("entity_stored_fe").operatorName("entityenergystored").interactName("energy")
8✔
2563
            .function(input -> {
1✔
2564
                ValueObjectTypeEntity.ValueEntity valueEntity = input.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2565
                Optional<Entity> a = valueEntity.getRawValue();
×
2566
                if(a.isPresent()) {
×
2567
                    Entity entity = a.get();
×
2568
                    IEnergyStorage energyStorage = entity.getCapability(Capabilities.EnergyStorage.ENTITY, null);
×
2569
                    return ValueTypeInteger.ValueInteger.of(energyStorage != null ? energyStorage.getEnergyStored() : 0);
×
2570
                }
2571
                return ValueTypeInteger.ValueInteger.of(0);
×
2572
            }).build());
1✔
2573

2574
    /**
2575
     * The entity energy stored.
2576
     */
2577
    public static final IOperator OBJECT_ENTITY_ENERGY_CAPACITY = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2578
            .output(ValueTypes.INTEGER).symbol("entity_capacity_fe").operatorName("entityenergycapacity").interactName("energyCapacity")
8✔
2579
            .function(input -> {
1✔
2580
                ValueObjectTypeEntity.ValueEntity valueEntity = input.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2581
                Optional<Entity> a = valueEntity.getRawValue();
×
2582
                if(a.isPresent()) {
×
2583
                    Entity entity = a.get();
×
2584
                    IEnergyStorage energyStorage = entity.getCapability(Capabilities.EnergyStorage.ENTITY, null);
×
2585
                    return ValueTypeInteger.ValueInteger.of(energyStorage != null ? energyStorage.getMaxEnergyStored() : 0);
×
2586
                }
2587
                return ValueTypeInteger.ValueInteger.of(0);
×
2588
            }).build());
1✔
2589

2590
    /**
2591
     * ----------------------------------- FLUID STACK OBJECT OPERATORS -----------------------------------
2592
     */
2593

2594
    /**
2595
     * The amount of fluid in the fluidstack
2596
     */
2597
    public static final IOperator OBJECT_FLUIDSTACK_AMOUNT = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2598
            .output(ValueTypes.INTEGER).symbolOperatorInteract("amount")
5✔
2599
            .function(OperatorBuilders.FUNCTION_FLUIDSTACK_TO_INT.build(
2✔
2600
                    FluidStack::getAmount
2601
            )).build());
1✔
2602

2603
    /**
2604
     * The block from the fluidstack
2605
     */
2606
    public static final IOperator OBJECT_FLUIDSTACK_BLOCK = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2607
            .output(ValueTypes.OBJECT_BLOCK).symbolOperatorInteract("block")
4✔
2608
            .function(variables -> {
1✔
2609
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2610
                FluidStack a = valueFluidStack.getRawValue();
3✔
2611
                return ValueObjectTypeBlock.ValueBlock.of(!a.isEmpty() ? a.getFluid().getFluidType().getStateForPlacement(null, null, a).createLegacyBlock() : null);
14!
2612
            }).build());
1✔
2613

2614
    /**
2615
     * The fluidstack luminosity
2616
     */
2617
    public static final IOperator OBJECT_FLUIDSTACK_LIGHT_LEVEL = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2618
            .output(ValueTypes.INTEGER).symbolOperator("light_level").interactName("lightLevel")
7✔
2619
            .function(OperatorBuilders.FUNCTION_FLUIDSTACK_TO_INT.build(
2✔
2620
                fluidStack -> fluidStack.getFluid().getFluidType().getLightLevel(fluidStack)
7✔
2621
            )).build());
1✔
2622

2623
    /**
2624
     * The fluidstack density
2625
     */
2626
    public static final IOperator OBJECT_FLUIDSTACK_DENSITY = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2627
            .output(ValueTypes.INTEGER).symbolOperatorInteract("density")
5✔
2628
            .function(OperatorBuilders.FUNCTION_FLUIDSTACK_TO_INT.build(
2✔
2629
                fluidStack -> fluidStack.getFluid().getFluidType().getDensity(fluidStack)
7✔
2630
            )).build());
1✔
2631

2632
    /**
2633
     * The fluidstack temperature
2634
     */
2635
    public static final IOperator OBJECT_FLUIDSTACK_TEMPERATURE = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2636
            .output(ValueTypes.INTEGER).symbolOperatorInteract("temperature")
5✔
2637
            .function(OperatorBuilders.FUNCTION_FLUIDSTACK_TO_INT.build(
2✔
2638
                    fluidStack -> fluidStack.getFluid().getFluidType().getTemperature(fluidStack)
7✔
2639
            )).build());
1✔
2640

2641
    /**
2642
     * The fluidstack viscosity
2643
     */
2644
    public static final IOperator OBJECT_FLUIDSTACK_VISCOSITY = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2645
            .output(ValueTypes.INTEGER).symbolOperatorInteract("viscosity")
5✔
2646
            .function(OperatorBuilders.FUNCTION_FLUIDSTACK_TO_INT.build(
2✔
2647
                fluidStack -> fluidStack.getFluid().getFluidType().getViscosity(fluidStack)
7✔
2648
            )).build());
1✔
2649

2650
    /**
2651
     * If the fluidstack is gaseous
2652
     */
2653
    public static final IOperator OBJECT_FLUIDSTACK_IS_LIGHTER_THAN_AIR = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2654
            .output(ValueTypes.BOOLEAN).symbolOperator("lighter_than_air").interactName("isLighterThanAir")
7✔
2655
            .function(OperatorBuilders.FUNCTION_FLUIDSTACK_TO_BOOLEAN.build(
2✔
2656
                fluidStack -> fluidStack.getFluid().getFluidType().isLighterThanAir()
6✔
2657
            )).build());
1✔
2658

2659
    /**
2660
     * The rarity of the fluidstack
2661
     */
2662
    public static final IOperator OBJECT_FLUIDSTACK_RARITY = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2663
            .output(ValueTypes.STRING).symbolOperatorInteract("rarity")
4✔
2664
            .function(variables -> {
1✔
2665
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2666
                FluidStack a = valueFluidStack.getRawValue();
3✔
2667
                return ValueTypeString.ValueString.of(a.getFluid().getFluidType().getRarity(a).name());
8✔
2668
            }).build());
1✔
2669

2670
    /**
2671
     * The bucket empty sound of the fluidstack
2672
     */
2673
    public static final IOperator OBJECT_FLUIDSTACK_SOUND_BUCKET_EMPTY = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2674
            .output(ValueTypes.STRING).symbolOperator("sound_bucket_empty").interactName("bucketEmptySound")
6✔
2675
            .function(variables -> {
1✔
2676
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2677
                FluidStack a = valueFluidStack.getRawValue();
3✔
2678
                return ValueTypeString.ValueString.of(Optional.ofNullable(a.getFluid().getFluidType().getSound(a, SoundActions.BUCKET_EMPTY))
10✔
2679
                        .map(soundEvent -> soundEvent.getLocation().toString())
6✔
2680
                        .orElse(""));
2✔
2681
            }).build());
1✔
2682

2683
    /**
2684
     * The fluid vaporize sound of the fluidstack
2685
     */
2686
    public static final IOperator OBJECT_FLUIDSTACK_SOUND_FLUID_VAPORIZE = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2687
            .output(ValueTypes.STRING).symbolOperator("sound_fluid_vaporize").interactName("fluidVaporizeSound")
6✔
2688
            .function(variables -> {
1✔
2689
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2690
                FluidStack a = valueFluidStack.getRawValue();
3✔
2691
                return ValueTypeString.ValueString.of(Optional.ofNullable(a.getFluid().getFluidType().getSound(a, SoundActions.FLUID_VAPORIZE))
10✔
2692
                        .map(soundEvent -> soundEvent.getLocation().toString())
6✔
2693
                        .orElse(""));
2✔
2694
            }).build());
1✔
2695

2696
    /**
2697
     * The bucket fill sound of the fluidstack
2698
     */
2699
    public static final IOperator OBJECT_FLUIDSTACK_SOUND_BUCKET_FILL = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2700
            .output(ValueTypes.STRING).symbolOperator("sound_bucket_fill").interactName("bucketFillSound")
6✔
2701
            .function(variables -> {
1✔
2702
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2703
                FluidStack a = valueFluidStack.getRawValue();
3✔
2704
                return ValueTypeString.ValueString.of(Optional.ofNullable(a.getFluid().getFluidType().getSound(a, SoundActions.BUCKET_FILL))
10✔
2705
                        .map(soundEvent -> soundEvent.getLocation().toString())
6✔
2706
                        .orElse(""));
2✔
2707
            }).build());
1✔
2708

2709
    /**
2710
     * The bucket of the fluidstack
2711
     */
2712
    public static final IOperator OBJECT_FLUIDSTACK_BUCKET = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2713
            .output(ValueTypes.OBJECT_ITEMSTACK).symbolOperatorInteract("bucket")
4✔
2714
            .function(variables -> {
1✔
2715
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2716
                FluidStack a = valueFluidStack.getRawValue();
3✔
2717
                return ValueObjectTypeItemStack.ValueItemStack.of(a.getFluid().getFluidType().getBucket(a));
7✔
2718
            }).build());
1✔
2719

2720
    /**
2721
     * If the fluid types of the two given fluidstacks are equal
2722
     */
2723
    public static final IOperator OBJECT_FLUIDSTACK_ISRAWFLUIDEQUAL = REGISTRY.register(OperatorBuilders.FLUIDSTACK_2
5✔
2724
            .output(ValueTypes.BOOLEAN).symbol("=Raw=").operatorName("israwfluidequal").interactName("isRawEqual")
8✔
2725
            .function(variables -> {
1✔
2726
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack0 = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2727
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack1 = variables.getValue(1, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2728
                return ValueTypeBoolean.ValueBoolean.of(FluidStack.isSameFluid(valueFluidStack0.getRawValue(), valueFluidStack1.getRawValue()));
7✔
2729
            }).build());
1✔
2730

2731
    /**
2732
     * The name of the mod owning this fluid
2733
     */
2734
    public static final IOperator OBJECT_FLUIDSTACK_MODNAME = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG.output(ValueTypes.STRING)
7✔
2735
            .symbolOperatorInteract("mod")
13✔
2736
            .function(new IterativeFunction(Lists.newArrayList(
3✔
2737
                    (OperatorBase.SafeVariablesGetter variables) -> {
2738
                        ValueObjectTypeFluidStack.ValueFluidStack a = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2739
                        return BuiltInRegistries.FLUID.getKey(a.getRawValue().getFluid());
6✔
2740
                    },
2741
                    OperatorBuilders.PROPAGATOR_RESOURCELOCATION_MODNAME
2742
            ))).build());
1✔
2743

2744
    /**
2745
     * The tag of the given fluidstack.
2746
     */
2747
    public static final IOperator OBJECT_FLUIDSTACK_DATA = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2748
            .output(ValueTypes.NBT).symbol("NBT()").operatorInteract("nbt")
6✔
2749
            .function(input -> {
1✔
2750
                ValueObjectTypeFluidStack.ValueFluidStack fluidStack = input.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2751
                if (fluidStack.getRawValue().getComponentsPatch().isEmpty()) {
5✔
2752
                    return ValueTypeNbt.ValueNbt.of(Optional.empty());
3✔
2753
                }
2754
                return ValueTypeNbt.ValueNbt.of(DataComponentPatch.CODEC.encodeStart(ServerLifecycleHooks.getCurrentServer().registryAccess().createSerializationContext(NbtOps.INSTANCE), fluidStack.getRawValue().getComponentsPatch()).getOrThrow());
13✔
2755
            }).build());
1✔
2756

2757
    /**
2758
     * Create a new fluidstack with the given amount.
2759
     */
2760
    public static final IOperator OBJECT_FLUIDSTACK_WITH_AMOUNT = REGISTRY.register(OperatorBuilders.FLUIDSTACK_2
14✔
2761
            .inputTypes(ValueTypes.OBJECT_FLUIDSTACK, ValueTypes.INTEGER)
2✔
2762
            .output(ValueTypes.OBJECT_FLUIDSTACK).symbolOperator("with_amount").interactName("withAmount")
6✔
2763
            .function(variables -> {
1✔
2764
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2765
                ValueTypeInteger.ValueInteger valueInteger = variables.getValue(1, ValueTypes.INTEGER);
6✔
2766
                FluidStack fluidStack = valueFluidStack.getRawValue().copy();
4✔
2767
                fluidStack.setAmount(valueInteger.getRawValue());
4✔
2768
                return ValueObjectTypeFluidStack.ValueFluidStack.of(fluidStack);
3✔
2769
            }).build());
1✔
2770

2771
    /**
2772
     * Get the data component keys of an fluidstack.
2773
     */
2774
    public static final IOperator OBJECT_FLUIDSTACK_DATA_KEYS = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2775
            .output(ValueTypes.LIST).symbol("data_keys").operatorName("datakeys").interactName("dataKeys")
8✔
2776
            .function(input -> {
1✔
2777
                ValueObjectTypeFluidStack.ValueFluidStack fluidStack = input.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2778
                // Explicitly check for fluid emptiness first, because vanilla sometimes persists NBT when setting stacks to empty
2779
                return ValueTypeList.ValueList.ofList(ValueTypes.STRING,
3✔
2780
                        fluidStack.getRawValue().isEmpty() ?
4!
2781
                                Lists.newArrayList() :
×
2782
                                fluidStack.getRawValue().getComponents().keySet().stream()
5✔
2783
                                        .filter(c -> !c.isTransient())
8!
2784
                                        .map(c -> ValueTypeString.ValueString.of(BuiltInRegistries.DATA_COMPONENT_TYPE.getKey(c).toString()))
8✔
2785
                                        .sorted((o1, o2) -> o1.getRawValue().compareTo(o2.getRawValue()))
1✔
2786
                                        .toList());
2✔
2787
            }).build());
1✔
2788

2789
    /**
2790
     * Get the data component value by key
2791
     */
2792
    public static final IOperator OBJECT_FLUIDSTACK_DATA_VALUE = REGISTRY.register(OperatorBuilders.FLUIDSTACK_2_LONG
14✔
2793
            .inputTypes(ValueTypes.OBJECT_FLUIDSTACK, ValueTypes.STRING)
2✔
2794
            .output(ValueTypes.NBT).symbol("data_value").operatorName("datavalue").interactName("dataValue")
8✔
2795
            .function(input -> {
1✔
2796
                ValueObjectTypeFluidStack.ValueFluidStack fluidStack = input.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2797

2798
                // Determine data component type
2799
                DataComponentType<?> dataComponentType;
2800
                try {
2801
                    dataComponentType = BuiltInRegistries.DATA_COMPONENT_TYPE.get(ResourceLocation.parse(input.getValue(1, ValueTypes.STRING).getRawValue()));
11✔
2802
                } catch (ResourceLocationException e) {
×
2803
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
2804
                }
1✔
2805

2806
                // Fetch component value
2807
                TypedDataComponent<?> typedComponent = fluidStack.getRawValue().getComponents().getTyped(dataComponentType);
6✔
2808
                if (typedComponent == null) {
2✔
2809
                    return ValueTypeNbt.ValueNbt.of((Tag) null);
4✔
2810
                }
2811

2812
                // Encode component value
2813
                try {
2814
                    Tag tag = typedComponent.encodeValue(ServerLifecycleHooks.getCurrentServer().registryAccess().createSerializationContext(NbtOps.INSTANCE)).getOrThrow();
9✔
2815
                    return ValueTypeNbt.ValueNbt.of(tag);
3✔
2816
                } catch (IllegalStateException e) {
×
2817
                    return ValueTypeNbt.ValueNbt.of((Tag) null);
×
2818
                }
2819
            }).build());
1✔
2820

2821
    /**
2822
     * Set the data component value by key
2823
     */
2824
    public static final IOperator OBJECT_FLUIDSTACK_WITH_DATA = REGISTRY.register(OperatorBuilders.FLUIDSTACK_3
18✔
2825
            .inputTypes(ValueTypes.OBJECT_FLUIDSTACK, ValueTypes.STRING, ValueTypes.NBT)
2✔
2826
            .output(ValueTypes.NBT).symbol("with_data").operatorName("withdata").interactName("withData")
8✔
2827
            .function(input -> {
1✔
2828
                ValueObjectTypeFluidStack.ValueFluidStack fluidStack = input.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2829

2830
                // Skip further processing if input value is empty
2831
                Optional<Tag> tagOptional = input.getValue(2, ValueTypes.NBT).getRawValue();
7✔
2832
                if (!tagOptional.isPresent()) {
3!
2833
                    return fluidStack;
×
2834
                }
2835

2836
                // Determine data component type
2837
                DataComponentType<?> dataComponentType;
2838
                try {
2839
                    dataComponentType = BuiltInRegistries.DATA_COMPONENT_TYPE.get(ResourceLocation.parse(input.getValue(1, ValueTypes.STRING).getRawValue()));
11✔
2840
                } catch (ResourceLocationException e) {
×
2841
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
2842
                }
1✔
2843

2844
                // Encode component value
2845
                try {
2846
                    Object value = dataComponentType.codec().decode(ServerLifecycleHooks.getCurrentServer().registryAccess().createSerializationContext(NbtOps.INSTANCE), tagOptional.get()).getOrThrow().getFirst();
14✔
2847
                    fluidStack = ValueObjectTypeFluidStack.ValueFluidStack.of(fluidStack.getRawValue().copy());
5✔
2848
                    fluidStack.getRawValue().set((DataComponentType) dataComponentType, value);
6✔
2849
                    return fluidStack;
2✔
2850
                } catch (IllegalStateException e) {
×
2851
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
2852
                }
2853
            }).build());
1✔
2854

2855
    /**
2856
     * The tag entries of the given fluidstack
2857
     */
2858
    public static final IOperator OBJECT_FLUIDSTACK_TAG = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2859
            .output(ValueTypes.LIST)
2✔
2860
            .symbol("fluid_tag_names").operatorName("tag").interactName("tags")
6✔
2861
            .function(variables -> {
1✔
2862
                ValueObjectTypeFluidStack.ValueFluidStack a = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
6✔
2863
                ImmutableList.Builder<ValueTypeString.ValueString> builder = ImmutableList.builder();
2✔
2864
                if(!a.getRawValue().isEmpty()) {
4✔
2865
                    a.getRawValue().getFluid().builtInRegistryHolder().tags()
7✔
2866
                            .forEach(owningTag -> builder.add(ValueTypeString.ValueString
6✔
2867
                                    .of(owningTag.location().toString())));
3✔
2868
                }
2869
                return ValueTypeList.ValueList.ofList(ValueTypes.STRING, builder.build());
5✔
2870
            }).build());
1✔
2871

2872
    /**
2873
     * Get a list of fluidstacks that correspond to the given tag key.
2874
     */
2875
    public static final IOperator OBJECT_FLUIDSTACK_TAG_STACKS = REGISTRY.register(OperatorBuilders.STRING_1_PREFIX
5✔
2876
            .output(ValueTypes.LIST)
2✔
2877
            .symbol("fluid_tag_values").operatorName("fluidtag").interactName("fluidsByTag")
6✔
2878
            .symbol("fluid_tag_values").operatorName("fluidtag").interactName("fluidsByTag")
6✔
2879
            .inputType(ValueTypes.STRING).renderPattern(IConfigRenderPattern.SUFFIX_1_LONG)
4✔
2880
            .function(variables -> {
1✔
2881
                ValueTypeString.ValueString a = variables.getValue(0, ValueTypes.STRING);
6✔
2882
                ImmutableList.Builder<ValueObjectTypeFluidStack.ValueFluidStack> builder = ImmutableList.builder();
2✔
2883
                if (!StringUtil.isNullOrEmpty(a.getRawValue())) {
4!
2884
                    try {
2885
                        Helpers.getFluidTagValues(a.getRawValue())
4✔
2886
                                .map(ValueObjectTypeFluidStack.ValueFluidStack::of)
3✔
2887
                                .forEach(builder::add);
4✔
2888
                    } catch (ResourceLocationException e) {
×
2889
                        throw new EvaluationException(Component.translatable(e.getMessage()));
×
2890
                    }
1✔
2891
                }
2892
                return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_FLUIDSTACK, builder.build());
5✔
2893
            }).build());
1✔
2894

2895
    /**
2896
     * Get an fluid by name.
2897
     */
2898
    public static final IOperator OBJECT_FLUIDSTACK_BY_NAME = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_PREFIX_LONG
5✔
2899
            .inputType(ValueTypes.STRING).output(ValueTypes.OBJECT_FLUIDSTACK)
4✔
2900
            .symbol("fluid_by_name").operatorName("fluidbyname").interactName("fluidByName")
7✔
2901
            .function(OperatorBuilders.FUNCTION_STRING_TO_RESOURCE_LOCATION
1✔
2902
                    .build(input -> {
1✔
2903
                        Fluid fluid = BuiltInRegistries.FLUID.get(input);
5✔
2904
                        FluidStack fluidStack = FluidStack.EMPTY;
2✔
2905
                        if (fluid != null) {
2!
2906
                            fluidStack = new FluidStack(fluid, FluidHelpers.BUCKET_VOLUME);
6✔
2907
                        }
2908
                        return ValueObjectTypeFluidStack.ValueFluidStack.of(fluidStack);
3✔
2909
                    })).build());
1✔
2910

2911
    /**
2912
     * ----------------------------------- OPERATOR OPERATORS -----------------------------------
2913
     */
2914

2915
    /**
2916
     * Apply for a given operator a given value.
2917
     */
2918
    public static final IOperator OPERATOR_APPLY = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
5✔
2919
            .conditionalOutputTypeDeriver(OperatorBuilders.OPERATOR_CONDITIONAL_OUTPUT_DERIVER)
2✔
2920
            .output(ValueTypes.CATEGORY_ANY).symbolOperatorInteract("apply")
9✔
2921
            .typeValidator(OperatorBuilders.createOperatorTypeValidator(ValueTypes.CATEGORY_ANY))
4✔
2922
            .function(OperatorBuilders.FUNCTION_OPERATOR_TAKE_OPERATOR.build(
2✔
2923
                    input -> {
2924
                        IOperator innerOperator = input.getLeft();
4✔
2925
                        OperatorBase.SafeVariablesGetter variables = input.getRight();
4✔
2926
                        IVariable variable = variables.getVariables()[0];
5✔
2927
                        return ValueHelpers.evaluateOperator(innerOperator, variable);
9✔
2928
                    })).build());
1✔
2929
    static {
2930
        REGISTRY.registerSerializer(new CurriedOperator.Serializer());
5✔
2931
    }
2932

2933
    /**
2934
     * Apply for a given operator the given 2 values.
2935
     */
2936
    public static final IOperator OPERATOR_APPLY_2 = REGISTRY.register(OperatorBuilders.OPERATOR
5✔
2937
            .renderPattern(IConfigRenderPattern.INFIX_2)
2✔
2938
            .conditionalOutputTypeDeriver(OperatorBuilders.OPERATOR_CONDITIONAL_OUTPUT_DERIVER)
15✔
2939
            .inputTypes(ValueTypes.OPERATOR, ValueTypes.CATEGORY_ANY, ValueTypes.CATEGORY_ANY)
2✔
2940
            .output(ValueTypes.CATEGORY_ANY).symbolOperatorInteract("apply2")
13✔
2941
            .typeValidator(OperatorBuilders.createOperatorTypeValidator(ValueTypes.CATEGORY_ANY, ValueTypes.CATEGORY_ANY))
4✔
2942
            .function(OperatorBuilders.FUNCTION_OPERATOR_TAKE_OPERATOR.build(
2✔
2943
                    input -> {
2944
                        IOperator innerOperator = input.getLeft();
4✔
2945
                        OperatorBase.SafeVariablesGetter variables = input.getRight();
4✔
2946
                        IVariable variable0 = variables.getVariables()[0];
5✔
2947
                        IVariable variable1 = variables.getVariables()[1];
5✔
2948
                        return ValueHelpers.evaluateOperator(innerOperator, variable0, variable1);
13✔
2949
                    })).build());
1✔
2950

2951
    /**
2952
     * Apply for a given operator the given 3 values.
2953
     */
2954
    public static final IOperator OPERATOR_APPLY_3 = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
5✔
2955
            .renderPattern(IConfigRenderPattern.INFIX_3)
2✔
2956
            .conditionalOutputTypeDeriver(OperatorBuilders.OPERATOR_CONDITIONAL_OUTPUT_DERIVER)
19✔
2957
            .inputTypes(ValueTypes.OPERATOR, ValueTypes.CATEGORY_ANY, ValueTypes.CATEGORY_ANY, ValueTypes.CATEGORY_ANY)
2✔
2958
            .output(ValueTypes.CATEGORY_ANY).symbolOperatorInteract("apply3")
17✔
2959
            .typeValidator(OperatorBuilders.createOperatorTypeValidator(ValueTypes.CATEGORY_ANY, ValueTypes.CATEGORY_ANY, ValueTypes.CATEGORY_ANY))
4✔
2960
            .function(OperatorBuilders.FUNCTION_OPERATOR_TAKE_OPERATOR.build(
2✔
2961
                    input -> {
2962
                        IOperator innerOperator = input.getLeft();
4✔
2963
                        OperatorBase.SafeVariablesGetter variables = input.getRight();
4✔
2964
                        IVariable variable0 = variables.getVariables()[0];
5✔
2965
                        IVariable variable1 = variables.getVariables()[1];
5✔
2966
                        IVariable variable2 = variables.getVariables()[2];
5✔
2967
                        return ValueHelpers.evaluateOperator(innerOperator, variable0, variable1, variable2);
17✔
2968
                    })).build());
1✔
2969

2970
    /**
2971
     * Apply for a given operator the given list of values.
2972
     */
2973
    public static final IOperator OPERATOR_APPLY_N = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
5✔
2974
            .conditionalOutputTypeDeriver(OperatorBuilders.OPERATOR_CONDITIONAL_OUTPUT_DERIVER_LIST)
11✔
2975
            .inputTypes(ValueTypes.OPERATOR, ValueTypes.LIST)
2✔
2976
            .output(ValueTypes.CATEGORY_ANY).symbolOperatorInteract("apply_n")
9✔
2977
            .typeValidator(OperatorBuilders.createOperatorTypeValidator(ValueTypes.LIST))
4✔
2978
            .function(OperatorBuilders.FUNCTION_OPERATOR_TAKE_OPERATOR_LIST.build(
2✔
2979
                    input -> {
2980
                        IOperator innerOperator = input.getLeft();
4✔
2981
                        OperatorBase.SafeVariablesGetter variables = input.getRight();
4✔
2982
                        IValueTypeListProxy<IValueType<IValue>, IValue> list = variables.getValue(0, ValueTypes.LIST).getRawValue();
7✔
2983
                        return ValueHelpers.evaluateOperator(innerOperator, Iterables.toArray(list, IValue.class));
7✔
2984
                    })).build());
1✔
2985

2986
    /**
2987
     * Apply for a given operator with zero arguments.
2988
     */
2989
    public static final IOperator OPERATOR_APPLY_0 = REGISTRY.register(OperatorBuilders.OPERATOR_1_PREFIX_LONG
5✔
2990
            .conditionalOutputTypeDeriver(OperatorBuilders.OPERATOR_CONDITIONAL_OUTPUT_DERIVER)
2✔
2991
            .output(ValueTypes.CATEGORY_ANY).symbolOperatorInteract("apply0")
5✔
2992
            .typeValidator(OperatorBuilders.createOperatorTypeValidator(new IValueType[0]))
4✔
2993
            .function(OperatorBuilders.FUNCTION_OPERATOR_TAKE_OPERATOR.build(
2✔
2994
                    input -> {
2995
                        IOperator innerOperator = input.getLeft();
4✔
2996
                        return ValueHelpers.evaluateOperator(innerOperator, new IVariable[0]);
5✔
2997
                    })).build());
1✔
2998

2999
    /**
3000
     * Apply the given operator on all elements of a list, resulting in a new list of mapped values.
3001
     */
3002
    public static final IOperator OPERATOR_MAP = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
14✔
3003
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.LIST})
2✔
3004
            .output(ValueTypes.LIST).symbolOperatorInteract("map")
5✔
3005
            .function(OperatorBuilders.FUNCTION_OPERATOR_TAKE_OPERATOR_LIST.build(
2✔
3006
                    input -> {
3007
                        final IOperator innerOperator = input.getLeft();
4✔
3008
                        OperatorBase.SafeVariablesGetter variables = input.getRight();
4✔
3009
                        ValueTypeList.ValueList inputList = variables.getValue(0, ValueTypes.LIST);
6✔
3010
                        return ValueTypeList.ValueList.ofFactory(
6✔
3011
                                new ValueTypeListProxyOperatorMapped(innerOperator, inputList.getRawValue()));
2✔
3012
                    })).build());
1✔
3013

3014
    /**
3015
     * Filter a list of elements by matching them all with the given predicate.
3016
     */
3017
    public static final IOperator OPERATOR_FILTER = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
14✔
3018
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.LIST})
2✔
3019
            .output(ValueTypes.LIST).symbolOperatorInteract("filter")
7✔
3020
            .function(OperatorBuilders.FUNCTION_OPERATOR_TAKE_OPERATOR_LIST.build(
2✔
3021
                    new IOperatorValuePropagator<Pair<IOperator, OperatorBase.SafeVariablesGetter>, IValue>() {
3✔
3022
                        @Override
3023
                        public IValue getOutput(Pair<IOperator, OperatorBase.SafeVariablesGetter> input) throws EvaluationException {
3024
                            final IOperator innerOperator = input.getLeft();
4✔
3025
                            OperatorBase.SafeVariablesGetter variables = input.getRight();
4✔
3026
                            ValueTypeList.ValueList<?, ?> inputList = variables.getValue(0, ValueTypes.LIST);
6✔
3027
                            List<IValue> filtered = Lists.newArrayList();
2✔
3028
                            for (IValue value : inputList.getRawValue()) {
11✔
3029
                                IValue result = ValueHelpers.evaluateOperator(innerOperator, value);
9✔
3030
                                ValueHelpers.validatePredicateOutput(innerOperator, result);
3✔
3031
                                if (((ValueTypeBoolean.ValueBoolean) result).getRawValue()) {
4✔
3032
                                    filtered.add(value);
4✔
3033
                                }
3034
                            }
1✔
3035
                            IValueType valueType = inputList.getRawValue().getValueType();
4✔
3036
                            return ValueTypeList.ValueList.ofList(valueType, filtered);
4✔
3037
                        }
3038
                    })).build());
1✔
3039

3040
    /**
3041
     * Takes the conjunction of two predicates.
3042
     */
3043
    public static final IOperator OPERATOR_CONJUNCTION = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
14✔
3044
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.OPERATOR})
2✔
3045
            .output(ValueTypes.OPERATOR).symbol(".&&.").operatorInteract("conjunction")
7✔
3046
            .function(OperatorBuilders.FUNCTION_TWO_PREDICATES.build(
2✔
3047
                input -> ValueTypeOperator.ValueOperator.of(CombinedOperator.Conjunction.asOperator(input.getLeft(), input.getRight()))
17✔
3048
            )).build());
1✔
3049
    static {
3050
        REGISTRY.registerSerializer(new CombinedOperator.Conjunction.Serializer());
5✔
3051
    }
3052

3053
    /**
3054
     * Takes the disjunction of two predicates.
3055
     */
3056
    public static final IOperator OPERATOR_DISJUNCTION = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
14✔
3057
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.OPERATOR})
2✔
3058
            .output(ValueTypes.OPERATOR).symbol(".||.").operatorInteract("disjunction")
7✔
3059
            .function(OperatorBuilders.FUNCTION_TWO_PREDICATES.build(
2✔
3060
                input -> ValueTypeOperator.ValueOperator.of(CombinedOperator.Disjunction.asOperator(input.getLeft(), input.getRight()))
17✔
3061
            )).build());
1✔
3062
    static {
3063
        REGISTRY.registerSerializer(new CombinedOperator.Disjunction.Serializer());
5✔
3064
    }
3065

3066
    /**
3067
     * Takes the negation of a predicate.
3068
     */
3069
    public static final IOperator OPERATOR_NEGATION = REGISTRY.register(OperatorBuilders.OPERATOR_1_PREFIX_LONG
5✔
3070
            .renderPattern(IConfigRenderPattern.PREFIX_1)
7✔
3071
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR})
2✔
3072
            .output(ValueTypes.OPERATOR).symbol("!.").operatorInteract("negation")
7✔
3073
            .function(OperatorBuilders.FUNCTION_ONE_PREDICATE.build(
2✔
3074
                input -> ValueTypeOperator.ValueOperator.of(CombinedOperator.Negation.asOperator(input))
4✔
3075
            )).build());
1✔
3076
    static {
3077
        REGISTRY.registerSerializer(new CombinedOperator.Negation.Serializer());
5✔
3078
    }
3079

3080
    /**
3081
     * Create a new operator that pipes the output from the first operator to the second operator.
3082
     */
3083
    public static final IOperator OPERATOR_PIPE = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
14✔
3084
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.OPERATOR})
2✔
3085
            .output(ValueTypes.OPERATOR).symbol(".").operatorInteract("pipe")
7✔
3086
            .function(OperatorBuilders.FUNCTION_TWO_OPERATORS.build(
2✔
3087
                input -> ValueTypeOperator.ValueOperator.of(CombinedOperator.Pipe.asOperator(input.getLeft(), input.getRight()))
17✔
3088
            )).build());
1✔
3089
    static {
3090
        REGISTRY.registerSerializer(new CombinedOperator.Pipe.Serializer());
5✔
3091
    }
3092

3093
    /**
3094
     * 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.
3095
     */
3096
    public static final IOperator OPERATOR_PIPE2 = REGISTRY.register(OperatorBuilders.OPERATOR
18✔
3097
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.OPERATOR, ValueTypes.OPERATOR})
2✔
3098
            .renderPattern(IConfigRenderPattern.INFIX_2_LATE)
2✔
3099
            .output(ValueTypes.OPERATOR).symbol(".2").operatorInteract("pipe2")
7✔
3100
            .function(OperatorBuilders.FUNCTION_THREE_OPERATORS.build(
2✔
3101
                input -> ValueTypeOperator.ValueOperator.of(CombinedOperator.Pipe2.asOperator(input.getLeft(), input.getMiddle(), input.getRight()))
23✔
3102
            )).build());
1✔
3103
    static {
3104
        REGISTRY.registerSerializer(new CombinedOperator.Pipe2.Serializer());
5✔
3105
    }
3106

3107
    /**
3108
     * Flip the input parameters of an operator with two inputs.
3109
     */
3110
    public static final IOperator OPERATOR_FLIP = REGISTRY.register(OperatorBuilders.OPERATOR_1_PREFIX_LONG
5✔
3111
            .renderPattern(IConfigRenderPattern.PREFIX_1)
7✔
3112
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR})
2✔
3113
            .output(ValueTypes.OPERATOR).symbolOperatorInteract("flip")
5✔
3114
            .function(OperatorBuilders.FUNCTION_ONE_OPERATOR.build(
2✔
3115
                input -> ValueTypeOperator.ValueOperator.of(CombinedOperator.Flip.asOperator(input))
4✔
3116
            )).build());
1✔
3117
    static {
3118
        REGISTRY.registerSerializer(new CombinedOperator.Flip.Serializer());
5✔
3119
    }
3120

3121
    /**
3122
     * Apply the given operator on all elements of a list to reduce the list to one value.
3123
     */
3124
    public static final IOperator OPERATOR_REDUCE = REGISTRY.register(OperatorBuilders.OPERATOR
18✔
3125
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.LIST, ValueTypes.CATEGORY_ANY})
2✔
3126
            .renderPattern(IConfigRenderPattern.PREFIX_3_LONG)
2✔
3127
            .output(ValueTypes.CATEGORY_ANY).symbolOperatorInteract("reduce")
4✔
3128
            .conditionalOutputTypeDeriver((operator, input) -> input[2].getType())
7✔
3129
            .function(variables -> {
1✔
3130
                IValue accumulator = variables.getValue(2);
4✔
3131
                final IOperator innerOperator = OperatorBuilders.getSafeOperator(
5✔
3132
                        variables.getValue(0, ValueTypes.OPERATOR), accumulator.getType());
4✔
3133
                ValueTypeList.ValueList<IValueType<IValue>, IValue> inputList = variables.getValue(1, ValueTypes.LIST);
6✔
3134
                for (IValue listValue : inputList.getRawValue()) {
11✔
3135
                    accumulator = ValueHelpers.evaluateOperator(innerOperator, accumulator, listValue);
13✔
3136
                }
1✔
3137
                return accumulator;
2✔
3138
            }).build());
1✔
3139

3140
    /**
3141
     * Apply the given operator on all elements of a list to reduce the list to one value.
3142
     */
3143
    public static final IOperator OPERATOR_REDUCE1 = REGISTRY.register(OperatorBuilders.OPERATOR
14✔
3144
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.LIST})
2✔
3145
            .renderPattern(IConfigRenderPattern.PREFIX_2_LONG)
2✔
3146
            .output(ValueTypes.CATEGORY_ANY).symbolOperatorInteract("reduce1")
4✔
3147
            .conditionalOutputTypeDeriver((operator, input) -> {
2✔
3148
                try {
3149
                    IValueTypeListProxy a = ((ValueTypeList.ValueList) input[1].getValue()).getRawValue();
7✔
3150
                    return a.getValueType();
3✔
3151
                } catch (EvaluationException e) {
×
3152
                    return operator.getOutputType();
×
3153
                }
3154
            })
3155
            .function(variables -> {
1✔
3156
                ValueTypeList.ValueList valueList = variables.getValue(1, ValueTypes.LIST);
6✔
3157
                Iterator<IValue> iter = valueList.getRawValue().iterator();
4✔
3158
                if (!iter.hasNext()) {
3✔
3159
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_REDUCE_EMPTY));
6✔
3160
                }
3161

3162
                IValue accumulator = iter.next();
4✔
3163
                final IOperator innerOperator = OperatorBuilders.getSafeOperator(
5✔
3164
                        variables.getValue(0, ValueTypes.OPERATOR), accumulator.getType());
4✔
3165

3166
                while (iter.hasNext()) {
3✔
3167
                    IValue listValue = iter.next();
4✔
3168
                    accumulator = ValueHelpers.evaluateOperator(innerOperator, accumulator, listValue);
13✔
3169
                }
1✔
3170
                return accumulator;
2✔
3171
            }).build());
1✔
3172

3173
    /**
3174
     * Apply for a given operator a given value.
3175
     */
3176
    public static final IOperator OPERATOR_BY_NAME = REGISTRY.register(OperatorBuilders.OPERATOR_1_PREFIX_LONG
5✔
3177
            .inputType(ValueTypes.STRING).output(ValueTypes.OPERATOR)
4✔
3178
            .symbol("op_by_name").operatorName("by_name").interactName("operatorByName")
6✔
3179
            .function(input -> {
1✔
3180
                ValueTypeString.ValueString name = input.getValue(0, ValueTypes.STRING);
6✔
3181
                try {
3182
                    ResourceLocation id = ResourceLocation.parse(name.getRawValue());
4✔
3183
                    IOperator operator = Operators.REGISTRY.getOperator(id);
4✔
3184
                    if (operator == null) {
2✔
3185
                        throw new EvaluationException(Component.translatable(
11✔
3186
                                L10NValues.OPERATOR_ERROR_OPERATORNOTFOUND, name.getRawValue()));
2✔
3187
                    }
3188
                    return ValueTypeOperator.ValueOperator.of(operator);
3✔
3189
                } catch (ResourceLocationException e) {
×
3190
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
3191
                }
3192
            }).build());
1✔
3193

3194
    /**
3195
     * ----------------------------------- NBT OPERATORS -----------------------------------
3196
     */
3197

3198
    /**
3199
     * The number of entries in an NBT tag
3200
     */
3201
    public static final IOperator NBT_COMPOUND_SIZE = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3202
            .output(ValueTypes.INTEGER).operatorName("compound_size").symbol("NBT{}.size").interactName("size")
9✔
3203
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_TO_INT.build(
2✔
3204
                opt -> opt.map(CompoundTag::size).orElse(0)
8✔
3205
            )).build());
1✔
3206

3207
    /**
3208
     * The list of keys in an NBT tag
3209
     */
3210
    public static final IOperator NBT_COMPOUND_KEYS = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3211
            .output(ValueTypes.LIST).operatorName("compound_keys").symbol("NBT{}.keys").interactName("keys")
8✔
3212
            .function(variables -> {
1✔
3213
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3214
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtKeys(value.getRawValue()));
7✔
3215
            }).build());
1✔
3216

3217
    /**
3218
     * If an NBT tag has the given key
3219
     */
3220
    public static final IOperator NBT_COMPOUND_HASKEY = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3221
            .output(ValueTypes.BOOLEAN).operatorName("compound_haskey").symbol("NBT{}.has_key").interactName("hasKey")
9✔
3222
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_BOOLEAN.build(
2✔
3223
                    Optional::isPresent
3224
            )).build());
1✔
3225

3226
    /**
3227
     * The NBT value type of an entry
3228
     */
3229
    public static final IOperator NBT_COMPOUND_VALUE_TYPE = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3230
            .output(ValueTypes.STRING).operatorName("compound_type").symbol("NBT{}.type").interactName("type")
9✔
3231
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_STRING.build(tag -> {
2✔
3232
                if (tag.isPresent()) {
3✔
3233
                    try {
3234
                        return TagTypes.getType(tag.get().getId()).getName();
7✔
3235
                    } catch (IndexOutOfBoundsException e) {
×
3236

3237
                    }
3238
                }
3239
                return "null";
2✔
3240
            })).build());
1✔
3241

3242
    /**
3243
     * The NBT tag value
3244
     */
3245
    public static final IOperator NBT_COMPOUND_VALUE_TAG = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3246
            .output(ValueTypes.NBT).operatorName("compound_value_tag").symbol("NBT{}.get_tag").interactName("getTag")
9✔
3247
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_NBT.build(o -> o)).build());
5✔
3248

3249
    /**
3250
     * The NBT boolean value
3251
     */
3252
    public static final IOperator NBT_COMPOUND_VALUE_BOOLEAN = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3253
            .output(ValueTypes.BOOLEAN).operatorName("compound_value_boolean").symbol("NBT{}.get_boolean").interactName("getBoolean")
9✔
3254
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_BOOLEAN.build(
2✔
3255
                    o -> o.map(tag -> tag instanceof NumericTag && ((NumericTag) tag).getAsByte() != 0).orElse(false)
19!
3256
            )).build());
1✔
3257

3258
    /**
3259
     * The NBT integer value
3260
     */
3261
    public static final IOperator NBT_COMPOUND_VALUE_INTEGER = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3262
            .output(ValueTypes.INTEGER).operatorName("compound_value_integer").symbol("NBT{}.get_integer").interactName("getInteger")
9✔
3263
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_INT.build(
2✔
3264
                    o -> o.map(tag -> tag instanceof NumericTag ? ((NumericTag) tag).getAsInt() : 0).orElse(0)
17!
3265
            )).build());
1✔
3266

3267
    /**
3268
     * The NBT long value
3269
     */
3270
    public static final IOperator NBT_COMPOUND_VALUE_LONG = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3271
            .output(ValueTypes.LONG).operatorName("compound_value_long").symbol("NBT{}.get_long").interactName("getLong")
9✔
3272
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_LONG.build(
2✔
3273
                    o -> o.map(tag -> tag instanceof NumericTag ? ((NumericTag) tag).getAsLong() : 0).orElse(0L)
17!
3274
            )).build());
1✔
3275

3276
    /**
3277
     * The NBT double value
3278
     */
3279
    public static final IOperator NBT_COMPOUND_VALUE_DOUBLE = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3280
            .output(ValueTypes.DOUBLE).operatorName("compound_value_double").symbol("NBT{}.get_double").interactName("getDouble")
9✔
3281
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_DOUBLE.build(
2✔
3282
                    o -> o.map(tag -> tag instanceof NumericTag ? ((NumericTag) tag).getAsDouble() : 0).orElse(0D)
17!
3283
            )).build());
1✔
3284

3285
    /**
3286
     * The NBT string value
3287
     */
3288
    public static final IOperator NBT_COMPOUND_VALUE_STRING = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3289
            .output(ValueTypes.STRING).operatorName("compound_value_string").symbol("NBT{}.get_string").interactName("getString")
9✔
3290
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_STRING.build(
2✔
3291
                    o -> o.map(tag -> tag instanceof StringTag ? tag.getAsString() : "").orElse("")
14!
3292
            )).build());
1✔
3293

3294
    /**
3295
     * The NBT compound value
3296
     */
3297
    public static final IOperator NBT_COMPOUND_VALUE_COMPOUND = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3298
            .output(ValueTypes.NBT).operatorName("compound_value_compound").symbol("NBT{}.get_compound").interactName("getCompound")
9✔
3299
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_NBT.build(
2✔
3300
                    o -> o.map(tag -> tag instanceof CompoundTag ? (CompoundTag) tag : new CompoundTag())
11!
3301
            )).build());
1✔
3302

3303
    /**
3304
     * The NBT tag list value
3305
     */
3306
    public static final IOperator NBT_COMPOUND_VALUE_LIST_TAG = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3307
            .output(ValueTypes.LIST).operatorName("compound_value_list_tag").symbol("NBT{}.get_list_tag").interactName("getListTag")
8✔
3308
            .function(variables -> {
1✔
3309
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3310
                ValueTypeString.ValueString key = variables.getValue(1, ValueTypes.STRING);
6✔
3311
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtValueListTag(key.getRawValue(), value.getRawValue()));
9✔
3312
            }).build());
1✔
3313

3314
    /**
3315
     * The NBT boolean list value
3316
     */
3317
    public static final IOperator NBT_COMPOUND_VALUE_LIST_BYTE = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3318
            .output(ValueTypes.LIST).operatorName("compound_value_list_byte").symbol("NBT{}.get_list_byte").interactName("getListByte")
8✔
3319
            .function(variables -> {
1✔
3320
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3321
                ValueTypeString.ValueString key = variables.getValue(1, ValueTypes.STRING);
6✔
3322
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtValueListByte(key.getRawValue(), value.getRawValue()));
9✔
3323
            }).build());
1✔
3324

3325
    /**
3326
     * The NBT int list value
3327
     */
3328
    public static final IOperator NBT_COMPOUND_VALUE_LIST_INT = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3329
            .output(ValueTypes.LIST).operatorName("compound_value_list_int").symbol("NBT{}.get_list_int").interactName("getListInt")
8✔
3330
            .function(variables -> {
1✔
3331
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3332
                ValueTypeString.ValueString key = variables.getValue(1, ValueTypes.STRING);
6✔
3333
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtValueListInt(key.getRawValue(), value.getRawValue()));
9✔
3334
            }).build());
1✔
3335

3336
    /**
3337
     * The NBT long list value
3338
     */
3339
    public static final IOperator NBT_COMPOUND_VALUE_LIST_LONG = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3340
            .output(ValueTypes.LIST).operatorName("compound_value_list_long").symbol("NBT{}.get_list_long").interactName("getListLong")
8✔
3341
            .function(variables -> {
1✔
3342
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3343
                ValueTypeString.ValueString key = variables.getValue(1, ValueTypes.STRING);
6✔
3344
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtValueListLong(key.getRawValue(), value.getRawValue()));
9✔
3345
            }).build());
1✔
3346

3347
    /**
3348
     * Remove an entry from an NBT compound
3349
     */
3350
    public static final IOperator NBT_COMPOUND_WITHOUT = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3351
            .output(ValueTypes.NBT).operatorName("compound_without").symbol("NBT{}.without").interactName("without")
8✔
3352
            .function(variables -> {
1✔
3353
                ValueTypeNbt.ValueNbt valueNbt = variables.getValue(0, ValueTypes.NBT);
6✔
3354
                Optional<Tag> tag = valueNbt.getRawValue();
3✔
3355
                if (tag.isPresent()) {
3!
3356
                    if (!(tag.get() instanceof CompoundTag)) {
4!
3357
                        return ValueTypeNbt.ValueNbt.of();
×
3358
                    }
3359
                    ValueTypeString.ValueString valueString = variables.getValue(1, ValueTypes.STRING);
6✔
3360
                    String key = valueString.getRawValue();
3✔
3361
                    CompoundTag tagCompound = (CompoundTag) tag.get();
4✔
3362
                    if (tagCompound.contains(key)) {
4!
3363
                        // Copy the tag to ensure immutability
3364
                        tagCompound = tagCompound.copy();
3✔
3365
                        tagCompound.remove(key);
3✔
3366
                    }
3367
                    return ValueTypeNbt.ValueNbt.of(tagCompound);
3✔
3368
                }
3369
                return valueNbt;
×
3370
            }).build());
1✔
3371

3372

3373

3374
    /**
3375
     * Set an NBT compound boolean value
3376
     */
3377
    public static final IOperator NBT_COMPOUND_WITH_BOOLEAN = REGISTRY.register(OperatorBuilders.NBT_3
5✔
3378
            .renderPattern(IConfigRenderPattern.INFIX_2_VERYLONG)
15✔
3379
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.BOOLEAN)
2✔
3380
            .operatorName("compound_with_boolean").symbol("NBT{}.with_boolean").interactName("withBoolean")
7✔
3381
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3382
                ValueTypeBoolean.ValueBoolean value = input.getRight().getValue(0, ValueTypes.BOOLEAN);
8✔
3383
                input.getLeft().ifPresent(tag -> tag.putBoolean(input.getMiddle(), value.getRawValue()));
15✔
3384
                return input.getLeft();
4✔
3385
            })).build());
1✔
3386

3387
    /**
3388
     * Set an NBT compound short value
3389
     */
3390
    public static final IOperator NBT_COMPOUND_WITH_SHORT = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3391
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.INTEGER)
2✔
3392
            .operatorName("compound_with_short").symbol("NBT{}.with_short").interactName("withShort")
7✔
3393
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3394
                ValueTypeInteger.ValueInteger value = input.getRight().getValue(0, ValueTypes.INTEGER);
8✔
3395
                input.getLeft().ifPresent(tag -> tag.putShort(input.getMiddle(), (short) value.getRawValue()));
16✔
3396
                return input.getLeft();
4✔
3397
            })).build());
1✔
3398

3399
    /**
3400
     * Set an NBT compound integer value
3401
     */
3402
    public static final IOperator NBT_COMPOUND_WITH_INTEGER = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3403
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.INTEGER)
2✔
3404
            .operatorName("compound_with_integer").symbol("NBT{}.with_integer").interactName("withInteger")
7✔
3405
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3406
                ValueTypeInteger.ValueInteger value = input.getRight().getValue(0, ValueTypes.INTEGER);
8✔
3407
                input.getLeft().ifPresent(tag -> tag.putInt(input.getMiddle(), value.getRawValue()));
15✔
3408
                return input.getLeft();
4✔
3409
            })).build());
1✔
3410

3411
    /**
3412
     * Set an NBT compound long value
3413
     */
3414
    public static final IOperator NBT_COMPOUND_WITH_LONG = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3415
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.LONG)
2✔
3416
            .operatorName("compound_with_long").symbol("NBT{}.with_long").interactName("withLong")
7✔
3417
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3418
                ValueTypeLong.ValueLong value = input.getRight().getValue(0, ValueTypes.LONG);
8✔
3419
                input.getLeft().ifPresent(tag -> tag.putLong(input.getMiddle(), value.getRawValue()));
15✔
3420
                return input.getLeft();
4✔
3421
            })).build());
1✔
3422

3423
    /**
3424
     * Set an NBT compound double value
3425
     */
3426
    public static final IOperator NBT_COMPOUND_WITH_DOUBLE = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3427
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.DOUBLE)
2✔
3428
            .operatorName("compound_with_double").symbol("NBT{}.with_double").interactName("withDouble")
7✔
3429
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3430
                ValueTypeDouble.ValueDouble value = input.getRight().getValue(0, ValueTypes.DOUBLE);
8✔
3431
                input.getLeft().ifPresent(tag -> tag.putDouble(input.getMiddle(), value.getRawValue()));
15✔
3432
                return input.getLeft();
4✔
3433
            })).build());
1✔
3434

3435
    /**
3436
     * Set an NBT compound float value
3437
     */
3438
    public static final IOperator NBT_COMPOUND_WITH_FLOAT = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3439
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.DOUBLE)
2✔
3440
            .operatorName("compound_with_float").symbol("NBT{}.with_float").interactName("withFloat")
7✔
3441
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3442
                ValueTypeDouble.ValueDouble value = input.getRight().getValue(0, ValueTypes.DOUBLE);
8✔
3443
                input.getLeft().ifPresent(tag -> tag.putFloat(input.getMiddle(), (float) value.getRawValue()));
16✔
3444
                return input.getLeft();
4✔
3445
            })).build());
1✔
3446

3447
    /**
3448
     * Set an NBT compound string value
3449
     */
3450
    public static final IOperator NBT_COMPOUND_WITH_STRING = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3451
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.STRING)
2✔
3452
            .operatorName("compound_with_string").symbol("NBT{}.with_string").interactName("withString")
7✔
3453
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3454
                ValueTypeString.ValueString value = input.getRight().getValue(0, ValueTypes.STRING);
8✔
3455
                input.getLeft().ifPresent(tag -> tag.putString(input.getMiddle(), value.getRawValue()));
15✔
3456
                return input.getLeft();
4✔
3457
            })).build());
1✔
3458

3459
    /**
3460
     * Set an NBT compound compound value
3461
     */
3462
    public static final IOperator NBT_COMPOUND_WITH_COMPOUND = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3463
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.NBT)
2✔
3464
            .operatorName("compound_with_tag").symbol("NBT{}.with_tag").interactName("withTag")
7✔
3465
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3466
                ValueTypeNbt.ValueNbt value = input.getRight().getValue(0, ValueTypes.NBT);
8✔
3467
                input.getLeft()
6✔
3468
                        .ifPresent(tag -> value.getRawValue()
7✔
3469
                                .ifPresent(v -> tag.put(input.getMiddle(), v)));
9✔
3470
                return input.getLeft();
4✔
3471
            })).build());
1✔
3472

3473
    /**
3474
     * Set an NBT compound tag list value
3475
     */
3476
    public static final IOperator NBT_COMPOUND_WITH_LIST_TAG = REGISTRY.register(OperatorBuilders.NBT_3
5✔
3477
            .renderPattern(IConfigRenderPattern.INFIX_2_VERYLONG)
15✔
3478
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.LIST)
2✔
3479
            .operatorName("compound_with_list_tag").symbol("NBT{}.with_tag_list").interactName("withTagList")
9✔
3480
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(new IOperatorValuePropagator<Triple<Optional<CompoundTag>, String, OperatorBase.SafeVariablesGetter>, Optional<CompoundTag>>() {
5✔
3481
                @Override
3482
                public Optional<CompoundTag> getOutput(Triple<Optional<CompoundTag>, String, OperatorBase.SafeVariablesGetter> input) throws EvaluationException {
3483
                    ValueTypeList.ValueList<?, ?> value = input.getRight().getValue(0, ValueTypes.LIST);
8✔
3484
                    input.getLeft().ifPresent(tag -> tag.put(input.getMiddle(),
16✔
3485
                            NbtHelpers.getListNbtTag(value, NBT_COMPOUND_WITH_LIST_TAG.getLocalizedNameFull())));
2✔
3486
                    return input.getLeft();
4✔
3487
                }
3488
            })).build());
1✔
3489

3490
    /**
3491
     * Set an NBT compound byte list value
3492
     */
3493
    public static final IOperator NBT_COMPOUND_WITH_LIST_BYTE = REGISTRY.register(OperatorBuilders.NBT_3
5✔
3494
            .renderPattern(IConfigRenderPattern.INFIX_2_VERYLONG)
15✔
3495
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.LIST)
2✔
3496
            .operatorName("compound_with_list_byte").symbol("NBT{}.with_byte_list").interactName("withByteList")
9✔
3497
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(new IOperatorValuePropagator<Triple<Optional<CompoundTag>, String, OperatorBase.SafeVariablesGetter>, Optional<CompoundTag>>() {
5✔
3498
                @Override
3499
                public Optional<CompoundTag> getOutput(Triple<Optional<CompoundTag>, String, OperatorBase.SafeVariablesGetter> input) throws EvaluationException {
3500
                    ValueTypeList.ValueList<?, ?> value = input.getRight().getValue(0, ValueTypes.LIST);
8✔
3501
                    input.getLeft().ifPresent(tag -> tag.put(input.getMiddle(),
16✔
3502
                            NbtHelpers.getListNbtByte(value, NBT_COMPOUND_WITH_LIST_BYTE.getLocalizedNameFull())));
2✔
3503
                    return input.getLeft();
4✔
3504
                }
3505
            })).build());
1✔
3506

3507
    /**
3508
     * Set an NBT compound int list value
3509
     */
3510
    public static final IOperator NBT_COMPOUND_WITH_LIST_INT = REGISTRY.register(OperatorBuilders.NBT_3
5✔
3511
            .renderPattern(IConfigRenderPattern.INFIX_2_VERYLONG)
15✔
3512
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.LIST)
2✔
3513
            .operatorName("compound_with_list_int").symbol("NBT{}.with_int_list").interactName("withIntList")
9✔
3514
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(new IOperatorValuePropagator<Triple<Optional<CompoundTag>, String, OperatorBase.SafeVariablesGetter>, Optional<CompoundTag>>() {
5✔
3515
                @Override
3516
                public Optional<CompoundTag> getOutput(Triple<Optional<CompoundTag>, String, OperatorBase.SafeVariablesGetter> input) throws EvaluationException {
3517
                    ValueTypeList.ValueList<?, ?> value = input.getRight().getValue(0, ValueTypes.LIST);
8✔
3518
                    input.getLeft().ifPresent(tag -> tag.put(input.getMiddle(),
16✔
3519
                            NbtHelpers.getListNbtInt(value, NBT_COMPOUND_WITH_LIST_INT.getLocalizedNameFull())));
2✔
3520
                    return input.getLeft();
4✔
3521
                }
3522
            })).build());
1✔
3523

3524
    /**
3525
     * Set an NBT compound long list value
3526
     */
3527
    public static final IOperator NBT_COMPOUND_WITH_LIST_LONG = REGISTRY.register(OperatorBuilders.NBT_3
5✔
3528
            .renderPattern(IConfigRenderPattern.INFIX_2_VERYLONG)
15✔
3529
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.LIST)
2✔
3530
            .operatorName("compound_with_list_long").symbol("NBT{}.with_list_long").interactName("withListLong")
9✔
3531
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(new IOperatorValuePropagator<Triple<Optional<CompoundTag>, String, OperatorBase.SafeVariablesGetter>, Optional<CompoundTag>>() {
5✔
3532
                @Override
3533
                public Optional<CompoundTag> getOutput(Triple<Optional<CompoundTag>, String, OperatorBase.SafeVariablesGetter> input) throws EvaluationException {
3534
                    ValueTypeList.ValueList<?, ?> value = input.getRight().getValue(0, ValueTypes.LIST);
8✔
3535
                    input.getLeft().ifPresent(tag -> tag.put(input.getMiddle(),
16✔
3536
                            NbtHelpers.getListNbtLong(value, NBT_COMPOUND_WITH_LIST_LONG.getLocalizedNameFull())));
2✔
3537
                    return input.getLeft();
4✔
3538
                }
3539
            })).build());
1✔
3540

3541
    /**
3542
     * Check if the first NBT compound tag is a subset of the second NBT compound tag.
3543
     */
3544
    public static final IOperator NBT_COMPOUND_SUBSET = REGISTRY.register(OperatorBuilders.NBT_2_NBT
5✔
3545
            .output(ValueTypes.BOOLEAN).operatorName("compound_subset").symbol("NBT{}.⊆").interactName("isSubset")
8✔
3546
            .function(variables -> {
1✔
3547
                ValueTypeNbt.ValueNbt valueNbt0 = variables.getValue(0, ValueTypes.NBT);
6✔
3548
                ValueTypeNbt.ValueNbt valueNbt1 = variables.getValue(1, ValueTypes.NBT);
6✔
3549
                if (valueNbt0.getRawValue().isPresent()
5!
3550
                        && valueNbt1.getRawValue().isPresent()
4!
3551
                        && valueNbt0.getRawValue().get() instanceof CompoundTag
5!
3552
                        && valueNbt1.getRawValue().get() instanceof CompoundTag) {
4!
3553
                    return ValueTypeBoolean.ValueBoolean.of(NbtHelpers.nbtMatchesSubset((CompoundTag) valueNbt0.getRawValue().get(), (CompoundTag) valueNbt1.getRawValue().get(), true));
12✔
3554
                }
3555
                return ValueTypeBoolean.ValueBoolean.of(false);
×
3556
            }).build());
1✔
3557

3558
    /**
3559
     * The union of the given NBT compound tags. Nested tags will be joined recusively.
3560
     */
3561
    public static final IOperator NBT_COMPOUND_UNION = REGISTRY.register(OperatorBuilders.NBT_2_NBT
5✔
3562
            .output(ValueTypes.NBT).operatorName("compound_union").symbol("NBT{}.∪").interactName("union")
8✔
3563
            .function(variables -> {
1✔
3564
                ValueTypeNbt.ValueNbt valueNbt0 = variables.getValue(0, ValueTypes.NBT);
6✔
3565
                ValueTypeNbt.ValueNbt valueNbt1 = variables.getValue(1, ValueTypes.NBT);
6✔
3566
                if (valueNbt0.getRawValue().isPresent()
5!
3567
                        && valueNbt1.getRawValue().isPresent()
4!
3568
                        && valueNbt0.getRawValue().get() instanceof CompoundTag
5!
3569
                        && valueNbt1.getRawValue().get() instanceof CompoundTag) {
4!
3570
                    return ValueTypeNbt.ValueNbt.of(NbtHelpers.union((CompoundTag) valueNbt0.getRawValue().get(), (CompoundTag) valueNbt1.getRawValue().get()));
19✔
3571
                }
3572
                return ValueTypeNbt.ValueNbt.of();
×
3573
            }).build());
1✔
3574

3575
    /**
3576
     * The intersection of the given NBT compound tags. Nested tags will be intersected recusively.
3577
     */
3578
    public static final IOperator NBT_COMPOUND_INTERSECTION = REGISTRY.register(OperatorBuilders.NBT_2_NBT
5✔
3579
            .output(ValueTypes.NBT).operatorName("compound_intersection").symbol("NBT{}.∩").interactName("intersection")
8✔
3580
            .function(variables -> {
1✔
3581
                ValueTypeNbt.ValueNbt valueNbt0 = variables.getValue(0, ValueTypes.NBT);
6✔
3582
                ValueTypeNbt.ValueNbt valueNbt1 = variables.getValue(1, ValueTypes.NBT);
6✔
3583
                if (valueNbt0.getRawValue().isPresent()
5!
3584
                        && valueNbt1.getRawValue().isPresent()
4!
3585
                        && valueNbt0.getRawValue().get() instanceof CompoundTag
5!
3586
                        && valueNbt1.getRawValue().get() instanceof CompoundTag) {
4!
3587
                    return ValueTypeNbt.ValueNbt.of(NbtHelpers.intersection((CompoundTag) valueNbt0.getRawValue().get(), (CompoundTag) valueNbt1.getRawValue().get()));
19✔
3588
                }
3589
                return ValueTypeNbt.ValueNbt.of();
×
3590
            }).build());
1✔
3591

3592
    /**
3593
     * The difference of the given NBT compound tags. Nested tags will be subtracted recusively.
3594
     */
3595
    public static final IOperator NBT_COMPOUND_MINUS = REGISTRY.register(OperatorBuilders.NBT_2_NBT
5✔
3596
            .output(ValueTypes.NBT).operatorName("compound_minus").symbol("NBT{}.∖").interactName("minus")
8✔
3597
            .function(variables -> {
1✔
3598
                ValueTypeNbt.ValueNbt valueNbt0 = variables.getValue(0, ValueTypes.NBT);
6✔
3599
                ValueTypeNbt.ValueNbt valueNbt1 = variables.getValue(1, ValueTypes.NBT);
6✔
3600
                if (valueNbt0.getRawValue().isPresent()
5!
3601
                        && valueNbt1.getRawValue().isPresent()
4!
3602
                        && valueNbt0.getRawValue().get() instanceof CompoundTag
5!
3603
                        && valueNbt1.getRawValue().get() instanceof CompoundTag) {
4!
3604
                    return ValueTypeNbt.ValueNbt.of(NbtHelpers.minus((CompoundTag) valueNbt0.getRawValue().get(), (CompoundTag) valueNbt1.getRawValue().get()));
11✔
3605
                }
3606
                return ValueTypeNbt.ValueNbt.of();
×
3607
            }).build());
1✔
3608

3609
    /**
3610
     * The boolean value of an NBT value
3611
     */
3612
    public static final IOperator NBT_AS_BOOLEAN = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3613
            .output(ValueTypes.BOOLEAN).operatorName("as_boolean").symbol("NBT.as_boolean").interactName("asBoolean")
9✔
3614
            .function(OperatorBuilders.FUNCTION_NBT_TO_BOOLEAN.build(
2✔
3615
                    o -> o.map(tag -> tag instanceof ByteTag && ((ByteTag) tag).getAsByte() != 0).orElse(false)
20!
3616
            )).build());
1✔
3617

3618
    /**
3619
     * The byte value of an NBT value
3620
     */
3621
    public static final IOperator NBT_AS_BYTE = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3622
            .output(ValueTypes.INTEGER).operatorName("as_byte").symbol("NBT.as_byte").interactName("asByte")
9✔
3623
            .function(OperatorBuilders.FUNCTION_NBT_TO_INT.build(
2✔
3624
                    o -> o.map(tag -> tag instanceof NumericTag ? ((NumericTag) tag).getAsInt() : 0).orElse(0)
18✔
3625
            )).build());
1✔
3626

3627
    /**
3628
     * The short value of an NBT value
3629
     */
3630
    public static final IOperator NBT_AS_SHORT = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3631
            .output(ValueTypes.INTEGER).operatorName("as_short").symbol("NBT.as_short").interactName("asShort")
9✔
3632
            .function(OperatorBuilders.FUNCTION_NBT_TO_INT.build(
2✔
3633
                    o -> o.map(tag -> tag instanceof NumericTag ? ((NumericTag) tag).getAsInt() : 0).orElse(0)
18✔
3634
            )).build());
1✔
3635

3636
    /**
3637
     * The int value of an NBT value
3638
     */
3639
    public static final IOperator NBT_AS_INT = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3640
            .output(ValueTypes.INTEGER).operatorName("as_int").symbol("NBT.as_int").interactName("asInt")
9✔
3641
            .function(OperatorBuilders.FUNCTION_NBT_TO_INT.build(
2✔
3642
                    o -> o.map(tag -> tag instanceof NumericTag ? ((NumericTag) tag).getAsInt() : 0).orElse(0)
18✔
3643
            )).build());
1✔
3644

3645
    /**
3646
     * The long value of an NBT value
3647
     */
3648
    public static final IOperator NBT_AS_LONG = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3649
            .output(ValueTypes.LONG).operatorName("as_long").symbol("NBT.as_long").interactName("asLong")
9✔
3650
            .function(OperatorBuilders.FUNCTION_NBT_TO_LONG.build(
2✔
3651
                    o -> o.map(tag -> tag instanceof NumericTag ? ((NumericTag) tag).getAsLong() : 0L).orElse(0L)
18✔
3652
            )).build());
1✔
3653

3654
    /**
3655
     * The double value of an NBT value
3656
     */
3657
    public static final IOperator NBT_AS_DOUBLE = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3658
            .output(ValueTypes.DOUBLE).operatorName("as_double").symbol("NBT.as_double").interactName("asDouble")
9✔
3659
            .function(OperatorBuilders.FUNCTION_NBT_TO_DOUBLE.build(
2✔
3660
                    o -> o.map(tag -> tag instanceof NumericTag ? ((NumericTag) tag).getAsDouble() : 0D).orElse(0D)
18✔
3661
            )).build());
1✔
3662

3663
    /**
3664
     * The float value of an NBT value
3665
     */
3666
    public static final IOperator NBT_AS_FLOAT = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3667
            .output(ValueTypes.DOUBLE).operatorName("as_float").symbol("NBT.as_float").interactName("asFloat")
9✔
3668
            .function(OperatorBuilders.FUNCTION_NBT_TO_DOUBLE.build(
2✔
3669
                    o -> o.map(tag -> tag instanceof NumericTag ? ((NumericTag) tag).getAsFloat() : 0D).orElse(0D)
19✔
3670
            )).build());
1✔
3671

3672
    /**
3673
     * The string value of an NBT value
3674
     */
3675
    public static final IOperator NBT_AS_STRING = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3676
            .output(ValueTypes.STRING).operatorName("as_string").symbol("NBT.as_string").interactName("asString")
9✔
3677
            .function(OperatorBuilders.FUNCTION_NBT_TO_STRING.build(
2✔
3678
                    o -> o.map(tag -> tag instanceof StringTag ? ((StringTag) tag).getAsString() : "").orElse("")
16✔
3679
            )).build());
1✔
3680

3681
    /**
3682
     * The tag list value of an NBT value
3683
     */
3684
    public static final IOperator NBT_AS_TAG_LIST = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3685
            .output(ValueTypes.LIST).operatorName("as_tag_list").symbol("NBT.as_tag_list").interactName("asTagList")
8✔
3686
            .function(variables -> {
1✔
3687
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3688
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtAsListTag(value.getRawValue()));
7✔
3689
            }).build());
1✔
3690

3691
    /**
3692
     * The byte list value of an NBT value
3693
     */
3694
    public static final IOperator NBT_AS_BYTE_LIST = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3695
            .output(ValueTypes.LIST).operatorName("as_byte_list").symbol("NBT.as_byte_list").interactName("asByteList")
8✔
3696
            .function(variables -> {
1✔
3697
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3698
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtAsListByte(value.getRawValue()));
7✔
3699
            }).build());
1✔
3700

3701
    /**
3702
     * The int list value of an NBT value
3703
     */
3704
    public static final IOperator NBT_AS_INT_LIST = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3705
            .output(ValueTypes.LIST).operatorName("as_int_list").symbol("NBT.as_int_list").interactName("asIntList")
8✔
3706
            .function(variables -> {
1✔
3707
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3708
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtAsListInt(value.getRawValue()));
7✔
3709
            }).build());
1✔
3710

3711
    /**
3712
     * The long list value of an NBT value
3713
     */
3714
    public static final IOperator NBT_AS_LONG_LIST = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3715
            .output(ValueTypes.LIST).operatorName("as_long_list").symbol("NBT.as_long_list").interactName("asLongList")
8✔
3716
            .function(variables -> {
1✔
3717
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3718
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtAsListLong(value.getRawValue()));
7✔
3719
            }).build());
1✔
3720

3721
    /**
3722
     * The NBT value of a boolean value
3723
     */
3724
    public static final IOperator NBT_FROM_BOOLEAN = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3725
            .inputType(ValueTypes.BOOLEAN).output(ValueTypes.NBT)
4✔
3726
            .operatorName("from_boolean").symbol("NBT.from_boolean").interactName("asNbt")
6✔
3727
            .function(variables -> {
1✔
3728
                ValueTypeBoolean.ValueBoolean value = variables.getValue(0, ValueTypes.BOOLEAN);
6✔
3729
                return ValueTypeNbt.ValueNbt.of(ByteTag.valueOf(value.getRawValue()));
5✔
3730
            }).build());
1✔
3731

3732
    /**
3733
     * The NBT value of a short value
3734
     */
3735
    public static final IOperator NBT_FROM_SHORT = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3736
            .inputType(ValueTypes.INTEGER).output(ValueTypes.NBT)
4✔
3737
            .operatorName("from_short").symbol("NBT.from_short").interactName("asNbt", "short", true)
8✔
3738
            .function(variables -> {
1✔
3739
                ValueTypeInteger.ValueInteger value = variables.getValue(0, ValueTypes.INTEGER);
6✔
3740
                return ValueTypeNbt.ValueNbt.of(ShortTag.valueOf((short) value.getRawValue()));
6✔
3741
            }).build());
1✔
3742

3743
    /**
3744
     * The NBT value of a byte value
3745
     */
3746
    public static final IOperator NBT_FROM_BYTE = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3747
            .inputType(ValueTypes.INTEGER).output(ValueTypes.NBT)
4✔
3748
            .operatorName("from_byte").symbol("NBT.from_byte").interactName("asNbt", "byte", true)
8✔
3749
            .function(variables -> {
1✔
3750
                ValueTypeInteger.ValueInteger value = variables.getValue(0, ValueTypes.INTEGER);
6✔
3751
                return ValueTypeNbt.ValueNbt.of(ByteTag.valueOf((byte) value.getRawValue()));
6✔
3752
            }).build());
1✔
3753

3754
    /**
3755
     * The NBT value of an int value
3756
     */
3757
    public static final IOperator NBT_FROM_INT = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3758
            .inputType(ValueTypes.INTEGER).output(ValueTypes.NBT)
4✔
3759
            .operatorName("from_int").symbol("NBT.from_int").interactName("asNbt")
6✔
3760
            .function(variables -> {
1✔
3761
                ValueTypeInteger.ValueInteger value = variables.getValue(0, ValueTypes.INTEGER);
6✔
3762
                return ValueTypeNbt.ValueNbt.of(IntTag.valueOf(value.getRawValue()));
5✔
3763
            }).build());
1✔
3764

3765
    /**
3766
     * The NBT value of a long value
3767
     */
3768
    public static final IOperator NBT_FROM_LONG = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3769
            .inputType(ValueTypes.LONG).output(ValueTypes.NBT)
4✔
3770
            .operatorName("from_long").symbol("NBT.from_long").interactName("asNbt")
6✔
3771
            .function(variables -> {
1✔
3772
                ValueTypeLong.ValueLong value = variables.getValue(0, ValueTypes.LONG);
6✔
3773
                return ValueTypeNbt.ValueNbt.of(LongTag.valueOf(value.getRawValue()));
5✔
3774
            }).build());
1✔
3775

3776
    /**
3777
     * The NBT value of a double value
3778
     */
3779
    public static final IOperator NBT_FROM_DOUBLE = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3780
            .inputType(ValueTypes.DOUBLE).output(ValueTypes.NBT)
4✔
3781
            .operatorName("from_double").symbol("NBT.from_double").interactName("asNbt")
6✔
3782
            .function(variables -> {
1✔
3783
                ValueTypeDouble.ValueDouble value = variables.getValue(0, ValueTypes.DOUBLE);
6✔
3784
                return ValueTypeNbt.ValueNbt.of(DoubleTag.valueOf(value.getRawValue()));
5✔
3785
            }).build());
1✔
3786

3787
    /**
3788
     * The NBT value of a float value
3789
     */
3790
    public static final IOperator NBT_FROM_FLOAT = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3791
            .inputType(ValueTypes.DOUBLE).output(ValueTypes.NBT)
4✔
3792
            .operatorName("from_float").symbol("NBT.from_float").interactName("asNbt", "float", true)
8✔
3793
            .function(variables -> {
1✔
3794
                ValueTypeDouble.ValueDouble value = variables.getValue(0, ValueTypes.DOUBLE);
6✔
3795
                return ValueTypeNbt.ValueNbt.of(FloatTag.valueOf((float) value.getRawValue()));
6✔
3796
            }).build());
1✔
3797

3798
    /**
3799
     * The NBT value of a string value
3800
     */
3801
    public static final IOperator NBT_FROM_STRING = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3802
            .inputType(ValueTypes.STRING).output(ValueTypes.NBT)
4✔
3803
            .operatorName("from_string").symbol("NBT.from_string").interactName("asNbt")
6✔
3804
            .function(variables -> {
1✔
3805
                ValueTypeString.ValueString value = variables.getValue(0, ValueTypes.STRING);
6✔
3806
                return ValueTypeNbt.ValueNbt.of(StringTag.valueOf(value.getRawValue()));
5✔
3807
            }).build());
1✔
3808

3809
    /**
3810
     * The NBT value of a tag list value
3811
     */
3812
    public static final IOperator NBT_FROM_TAG_LIST = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3813
            .inputType(ValueTypes.LIST).output(ValueTypes.NBT)
4✔
3814
            .operatorName("from_tag_list").symbol("NBT.from_tag_list").interactName("asNbt", "tagList", true)
10✔
3815
            .function(new OperatorBase.IFunction() {
4✔
3816
                @Override
3817
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
3818
                    ValueTypeList.ValueList value = variables.getValue(0, ValueTypes.LIST);
6✔
3819
                    return ValueTypeNbt.ValueNbt.of(NbtHelpers.getListNbtTag(value, NBT_FROM_TAG_LIST.getLocalizedNameFull()));
6✔
3820
                }
3821
            }).build());
1✔
3822

3823
    /**
3824
     * The NBT value of a byte list value
3825
     */
3826
    public static final IOperator NBT_FROM_BYTE_LIST = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3827
            .inputType(ValueTypes.LIST).output(ValueTypes.NBT)
4✔
3828
            .operatorName("from_byte_list").symbol("NBT.from_byte_list").interactName("asNbt", "byteList", true)
10✔
3829
            .function(new OperatorBase.IFunction() {
4✔
3830
                @Override
3831
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
3832
                    ValueTypeList.ValueList value = variables.getValue(0, ValueTypes.LIST);
6✔
3833
                    return ValueTypeNbt.ValueNbt.of(NbtHelpers.getListNbtByte(value, NBT_FROM_BYTE_LIST.getLocalizedNameFull()));
6✔
3834
                }
3835
            }).build());
1✔
3836

3837
    /**
3838
     * The NBT value of a int list value
3839
     */
3840
    public static final IOperator NBT_FROM_INT_LIST = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3841
            .inputType(ValueTypes.LIST).output(ValueTypes.NBT)
4✔
3842
            .operatorName("from_int_list").symbol("NBT.from_int_list").interactName("asNbt", "intList", true)
10✔
3843
            .function(new OperatorBase.IFunction() {
4✔
3844
                @Override
3845
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
3846
                    ValueTypeList.ValueList value = variables.getValue(0, ValueTypes.LIST);
6✔
3847
                    return ValueTypeNbt.ValueNbt.of(NbtHelpers.getListNbtInt(value, NBT_FROM_INT_LIST.getLocalizedNameFull()));
6✔
3848
                }
3849
            }).build());
1✔
3850

3851
    /**
3852
     * The NBT value of a long list value
3853
     */
3854
    public static final IOperator NBT_FROM_LONG_LIST = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3855
            .inputType(ValueTypes.LIST).output(ValueTypes.NBT)
4✔
3856
            .operatorName("from_long_list").symbol("NBT.from_long_list").interactName("asNbt", "longList", true)
10✔
3857
            .function(new OperatorBase.IFunction() {
4✔
3858
                @Override
3859
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
3860
                    ValueTypeList.ValueList value = variables.getValue(0, ValueTypes.LIST);
6✔
3861
                    return ValueTypeNbt.ValueNbt.of(NbtHelpers.getListNbtLong(value, NBT_FROM_LONG_LIST.getLocalizedNameFull()));
6✔
3862
                }
3863
            }).build());
1✔
3864

3865
    /**
3866
     * Apply the given NBT path expression on the given NBT value and get the first result.
3867
     */
3868
    public static final IOperator NBT_PATH_MATCH_FIRST = REGISTRY.register(OperatorBuilders.NBT_2
14✔
3869
            .inputTypes(ValueTypes.STRING, ValueTypes.NBT).output(ValueTypes.NBT)
4✔
3870
            .operatorName("path_match_first").symbol("NBT.path_match_first").interactName("nbtPathMatchFirst")
6✔
3871
            .function(variables -> {
1✔
3872
                ValueTypeString.ValueString string = variables.getValue(0, ValueTypes.STRING);
6✔
3873
                ValueTypeNbt.ValueNbt nbt = variables.getValue(1, ValueTypes.NBT);
6✔
3874
                INbtPathExpression expression = null;
2✔
3875
                try {
3876
                    expression = NbtPath.parse(string.getRawValue());
4✔
3877
                } catch (NbtParseException e) {
×
3878
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_NBT_PATH_EXPRESSION,
×
3879
                            string.getRawValue(),
×
3880
                            e.getMessage()));
×
3881
                }
1✔
3882
                if (!nbt.getRawValue().isPresent()) {
4!
3883
                    return ValueTypeNbt.ValueNbt.of();
×
3884
                }
3885
                return ValueTypeNbt.ValueNbt.of(expression.match(nbt.getRawValue().get()).getMatches().findAny());
10✔
3886
            }).build());
1✔
3887

3888
    /**
3889
     * Apply the given NBT path expression on the given NBT value and get all results.
3890
     */
3891
    public static final IOperator NBT_PATH_MATCH_ALL = REGISTRY.register(OperatorBuilders.NBT_2
14✔
3892
            .inputTypes(ValueTypes.STRING, ValueTypes.NBT).output(ValueTypes.LIST)
4✔
3893
            .operatorName("path_match_all").symbol("NBT.path_match_all").interactName("nbtPathMatchAll")
6✔
3894
            .function(variables -> {
1✔
3895
                ValueTypeString.ValueString string = variables.getValue(0, ValueTypes.STRING);
6✔
3896
                ValueTypeNbt.ValueNbt nbt = variables.getValue(1, ValueTypes.NBT);
6✔
3897
                INbtPathExpression expression = null;
2✔
3898
                try {
3899
                    expression = NbtPath.parse(string.getRawValue());
4✔
3900
                } catch (NbtParseException e) {
×
3901
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_NBT_PATH_EXPRESSION,
×
3902
                            string.getRawValue(),
×
3903
                            e.getMessage()));
×
3904
                }
1✔
3905
                if (!nbt.getRawValue().isPresent()) {
4!
3906
                    return ValueTypeList.ValueList.ofAll(ValueTypes.NBT);
×
3907
                }
3908
                List<ValueTypeNbt.ValueNbt> matches = expression.match(nbt.getRawValue().get()).getMatches()
8✔
3909
                        .map(ValueTypeNbt.ValueNbt::of)
1✔
3910
                        .collect(Collectors.toList());
4✔
3911
                return ValueTypeList.ValueList.ofList(ValueTypes.NBT, matches);
4✔
3912
            }).build());
1✔
3913

3914
    /**
3915
     * Test the given NBT path expression on the given NBT value.
3916
     */
3917
    public static final IOperator NBT_PATH_TEST = REGISTRY.register(OperatorBuilders.NBT_2
14✔
3918
            .inputTypes(ValueTypes.STRING, ValueTypes.NBT).output(ValueTypes.BOOLEAN)
4✔
3919
            .operatorName("path_test").symbol("NBT.path_test").interactName("nbtPathTest")
6✔
3920
            .function(variables -> {
1✔
3921
                ValueTypeString.ValueString string = variables.getValue(0, ValueTypes.STRING);
6✔
3922
                ValueTypeNbt.ValueNbt nbt = variables.getValue(1, ValueTypes.NBT);
6✔
3923
                INbtPathExpression expression = null;
2✔
3924
                try {
3925
                    expression = NbtPath.parse(string.getRawValue());
4✔
3926
                } catch (NbtParseException e) {
×
3927
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_NBT_PATH_EXPRESSION,
×
3928
                            string.getRawValue(),
×
3929
                            e.getMessage()));
×
3930
                }
1✔
3931
                if (!nbt.getRawValue().isPresent()) {
4!
3932
                    return ValueTypeBoolean.ValueBoolean.of(false);
×
3933
                }
3934
                return ValueTypeBoolean.ValueBoolean.of(expression.test(nbt.getRawValue().get()));
8✔
3935
            }).build());
1✔
3936

3937
    /**
3938
     * ----------------------------------- INGREDIENTS OPERATORS -----------------------------------
3939
     */
3940

3941
    /**
3942
     * The list of items.
3943
     */
3944
    public static final IOperator INGREDIENTS_ITEMS = REGISTRY.register(OperatorBuilders.INGREDIENTS_1_PREFIX_LONG
5✔
3945
            .output(ValueTypes.LIST).operatorInteract("items").symbol("Ingr.items")
6✔
3946
            .function(OperatorBuilders.createFunctionIngredientsList(() -> IngredientComponent.ITEMSTACK))
4✔
3947
            .build());
1✔
3948

3949
    /**
3950
     * The list of fluids
3951
     */
3952
    public static final IOperator INGREDIENTS_FLUIDS = REGISTRY.register(OperatorBuilders.INGREDIENTS_1_PREFIX_LONG
5✔
3953
            .output(ValueTypes.LIST).operatorInteract("fluids").symbol("Ingr.fluids")
6✔
3954
            .function(OperatorBuilders.createFunctionIngredientsList(() -> IngredientComponent.FLUIDSTACK))
4✔
3955
            .build());
1✔
3956

3957
    /**
3958
     * The list of fluids
3959
     */
3960
    public static final IOperator INGREDIENTS_ENERGIES = REGISTRY.register(OperatorBuilders.INGREDIENTS_1_PREFIX_LONG
5✔
3961
            .output(ValueTypes.LIST).operatorInteract("energies").symbol("Ingr.energies")
6✔
3962
            .function(OperatorBuilders.createFunctionIngredientsList(() -> IngredientComponent.ENERGY))
4✔
3963
            .build());
1✔
3964

3965
    /**
3966
     * Set an ingredient item
3967
     */
3968
    public static final IOperator INGREDIENTS_WITH_ITEM = REGISTRY.register(OperatorBuilders.INGREDIENTS_3_ITEMSTACK
5✔
3969
            .operatorName("with_item").symbol("Ingr.with_item").interactName("withItem")
6✔
3970
            .function(variables -> {
1✔
3971
                ValueObjectTypeIngredients.ValueIngredients value = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
6✔
3972
                ValueTypeInteger.ValueInteger index = variables.getValue(1, ValueTypes.INTEGER);
6✔
3973
                ValueObjectTypeItemStack.ValueItemStack itemStack = variables.getValue(2, ValueTypes.OBJECT_ITEMSTACK);
6✔
3974
                if (value.getRawValue().isEmpty()) {
4!
3975
                    value = ValueObjectTypeIngredients.ValueIngredients.of(new MixedIngredients(Maps.newIdentityHashMap()));
×
3976
                }
3977
                IMixedIngredients baseIngredients = value.getRawValue().get();
5✔
3978
                return ValueObjectTypeIngredients.ValueIngredients.of(new ExtendedIngredientsSingle<>(baseIngredients,
6✔
3979
                        index.getRawValue(), IngredientComponent.ITEMSTACK, itemStack.getRawValue()));
5✔
3980
            }).build());
1✔
3981

3982
    /**
3983
     * Set an ingredient fluid
3984
     */
3985
    public static final IOperator INGREDIENTS_WITH_FLUID = REGISTRY.register(OperatorBuilders.INGREDIENTS_3_FLUIDSTACK
5✔
3986
            .operatorName("with_fluid").symbol("Ingr.with_fluid").interactName("withFluid")
6✔
3987
            .function(variables -> {
1✔
3988
                ValueObjectTypeIngredients.ValueIngredients value = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
6✔
3989
                ValueTypeInteger.ValueInteger index = variables.getValue(1, ValueTypes.INTEGER);
6✔
3990
                ValueObjectTypeFluidStack.ValueFluidStack fluidStack = variables.getValue(2, ValueTypes.OBJECT_FLUIDSTACK);
6✔
3991
                if (value.getRawValue().isEmpty()) {
4!
3992
                    value = ValueObjectTypeIngredients.ValueIngredients.of(new MixedIngredients(Maps.newIdentityHashMap()));
×
3993
                }
3994
                IMixedIngredients baseIngredients = value.getRawValue().get();
5✔
3995
                return ValueObjectTypeIngredients.ValueIngredients.of(new ExtendedIngredientsSingle<>(baseIngredients,
6✔
3996
                        index.getRawValue(), IngredientComponent.FLUIDSTACK, fluidStack.getRawValue()));
5✔
3997
            }).build());
1✔
3998

3999
    /**
4000
     * Set an ingredient energy
4001
     */
4002
    public static final IOperator INGREDIENTS_WITH_ENERGY = REGISTRY.register(OperatorBuilders.INGREDIENTS_3_LONG
5✔
4003
            .operatorName("with_energy").symbol("Ingr.with_energy").interactName("withEnergy")
6✔
4004
            .function(variables -> {
1✔
4005
                ValueObjectTypeIngredients.ValueIngredients value = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
6✔
4006
                ValueTypeInteger.ValueInteger index = variables.getValue(1, ValueTypes.INTEGER);
6✔
4007
                ValueTypeLong.ValueLong energy = variables.getValue(2, ValueTypes.LONG);
6✔
4008
                if (value.getRawValue().isEmpty()) {
4!
4009
                    value = ValueObjectTypeIngredients.ValueIngredients.of(new MixedIngredients(Maps.newIdentityHashMap()));
×
4010
                }
4011
                IMixedIngredients baseIngredients = value.getRawValue().get();
5✔
4012
                return ValueObjectTypeIngredients.ValueIngredients.of(new ExtendedIngredientsSingle<>(baseIngredients,
6✔
4013
                        index.getRawValue(), IngredientComponent.ENERGY, energy.getRawValue()));
6✔
4014
            }).build());
1✔
4015

4016
    /**
4017
     * Set the list of items
4018
     */
4019
    public static final IOperator INGREDIENTS_WITH_ITEMS = REGISTRY.register(OperatorBuilders.INGREDIENTS_2_LIST
5✔
4020
            .operatorName("with_items").symbol("Ingr.with_items").interactName("withItems")
6✔
4021
            .function(variables -> {
1✔
4022
                ValueObjectTypeIngredients.ValueIngredients valueIngredients = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
6✔
4023
                ValueTypeList.ValueList<ValueObjectTypeItemStack, ValueObjectTypeItemStack.ValueItemStack> list = variables.getValue(1, ValueTypes.LIST);
6✔
4024
                if (valueIngredients.getRawValue().isEmpty()) {
4!
4025
                    valueIngredients = ValueObjectTypeIngredients.ValueIngredients.of(new MixedIngredients(Maps.newIdentityHashMap()));
×
4026
                }
4027
                IMixedIngredients baseIngredients = valueIngredients.getRawValue().get();
5✔
4028
                return ValueObjectTypeIngredients.ValueIngredients.of(new ExtendedIngredientsList<>(baseIngredients,
8✔
4029
                        IngredientComponent.ITEMSTACK, OperatorBuilders.unwrapIngredientComponentList(IngredientComponent.ITEMSTACK, list)));
2✔
4030
            }).build());
1✔
4031

4032
    /**
4033
     * Set the list of fluids
4034
     */
4035
    public static final IOperator INGREDIENTS_WITH_FLUIDS = REGISTRY.register(OperatorBuilders.INGREDIENTS_2_LIST
5✔
4036
            .operatorName("with_fluids").symbol("Ingr.with_fluids").interactName("withFluids")
6✔
4037
            .function(variables -> {
1✔
4038
                ValueObjectTypeIngredients.ValueIngredients valueIngredients = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
6✔
4039
                ValueTypeList.ValueList<ValueObjectTypeFluidStack, ValueObjectTypeFluidStack.ValueFluidStack> list = variables.getValue(1, ValueTypes.LIST);
6✔
4040
                if (valueIngredients.getRawValue().isEmpty()) {
4!
4041
                    valueIngredients = ValueObjectTypeIngredients.ValueIngredients.of(new MixedIngredients(Maps.newIdentityHashMap()));
×
4042
                }
4043
                IMixedIngredients baseIngredients = valueIngredients.getRawValue().get();
5✔
4044
                return ValueObjectTypeIngredients.ValueIngredients.of(new ExtendedIngredientsList<>(baseIngredients,
8✔
4045
                        IngredientComponent.FLUIDSTACK, OperatorBuilders.unwrapIngredientComponentList(IngredientComponent.FLUIDSTACK, list)));
2✔
4046
            }).build());
1✔
4047

4048
    /**
4049
     * Set the list of energies
4050
     */
4051
    public static final IOperator INGREDIENTS_WITH_ENERGIES = REGISTRY.register(OperatorBuilders.INGREDIENTS_2_LIST
5✔
4052
            .renderPattern(IConfigRenderPattern.INFIX_VERYLONG)
2✔
4053
            .operatorName("with_energies").symbol("Ingr.with_energies").interactName("withEnergies")
6✔
4054
            .function(variables -> {
1✔
4055
                ValueObjectTypeIngredients.ValueIngredients valueIngredients = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
6✔
4056
                ValueTypeList.ValueList<ValueTypeInteger, ValueTypeInteger.ValueInteger> list = variables.getValue(1, ValueTypes.LIST);
6✔
4057
                if (valueIngredients.getRawValue().isEmpty()) {
4!
4058
                    valueIngredients = ValueObjectTypeIngredients.ValueIngredients.of(new MixedIngredients(Maps.newIdentityHashMap()));
×
4059
                }
4060
                IMixedIngredients baseIngredients = valueIngredients.getRawValue().get();
5✔
4061
                return ValueObjectTypeIngredients.ValueIngredients.of(new ExtendedIngredientsList<>(baseIngredients,
8✔
4062
                        IngredientComponent.ENERGY, OperatorBuilders.unwrapIngredientComponentList(IngredientComponent.ENERGY, list)));
2✔
4063
            }).build());
1✔
4064

4065
    /**
4066
     * ----------------------------------- RECIPE OPERATORS -----------------------------------
4067
     */
4068

4069
    /**
4070
     * The input ingredients of a recipe
4071
     */
4072
    public static final IOperator RECIPE_INPUT = REGISTRY.register(OperatorBuilders.RECIPE_1_SUFFIX_LONG
5✔
4073
            .output(ValueTypes.OBJECT_INGREDIENTS)
2✔
4074
            .operatorInteract("input").symbol("recipe_in")
4✔
4075
            .function(variables -> {
1✔
4076
                ValueObjectTypeRecipe.ValueRecipe value = variables.getValue(0, ValueTypes.OBJECT_RECIPE);
6✔
4077
                if (value.getRawValue().isPresent()) {
4!
4078
                    return ValueObjectTypeIngredients.ValueIngredients.of(MixedIngredients.fromRecipeInput(value.getRawValue().get()));
7✔
4079
                }
4080
                return ValueObjectTypeIngredients.ValueIngredients.of(null);
×
4081
            }).build());
1✔
4082

4083
    /**
4084
     * The output ingredients of a recipe
4085
     */
4086
    public static final IOperator RECIPE_OUTPUT = REGISTRY.register(OperatorBuilders.RECIPE_1_SUFFIX_LONG
5✔
4087
            .output(ValueTypes.OBJECT_INGREDIENTS)
2✔
4088
            .operatorInteract("output").symbol("recipe_out")
4✔
4089
            .function(variables -> {
1✔
4090
                ValueObjectTypeRecipe.ValueRecipe value = variables.getValue(0, ValueTypes.OBJECT_RECIPE);
6✔
4091
                if (value.getRawValue().isPresent()) {
4!
4092
                    return ValueObjectTypeIngredients.ValueIngredients.of(value.getRawValue().get().getOutput());
7✔
4093
                }
4094
                return ValueObjectTypeIngredients.ValueIngredients.of(null);
×
4095
            }).build());
1✔
4096

4097
    /**
4098
     * Set the input ingredients of a recipe
4099
     */
4100
    public static final IOperator RECIPE_WITH_INPUT = REGISTRY.register(OperatorBuilders.RECIPE_2_INFIX
5✔
4101
            .output(ValueTypes.OBJECT_RECIPE)
2✔
4102
            .operatorName("with_input").symbol("Recipe.with_in").interactName("withInput")
6✔
4103
            .function(variables -> {
1✔
4104
                ValueObjectTypeRecipe.ValueRecipe valueRecipe = variables.getValue(0, ValueTypes.OBJECT_RECIPE);
6✔
4105
                ValueObjectTypeIngredients.ValueIngredients valueIngredients = variables.getValue(1, ValueTypes.OBJECT_INGREDIENTS);
6✔
4106
                if (valueRecipe.getRawValue().isPresent() && valueIngredients.getRawValue().isPresent()) {
8!
4107
                    IMixedIngredients ingredients = valueIngredients.getRawValue().get();
5✔
4108
                    Map<IngredientComponent<?, ?>, List<IPrototypedIngredientAlternatives<?, ?>>> inputs = Maps.newIdentityHashMap();
2✔
4109
                    for (IngredientComponent<?, ?> component : ingredients.getComponents()) {
11✔
4110
                        IIngredientMatcher matcher = component.getMatcher();
3✔
4111
                        inputs.put(component, (List) ingredients.getInstances(component)
7✔
4112
                                .stream()
4✔
4113
                                .map(instance -> new PrototypedIngredientAlternativesList(Collections.singletonList(new PrototypedIngredient(component, instance, matcher.getExactMatchCondition()))))
13✔
4114
                                .collect(Collectors.toList()));
3✔
4115
                    }
1✔
4116
                    return ValueObjectTypeRecipe.ValueRecipe.of(new RecipeDefinition(
6✔
4117
                            inputs,
4118
                            valueRecipe.getRawValue().get().getOutput()
5✔
4119
                    ));
4120
                }
4121
                return ValueObjectTypeRecipe.ValueRecipe.of(null);
×
4122
            }).build());
1✔
4123

4124
    /**
4125
     * Set the output ingredients of a recipe
4126
     */
4127
    public static final IOperator RECIPE_WITH_OUTPUT = REGISTRY.register(OperatorBuilders.RECIPE_2_INFIX
5✔
4128
            .output(ValueTypes.OBJECT_RECIPE)
2✔
4129
            .operatorName("with_output").symbol("Recipe.with_out").interactName("withOutput")
6✔
4130
            .function(variables -> {
1✔
4131
                ValueObjectTypeRecipe.ValueRecipe valueRecipe = variables.getValue(0, ValueTypes.OBJECT_RECIPE);
6✔
4132
                ValueObjectTypeIngredients.ValueIngredients valueIngredients = variables.getValue(1, ValueTypes.OBJECT_INGREDIENTS);
6✔
4133
                if (valueRecipe.getRawValue().isPresent() && valueIngredients.getRawValue().isPresent()) {
8!
4134
                    IRecipeDefinition recipe = valueRecipe.getRawValue().get();
5✔
4135
                    Map<IngredientComponent<?, ?>, List<IPrototypedIngredientAlternatives<?, ?>>> inputs = Maps.newIdentityHashMap();
2✔
4136
                    for (IngredientComponent<?, ?> component : recipe.getInputComponents()) {
11✔
4137
                        inputs.put(component, (List) recipe.getInputs(component));
7✔
4138
                    }
1✔
4139
                    return ValueObjectTypeRecipe.ValueRecipe.of(new RecipeDefinition(
6✔
4140
                            inputs,
4141
                            valueIngredients.getRawValue().get()
4✔
4142
                    ));
4143
                }
4144
                return ValueObjectTypeRecipe.ValueRecipe.of(null);
×
4145
            }).build());
1✔
4146

4147
    /**
4148
     * Create a recipe from two the given I/O ingredients
4149
     */
4150
    public static final IOperator RECIPE_WITH_INPUT_OUTPUT = REGISTRY.register(OperatorBuilders.RECIPE_2_PREFIX
5✔
4151
            .output(ValueTypes.OBJECT_RECIPE)
2✔
4152
            .operatorName("with_input_output").symbol("Recipe.with_io").interactName("withInputOutput")
6✔
4153
            .function(variables -> {
1✔
4154
                ValueObjectTypeIngredients.ValueIngredients valueIn = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
6✔
4155
                ValueObjectTypeIngredients.ValueIngredients valueOut = variables.getValue(1, ValueTypes.OBJECT_INGREDIENTS);
6✔
4156
                if (valueIn.getRawValue().isPresent() && valueOut.getRawValue().isPresent()) {
8!
4157
                    IMixedIngredients ingredients = valueIn.getRawValue().get();
5✔
4158
                    Map<IngredientComponent<?, ?>, List<IPrototypedIngredientAlternatives<?, ?>>> inputs = Maps.newIdentityHashMap();
2✔
4159
                    for (IngredientComponent<?, ?> component : ingredients.getComponents()) {
11✔
4160
                        IIngredientMatcher matcher = component.getMatcher();
3✔
4161
                        inputs.put(component, (List) ingredients.getInstances(component)
7✔
4162
                                .stream()
4✔
4163
                                .map(instance -> new PrototypedIngredientAlternativesList(Collections.singletonList(new PrototypedIngredient(component, instance, matcher.getExactMatchCondition()))))
13✔
4164
                                .collect(Collectors.toList()));
3✔
4165
                    }
1✔
4166
                    try {
4167
                        return ValueObjectTypeRecipe.ValueRecipe.of(new RecipeDefinition(
6✔
4168
                                inputs,
4169
                                valueOut.getRawValue().get()
4✔
4170
                        ));
4171
                    } catch (IllegalArgumentException e) {
×
4172
                        throw new EvaluationException(Component.literal(e.getMessage()));
×
4173
                    }
4174
                }
4175
                return ValueObjectTypeRecipe.ValueRecipe.of(null);
×
4176
            }).build());
1✔
4177

4178
    /**
4179
     * ------------------------------------ PARSE OPERATORS ------------------------------------
4180
     */
4181

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

4191
    /**
4192
     * Double Parse operator which takes a string of a form Double.parseDouble(),
4193
     * `/([+-]?)(Inf(inity)?|\u221E)/i`, or Long.decode() can consume.
4194
     */
4195
    public static final IOperator PARSE_DOUBLE = Operators.REGISTRY.register(new ParseOperator<>(ValueTypes.DOUBLE, v -> {
8✔
4196
      ValueTypeString.ValueString value = v.getValue(0, ValueTypes.STRING);
6✔
4197
      try {
4198
        return ValueTypeDouble.ValueDouble.of(Double.parseDouble(value.getRawValue()));
5✔
4199
      } catch (NumberFormatException e) {
1✔
4200
        try {
4201
          // \u221E = infinity symbol
4202
          Pattern p = Pattern.compile("\\A([+-]?)(Inf(inity)?|\u221E)\\z", Pattern.CASE_INSENSITIVE);
4✔
4203
          Matcher m = p.matcher(value.getRawValue().trim());
6✔
4204
          if (m.matches()){
3✔
4205
            if (m.group(1).equals("-")){
6✔
4206
              return ValueTypeDouble.ValueDouble.of(Double.NEGATIVE_INFINITY);
3✔
4207
            }
4208
            return ValueTypeDouble.ValueDouble.of(Double.POSITIVE_INFINITY);
3✔
4209
          }
4210
          // Try as a long
4211
          return ValueTypeDouble.ValueDouble.of((double) Long.decode(value.getRawValue()));
7✔
4212
        } catch (NumberFormatException e2) {
1✔
4213
            throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_PARSE, value.getRawValue(),
16✔
4214
                    Component.translatable(ValueTypes.DOUBLE.getTranslationKey())));
3✔
4215
        }
4216
      }
4217
    }));
4218

4219
    /**
4220
     * Integer Parse operator which takes a string of a form Integer.decode() can consume.
4221
     */
4222
    public static final IOperator PARSE_INTEGER = Operators.REGISTRY.register(new ParseOperator<>(ValueTypes.INTEGER, v -> {
8✔
4223
      ValueTypeString.ValueString value = v.getValue(0, ValueTypes.STRING);
6✔
4224
      try{
4225
        return ValueTypeInteger.ValueInteger.of(Integer.decode(value.getRawValue()));
6✔
4226
      } catch (NumberFormatException e) {
1✔
4227
          throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_PARSE, value.getRawValue(),
16✔
4228
                  Component.translatable(ValueTypes.INTEGER.getTranslationKey())));
3✔
4229
      }
4230
    }));
4231

4232
    /**
4233
     * Long Parse operator which takes a string of a form Long.decode() can consume.
4234
     */
4235
    public static final IOperator PARSE_LONG = Operators.REGISTRY.register(new ParseOperator<>(ValueTypes.LONG, v -> {
8✔
4236
      ValueTypeString.ValueString value = v.getValue(0, ValueTypes.STRING);
6✔
4237
      try {
4238
        return ValueTypeLong.ValueLong.of(Long.decode(value.getRawValue()));
6✔
4239
      } catch (NumberFormatException e) {
1✔
4240
          throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_PARSE, value.getRawValue(),
16✔
4241
                  Component.translatable(ValueTypes.LONG.getTranslationKey())));
3✔
4242
      }
4243
    }));
4244

4245
    /**
4246
     * NBT Parse operator which takes a string of a form ValueTypeNbt().deserialize() can consume.
4247
     */
4248
    public static final IOperator PARSE_NBT = Operators.REGISTRY.register(new ParseOperator<>(ValueTypes.NBT, v -> {
8✔
4249
      ValueTypeString.ValueString value = v.getValue(0, ValueTypes.STRING);
6✔
4250
      try {
4251
        return ValueTypeNbt.ValueNbt.of(TagParser.parseTag(value.getRawValue()));
5✔
4252
      } catch (CommandSyntaxException e) {
1✔
4253
        throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_PARSE, value.getRawValue(),
16✔
4254
                Component.translatable(ValueTypes.NBT.getTranslationKey())));
3✔
4255
      }
4256
    }));
4257

4258
    /**
4259
     * ----------------------------------- GENERAL OPERATORS -----------------------------------
4260
     */
4261

4262
    /**
4263
     * Choice operator with one boolean input, two any inputs and one output any.
4264
     */
4265
    public static final GeneralOperator GENERAL_CHOICE = REGISTRY.register(new GeneralChoiceOperator("?", "choice", "choice"));
10✔
4266

4267
    /**
4268
     * Identity operator with one any input and one any output
4269
     */
4270
    public static final GeneralOperator GENERAL_IDENTITY = REGISTRY.register(new GeneralIdentityOperator("id", "identity", "identity"));
10✔
4271

4272
    /**
4273
     * Constant operator with two any inputs and one any output
4274
     */
4275
    public static final GeneralOperator GENERAL_CONSTANT = REGISTRY.register(new GeneralConstantOperator("K", "constant", "constant"));
11✔
4276

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