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

CyclopsMC / IntegratedDynamics / 20210191346

14 Dec 2025 03:32PM UTC coverage: 19.514% (-33.5%) from 53.061%
20210191346

push

github

rubensworks
Remove deprecations

663 of 8728 branches covered (7.6%)

Branch coverage included in aggregate %.

6786 of 29445 relevant lines covered (23.05%)

1.09 hits per line

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

599

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1215
                    return ValueTypeList.ValueList.ofList(rawList1.getValueType(), result.stream().toList());
7✔
1216
                }
1217
            }).build());
1✔
1218

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

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

1265
    /**
1266
     * ----------------------------------- BLOCK OBJECT OPERATORS -----------------------------------
1267
     */
1268

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

1278
    /**
1279
     * The itemstack representation of the block
1280
     */
1281
    public static final IOperator OBJECT_BLOCK_ITEMSTACK = REGISTRY.register(OperatorBuilders.BLOCK_1_SUFFIX_LONG.output(ValueTypes.OBJECT_ITEMSTACK).symbolOperator("itemstack").interactName("itemStack")
11✔
1282
            .function(variables -> {
1✔
1283
                ValueObjectTypeBlock.ValueBlock a = variables.getValue(0, ValueTypes.OBJECT_BLOCK);
×
1284
                return ValueObjectTypeItemStack.ValueItemStack.of(a.getRawValue().isPresent() ? IModHelpers.get().getBlockHelpers().getItemStackFromBlockState(a.getRawValue().get()) : ItemStack.EMPTY);
×
1285
            }).build());
1✔
1286

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

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

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

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

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

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

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

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

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

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

1478
    /**
1479
     * ----------------------------------- ITEM STACK OBJECT OPERATORS -----------------------------------
1480
     */
1481

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

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

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

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

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

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

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

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

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

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

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

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

1598
    /**
1599
     * The block from the stack
1600
     */
1601
    public static final IOperator OBJECT_ITEMSTACK_BLOCK = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1602
            .output(ValueTypes.OBJECT_BLOCK).symbolOperatorInteract("block")
4✔
1603
            .function(variables -> {
1✔
1604
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
×
1605
                return ValueObjectTypeBlock.ValueBlock.of((!a.getRawValue().isEmpty() && a.getRawValue().getItem() instanceof BlockItem) ? IModHelpers.get().getBlockHelpers().getBlockStateFromItemStack(a.getRawValue()) : null);
×
1606
            }).build());
1✔
1607

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

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

1628
    /**
1629
     * The capacity of the fluidstack from the stack.
1630
     */
1631
    public static final IOperator OBJECT_ITEMSTACK_FLUIDSTACKCAPACITY = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1632
            .output(ValueTypes.LONG)
2✔
1633
            .symbol("fluidstack_capacity").operatorName("fluidstackcapacity").interactName("fluidCapacity")
7✔
1634
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_LONG.build(
2✔
1635
                itemStack -> !itemStack.isEmpty() ? Helpers.getFluidStackCapacity(itemStack) : 0
×
1636
            )).build());
1✔
1637

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

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

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

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

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

1724
    /**
1725
     * If the given item can be used as fuel
1726
     */
1727
    public static final IOperator OBJECT_ITEMSTACK_CANBURN = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1728
            .output(ValueTypes.BOOLEAN)
2✔
1729
            .symbol("can_burn").operatorName("canburn").interactName("canBurn")
7✔
1730
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_BOOLEAN
1✔
1731
                    .build(stack -> stack.getBurnTime(null, ServerLifecycleHooks.getCurrentServer().fuelValues()) > 0))
1!
1732
            .build());
1✔
1733

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

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

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

1790
    /**
1791
     * Check if the item is an energy container item
1792
     */
1793
    public static final IOperator OBJECT_ITEMSTACK_ISENERGYCONTAINER = Operators.REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1794
            .output(ValueTypes.BOOLEAN)
2✔
1795
            .symbol("is_energy_container").operatorName("isenergycontainer").interactName("isEnergyContainer")
7✔
1796
            .function(OperatorBuilders.FUNCTION_CONTAINERITEM_TO_BOOLEAN.build(
2✔
1797
                Objects::nonNull
1798
            )).build());
1✔
1799

1800
    /**
1801
     * Get the storage energy
1802
     */
1803
    public static final IOperator OBJECT_ITEMSTACK_STOREDENERGY = Operators.REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1804
            .output(ValueTypes.LONG)
2✔
1805
            .symbol("stored_energy").operatorName("storedenergy").interactName("energyStored")
7✔
1806
            .function(OperatorBuilders.FUNCTION_CONTAINERITEM_TO_LONG.build(
2✔
1807
                input -> input != null ? input.getAmountAsLong() : 0
×
1808
            )).build());
1✔
1809

1810
    /**
1811
     * Get the energy capacity
1812
     */
1813
    public static final IOperator OBJECT_ITEMSTACK_ENERGYCAPACITY = Operators.REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1814
            .output(ValueTypes.LONG)
2✔
1815
            .symbol("capacity_energy").operatorName("energycapacity").interactName("energyCapacity")
7✔
1816
            .function(OperatorBuilders.FUNCTION_CONTAINERITEM_TO_LONG.build(
2✔
1817
                input -> input != null ? input.getCapacityAsLong() : 0
×
1818
            )).build());
1✔
1819

1820

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

1832

1833

1834

1835
    /**
1836
     * Retrieve the inventory size of the given item handler contents.
1837
     */
1838
    public static final IOperator OBJECT_ITEMSTACK_INVENTORYSIZE = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1839
            .output(ValueTypes.INTEGER)
2✔
1840
            .symbol("inventory_size").operatorName("inventorysize").interactName("inventorySize")
6✔
1841
            .function(variables -> {
1✔
1842
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
×
1843
                ResourceHandler<ItemResource> itemHandler = ItemAccess.forStack(a.getRawValue()).getCapability(Capabilities.Item.ITEM);
×
1844
                return ValueTypeInteger.ValueInteger.of(itemHandler != null ? itemHandler.size() : 0);
×
1845
            }).build());
1✔
1846

1847
    /**
1848
     * Retrieve the inventory of the given item handler contents.
1849
     */
1850
    public static final IOperator OBJECT_ITEMSTACK_INVENTORY = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1851
            .output(ValueTypes.LIST).symbolOperator("inventory").interactName("inventory")
6✔
1852
            .function(variables -> {
1✔
1853
                ValueObjectTypeItemStack.ValueItemStack a = variables.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
×
1854
                ResourceHandler<ItemResource> itemHandler = ItemAccess.forStack(a.getRawValue()).getCapability(Capabilities.Item.ITEM);
×
1855
                if (itemHandler != null) {
×
1856
                    List<ValueObjectTypeItemStack.ValueItemStack> values = Lists.newArrayListWithCapacity(itemHandler.size());
×
1857
                    for (int i = 0; i < itemHandler.size(); i++) {
×
1858
                        values.add(ValueObjectTypeItemStack.ValueItemStack.of(itemHandler.getResource(i).toStack(itemHandler.getAmountAsInt(i))));
×
1859
                    }
1860
                    return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_ITEMSTACK, values);
×
1861
                }
1862
                return ValueTypes.LIST.getDefault();
×
1863
            }).build());
1✔
1864

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

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

1899
                ItemStack itemStack = b.getRawValue();
×
1900
                int count = 0;
×
1901
                for (IValue listValueRaw : a.getRawValue()) {
×
1902
                    if (listValueRaw.getType().correspondsTo(ValueTypes.OBJECT_ITEMSTACK)) {
×
1903
                        ValueObjectTypeItemStack.ValueItemStack listValue = (ValueObjectTypeItemStack.ValueItemStack) listValueRaw;
×
1904
                        if (!listValue.getRawValue().isEmpty()) {
×
1905
                            ItemStack listItem = listValue.getRawValue();
×
1906
                            if (!itemStack.isEmpty()) {
×
1907
                                if (ItemStack.isSameItemSameComponents(itemStack, listItem)) {
×
1908
                                    count += listItem.getCount();
×
1909
                                }
1910
                            } else {
1911
                                count += listItem.getCount();
×
1912
                            }
1913
                        }
1914
                    }
1915
                }
×
1916

1917
                return ValueTypeInteger.ValueInteger.of(count);
×
1918
            }).build());
1✔
1919

1920
    /**
1921
     * Item Stack size operator with one input itemstack and one output NBT tag.
1922
     */
1923
    public static final IOperator OBJECT_ITEMSTACK_DATA = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1924
            .output(ValueTypes.NBT).symbol("NBT()").operatorName("nbt").interactName("nbt")
8✔
1925
            .function(input -> {
1✔
1926
                ValueObjectTypeItemStack.ValueItemStack itemStack = input.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
×
1927
                // Explicitly check for item emptiness first, because vanilla sometimes persists NBT when setting stacks to empty
1928
                if (itemStack.getRawValue().isEmpty() || itemStack.getRawValue().getComponents().isEmpty()) {
×
1929
                    return ValueTypeNbt.ValueNbt.of();
×
1930
                }
1931
                CompoundTag tag = (CompoundTag) DataComponentPatch.CODEC.encodeStart(ServerLifecycleHooks.getCurrentServer().registryAccess().createSerializationContext(NbtOps.INSTANCE), itemStack.getRawValue().getComponentsPatch()).getOrThrow();
×
1932
                // Remove entries that have been marked as removed.
1933
                for (String key : Sets.newHashSet(tag.keySet())) {
×
1934
                    if (key.startsWith("!")) {
×
1935
                        tag.remove(key);
×
1936
                    }
1937
                }
×
1938
                if (tag.isEmpty()) {
×
1939
                    return ValueTypeNbt.ValueNbt.of();
×
1940
                }
1941
                return ValueTypeNbt.ValueNbt.of(Optional.of(tag));
×
1942
            }).build());
1✔
1943

1944
    /**
1945
     * Item Stack has_nbt operator with one input itemstack and one output boolean.
1946
     */
1947
    public static final IOperator OBJECT_ITEMSTACK_HASDATA = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_PREFIX_LONG
5✔
1948
            .output(ValueTypes.BOOLEAN).symbol("has_nbt").operatorName("hasnbt").interactName("hasNbt")
9✔
1949
            .function(OperatorBuilders.FUNCTION_ITEMSTACK_TO_BOOLEAN.build(
2✔
1950
                    itemStack -> !itemStack.isEmpty() && itemStack.getComponents().stream().anyMatch(t -> !t.type().isTransient())
×
1951
            )).build());
1✔
1952

1953
    /**
1954
     * Get the data component keys of an itemstack.
1955
     */
1956
    public static final IOperator OBJECT_ITEMSTACK_DATA_KEYS = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
1957
            .output(ValueTypes.LIST).symbol("data_keys").operatorName("datakeys").interactName("dataKeys")
8✔
1958
            .function(input -> {
1✔
1959
                ValueObjectTypeItemStack.ValueItemStack itemStack = input.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
×
1960
                // Explicitly check for item emptiness first, because vanilla sometimes persists NBT when setting stacks to empty
1961
                return ValueTypeList.ValueList.ofList(ValueTypes.STRING,
×
1962
                        itemStack.getRawValue().isEmpty() ?
×
1963
                                Lists.newArrayList() :
×
1964
                                itemStack.getRawValue().getComponents().keySet().stream()
×
1965
                                        .filter(c -> !c.isTransient())
×
1966
                                        .map(c -> ValueTypeString.ValueString.of(BuiltInRegistries.DATA_COMPONENT_TYPE.getKey(c).toString()))
×
1967
                                        .sorted(Comparator.comparing(ValueTypeString.ValueString::getRawValue))
×
1968
                                        .toList());
×
1969
            }).build());
1✔
1970

1971
    /**
1972
     * Get the data component value by key
1973
     */
1974
    public static final IOperator OBJECT_ITEMSTACK_DATA_VALUE = REGISTRY.register(OperatorBuilders.ITEMSTACK_2_LONG
14✔
1975
            .inputTypes(ValueTypes.OBJECT_ITEMSTACK, ValueTypes.STRING)
2✔
1976
            .output(ValueTypes.NBT).symbol("data_value").operatorName("datavalue").interactName("dataValue")
8✔
1977
            .function(input -> {
1✔
1978
                ValueObjectTypeItemStack.ValueItemStack itemStack = input.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
×
1979

1980
                // Determine data component type
1981
                DataComponentType<?> dataComponentType;
1982
                try {
1983
                    dataComponentType = BuiltInRegistries.DATA_COMPONENT_TYPE.getValue(ResourceLocation.parse(input.getValue(1, ValueTypes.STRING).getRawValue()));
×
1984
                } catch (ResourceLocationException e) {
×
1985
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
1986
                }
×
1987

1988
                // Fetch component value
1989
                TypedDataComponent<?> typedComponent = itemStack.getRawValue().getComponents().getTyped(dataComponentType);
×
1990
                if (typedComponent == null) {
×
1991
                    return ValueTypeNbt.ValueNbt.of((Tag) null);
×
1992
                }
1993

1994
                // Encode component value
1995
                try {
1996
                    Tag tag = typedComponent.encodeValue(ServerLifecycleHooks.getCurrentServer().registryAccess().createSerializationContext(NbtOps.INSTANCE)).getOrThrow();
×
1997
                    return ValueTypeNbt.ValueNbt.of(tag);
×
1998
                } catch (IllegalStateException e) {
×
1999
                    return ValueTypeNbt.ValueNbt.of((Tag) null);
×
2000
                }
2001
            }).build());
1✔
2002

2003
    /**
2004
     * Get the data component value by key
2005
     */
2006
    public static final IOperator OBJECT_ITEMSTACK_WITH_DATA = REGISTRY.register(OperatorBuilders.ITEMSTACK_3
18✔
2007
            .inputTypes(ValueTypes.OBJECT_ITEMSTACK, ValueTypes.STRING, ValueTypes.NBT)
2✔
2008
            .output(ValueTypes.NBT).symbol("with_data").operatorName("withdata").interactName("withData")
8✔
2009
            .function(input -> {
1✔
2010
                ValueObjectTypeItemStack.ValueItemStack itemStack = input.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
×
2011

2012
                // Skip further processing if input value is empty
2013
                Optional<Tag> tagOptional = input.getValue(2, ValueTypes.NBT).getRawValue();
×
2014
                if (!tagOptional.isPresent()) {
×
2015
                    return itemStack;
×
2016
                }
2017

2018
                // Determine data component type
2019
                DataComponentType<?> dataComponentType;
2020
                try {
2021
                    dataComponentType = BuiltInRegistries.DATA_COMPONENT_TYPE.getValue(ResourceLocation.parse(input.getValue(1, ValueTypes.STRING).getRawValue()));
×
2022
                } catch (ResourceLocationException e) {
×
2023
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
2024
                }
×
2025

2026
                // Encode component value
2027
                try {
2028
                    Object value = dataComponentType.codec().decode(ServerLifecycleHooks.getCurrentServer().registryAccess().createSerializationContext(NbtOps.INSTANCE), tagOptional.get()).getOrThrow().getFirst();
×
2029
                    itemStack = ValueObjectTypeItemStack.ValueItemStack.of(itemStack.getRawValue().copy());
×
2030
                    itemStack.getRawValue().set((DataComponentType) dataComponentType, value);
×
2031
                    return itemStack;
×
2032
                } catch (IllegalStateException e) {
×
2033
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
2034
                }
2035
            }).build());
1✔
2036

2037
    /**
2038
     * Get the tooltip of an itemstack in list form.
2039
     */
2040
    public static final IOperator OBJECT_ITEMSTACK_TOOLTIP = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
5✔
2041
            .output(ValueTypes.LIST).symbol("tooltip").operatorName("tooltip").interactName("tooltip")
8✔
2042
            .function(input -> {
1✔
2043
                ValueObjectTypeItemStack.ValueItemStack itemStack = input.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
×
2044
                return ValueTypeList.ValueList.ofList(ValueTypes.STRING,
×
2045
                        itemStack.getRawValue().getTooltipLines(Item.TooltipContext.EMPTY, null, TooltipFlag.Default.NORMAL).stream()
×
2046
                                .map(c -> ValueTypeString.ValueString.of(c.getString()))
×
2047
                                .toList());
×
2048
            }).build());
1✔
2049
    /**
2050
     * Get the tooltip of an itemstack in list form, using the provided player entity as the player context.
2051
     */
2052
    public static final IOperator OBJECT_ITEMSTACK_ENTITY_TOOLTIP = REGISTRY.register(OperatorBuilders.ENTITY_1_ITEMSTACK_1
14✔
2053
            .inputTypes(ValueTypes.OBJECT_ENTITY, ValueTypes.OBJECT_ITEMSTACK)
2✔
2054
            .output(ValueTypes.LIST).symbol("entity_item_tooltip").operatorName("entityitemtooltip").interactName("entityItemTooltip")
8✔
2055
            .function(variables -> {
1✔
2056
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2057
                ValueObjectTypeItemStack.ValueItemStack itemStack = variables.getValue(1, ValueTypes.OBJECT_ITEMSTACK);
×
2058
                if(a.getRawValue().isPresent() && a.getRawValue().get() instanceof Player) {
×
2059
                    Player entity = (Player) a.getRawValue().get();
×
2060
                    return ValueTypeList.ValueList.ofList(ValueTypes.STRING,
×
2061
                            itemStack.getRawValue().getTooltipLines(Item.TooltipContext.of(entity.level()), entity, TooltipFlag.Default.NORMAL).stream()
×
2062
                                    .map(c -> ValueTypeString.ValueString.of(c.getString()))
×
2063
                                    .toList());
×
2064
                }
2065
                return ValueTypes.LIST.getDefault();
×
2066
            }).build());
1✔
2067

2068
    /**
2069
     * ----------------------------------- ENTITY OBJECT OPERATORS -----------------------------------
2070
     */
2071

2072
    /**
2073
     * If the entity is a mob
2074
     */
2075
    public static final IOperator OBJECT_ENTITY_ISMOB = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2076
            .output(ValueTypes.BOOLEAN).symbol("is_mob").operatorName("ismob").interactName("isMob")
9✔
2077
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2078
                entity -> entity instanceof Enemy
×
2079
            )).build());
1✔
2080

2081
    /**
2082
     * If the entity is an animal
2083
     */
2084
    public static final IOperator OBJECT_ENTITY_ISANIMAL = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2085
            .output(ValueTypes.BOOLEAN).symbol("is_animal").operatorName("isanimal").interactName("isAnimal")
9✔
2086
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2087
                entity -> entity instanceof Animal && !(entity instanceof Enemy)
×
2088
            )).build());
1✔
2089

2090
    /**
2091
     * If the entity is an item
2092
     */
2093
    public static final IOperator OBJECT_ENTITY_ISITEM = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2094
            .output(ValueTypes.BOOLEAN).symbol("is_item").operatorName("isitem").interactName("isItem")
9✔
2095
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2096
                entity -> entity instanceof ItemEntity
×
2097
            )).build());
1✔
2098

2099
    /**
2100
     * If the entity is a player
2101
     */
2102
    public static final IOperator OBJECT_ENTITY_ISPLAYER = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2103
            .output(ValueTypes.BOOLEAN).symbol("is_player").operatorName("isplayer").interactName("isPlayer")
9✔
2104
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2105
                entity -> entity instanceof Player
×
2106
            )).build());
1✔
2107

2108
    /**
2109
     * If the entity is a minecart
2110
     */
2111
    public static final IOperator OBJECT_ENTITY_ISMINECART = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2112
            .output(ValueTypes.BOOLEAN).symbol("is_minecart").operatorName("isminecart").interactName("isMinecart")
9✔
2113
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2114
                entity -> entity instanceof AbstractMinecart
×
2115
            )).build());
1✔
2116

2117
    /**
2118
     * The itemstack from the entity
2119
     */
2120
    public static final IOperator OBJECT_ENTITY_ITEMSTACK = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX
5✔
2121
            .output(ValueTypes.OBJECT_ITEMSTACK).symbolOperatorInteract("item")
4✔
2122
            .function(variables -> {
1✔
2123
                ValueObjectTypeEntity.ValueEntity valueEntity = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2124
                Optional<Entity> a = valueEntity.getRawValue();
×
2125
                return ValueObjectTypeItemStack.ValueItemStack.of((a.isPresent() && a.get() instanceof ItemEntity) ? ((ItemEntity) a.get()).getItem() : ItemStack.EMPTY);
×
2126
            }).build());
1✔
2127

2128
    /**
2129
     * The entity health
2130
     */
2131
    public static final IOperator OBJECT_ENTITY_HEALTH = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2132
            .output(ValueTypes.DOUBLE).symbolOperatorInteract("health")
5✔
2133
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_DOUBLE.build(
2✔
2134
                entity -> entity instanceof LivingEntity ? ((LivingEntity) entity).getHealth() : 0.0
×
2135
            )).build());
1✔
2136

2137
    /**
2138
     * The entity width
2139
     */
2140
    public static final IOperator OBJECT_ENTITY_WIDTH = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2141
            .output(ValueTypes.DOUBLE).symbolOperatorInteract("width")
5✔
2142
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_DOUBLE.build(
2✔
2143
                entity -> entity != null ? entity.getBbWidth() : 0.0
×
2144
            )).build());
1✔
2145

2146
    /**
2147
     * The entity width
2148
     */
2149
    public static final IOperator OBJECT_ENTITY_HEIGHT = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2150
            .output(ValueTypes.DOUBLE).symbolOperatorInteract("height")
5✔
2151
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_DOUBLE.build(
2✔
2152
                entity -> entity != null ? entity.getBbHeight() : 0.0
×
2153
            )).build());
1✔
2154

2155
    /**
2156
     * If the entity is burning
2157
     */
2158
    public static final IOperator OBJECT_ENTITY_ISBURNING = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2159
            .output(ValueTypes.BOOLEAN).symbol("is_burning").operatorName("isburning").interactName("entityIsBurning")
9✔
2160
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2161
                entity -> entity != null && entity.isOnFire()
×
2162
            )).build());
1✔
2163

2164
    /**
2165
     * If the entity is wet
2166
     */
2167
    public static final IOperator OBJECT_ENTITY_ISWET = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2168
            .output(ValueTypes.BOOLEAN).symbol("is_wet").operatorName("iswet").interactName("isWet")
9✔
2169
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2170
                entity -> entity != null && entity.isInWaterOrRain()
×
2171
            )).build());
1✔
2172

2173
    /**
2174
     * If the entity is crouching
2175
     */
2176
    public static final IOperator OBJECT_ENTITY_ISCROUCHING = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2177
            .output(ValueTypes.BOOLEAN).symbol("is_crouching").operatorName("iscrouching").interactName("isCrouching")
9✔
2178
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2179
                entity -> entity != null && entity.isCrouching()
×
2180
            )).build());
1✔
2181

2182
    /**
2183
     * If the entity is eating
2184
     */
2185
    public static final IOperator OBJECT_ENTITY_ISEATING = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2186
            .output(ValueTypes.BOOLEAN).symbol("is_eating").operatorName("iseating").interactName("isEating")
9✔
2187
            .function(OperatorBuilders.FUNCTION_ENTITY_TO_BOOLEAN.build(
2✔
2188
                entity -> entity instanceof LivingEntity && ((LivingEntity) entity).getUseItemRemainingTicks() > 0
×
2189
            )).build());
1✔
2190

2191
    /**
2192
     * The list of armor itemstacks from an entity
2193
     */
2194
    public static final IOperator OBJECT_ENTITY_ARMORINVENTORY = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2195
            .output(ValueTypes.LIST).symbol("armor_inventory").operatorName("armorinventory").interactName("armorInventory")
8✔
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 ValueTypeListProxyEntityArmorInventory(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 list of itemstacks from an entity
2209
     */
2210
    public static final IOperator OBJECT_ENTITY_INVENTORY = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2211
            .output(ValueTypes.LIST).symbolOperator("inventory").interactName("inventory")
6✔
2212
            .function(variables -> {
1✔
2213
                ValueObjectTypeEntity.ValueEntity valueEntity = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2214
                Optional<Entity> a = valueEntity.getRawValue();
×
2215
                if(a.isPresent()) {
×
2216
                    Entity entity = a.get();
×
2217
                    return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyEntityInventory(entity.level(), entity));
×
2218
                } else {
2219
                    return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_ITEMSTACK, Collections.<ValueObjectTypeItemStack.ValueItemStack>emptyList());
×
2220
                }
2221
            }).build());
1✔
2222

2223
    /**
2224
     * The name of the mod owning this entity
2225
     */
2226
    public static final IOperator OBJECT_ENTITY_MODNAME = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.STRING)
7✔
2227
            .symbolOperatorInteract("mod")
13✔
2228
            .function(new IterativeFunction(Lists.newArrayList(
3✔
2229
                    (OperatorBase.SafeVariablesGetter variables) -> {
2230
                        ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2231
                        if(a.getRawValue().isPresent()) {
×
2232
                            Entity entity = a.getRawValue().get();
×
2233
                            return BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType());
×
2234
                        }
2235
                        return ResourceLocation.parse("");
×
2236
                    },
2237
                    OperatorBuilders.PROPAGATOR_RESOURCELOCATION_MODNAME
2238
            )))
2239
            .build());
1✔
2240

2241
    /**
2242
     * The block the given player is currently looking at.
2243
     */
2244
    public static final IOperator OBJECT_PLAYER_TARGETBLOCK = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.OBJECT_BLOCK)
7✔
2245
            .symbol("target_block").operatorName("targetblock").interactName("targetBlock")
6✔
2246
            .function(variables -> {
1✔
2247
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2248
                BlockState blockState = null;
×
2249
                if(a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
×
2250
                    LivingEntity entity = (LivingEntity) a.getRawValue().get();
×
2251
                    AttributeInstance reachDistanceAttribute = entity.getAttribute(Attributes.BLOCK_INTERACTION_RANGE);
×
2252
                    double reachDistance = reachDistanceAttribute == null ? 5 : reachDistanceAttribute.getValue();
×
2253
                    double eyeHeight = entity.getEyeHeight();
×
2254
                    Vec3 lookVec = entity.getLookAngle();
×
2255
                    Vec3 origin = new Vec3(entity.getX(), entity.getY() + eyeHeight, entity.getZ());
×
2256
                    Vec3 direction = origin.add(lookVec.x * reachDistance, lookVec.y * reachDistance, lookVec.z * reachDistance);
×
2257

2258
                    ClipContext rayTraceContext = new ClipContext(origin, direction, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity);
×
2259
                    BlockHitResult mop = entity.level().clip(rayTraceContext);
×
2260
                    if(mop != null && mop.getType() == HitResult.Type.BLOCK) {
×
2261
                        blockState = entity.level().getBlockState(mop.getBlockPos());
×
2262
                    }
2263
                }
2264
                return ValueObjectTypeBlock.ValueBlock.of(blockState);
×
2265
            }).build());
1✔
2266

2267
    /**
2268
     * The entity the given player is currently looking at.
2269
     */
2270
    public static final IOperator OBJECT_PLAYER_TARGETENTITY = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.OBJECT_ENTITY)
7✔
2271
            .symbol("target_entity").operatorName("targetentity").interactName("targetEntity")
6✔
2272
            .function(variables -> {
1✔
2273
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2274
                Entity entityOut = null;
×
2275
                if(a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
×
2276
                    LivingEntity entity = (LivingEntity) a.getRawValue().get();
×
2277
                    AttributeInstance reachDistanceAttribute = entity.getAttribute(Attributes.ENTITY_INTERACTION_RANGE);
×
2278
                    double reachDistance = reachDistanceAttribute == null ? 5 : reachDistanceAttribute.getValue();
×
2279

2280
                    // Copied and modified from GameRenderer#getMouseOver
2281
                    Vec3 origin = entity.getEyePosition(1.0F);
×
2282
                    double reachDistanceSquared = reachDistance * reachDistance;
×
2283

2284
                    Vec3 lookVec = entity.getViewVector(1.0F);
×
2285
                    Vec3 direction = origin.add(lookVec.x * reachDistance, lookVec.y * reachDistance, lookVec.z * reachDistance);
×
2286
                    AABB boundingBox = entity.getBoundingBox()
×
2287
                            .expandTowards(lookVec.scale(reachDistance))
×
2288
                            .inflate(1.0D, 1.0D, 1.0D);
×
2289
                    EntityHitResult entityraytraceresult = ProjectileUtil.getEntityHitResult(entity, origin, direction,
×
2290
                            boundingBox, e -> !e.isSpectator() && e.isPickable(), reachDistanceSquared);
×
2291
                    if (entityraytraceresult != null) {
×
2292
                        Entity entity1 = entityraytraceresult.getEntity();
×
2293
                        Vec3 vec3d3 = entityraytraceresult.getLocation();
×
2294
                        double distanceSquared = origin.distanceToSqr(vec3d3);
×
2295
                        if (distanceSquared < reachDistanceSquared
×
2296
                                && (entity1 instanceof LivingEntity || entity1 instanceof ItemFrame)) {
2297
                            entityOut = entity1;
×
2298
                        }
2299
                    }
2300
                }
2301
                return ValueObjectTypeEntity.ValueEntity.of(entityOut);
×
2302
            }).build());
1✔
2303

2304
    /**
2305
     * If the given player has an external gui open.
2306
     */
2307
    public static final IOperator OBJECT_PLAYER_HASGUIOPEN = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.BOOLEAN)
7✔
2308
            .symbol("has_gui_open").operatorName("hasguiopen").interactName("hasGuiOpen")
6✔
2309
            .function(variables -> {
1✔
2310
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2311
                if(a.getRawValue().isPresent() && a.getRawValue().get() instanceof Player) {
×
2312
                    Player entity = (Player) a.getRawValue().get();
×
2313
                    return ValueTypeBoolean.ValueBoolean.of(entity.containerMenu != entity.inventoryMenu);
×
2314
                }
2315
                return ValueTypeBoolean.ValueBoolean.of(false);
×
2316
            }).build());
1✔
2317

2318
    /**
2319
     * The item the given entity is currently holding in its main hand.
2320
     */
2321
    public static final IOperator OBJECT_ENTITY_HELDITEM_MAIN = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.OBJECT_ITEMSTACK)
7✔
2322
            .symbol("held_item_1").operatorName("helditem").interactName("heldItem")
6✔
2323
            .function(variables -> {
1✔
2324
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2325
                ItemStack itemStack = ItemStack.EMPTY;
×
2326
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
×
2327
                    itemStack = ((LivingEntity) a.getRawValue().get()).getMainHandItem();
×
2328
                }
2329
                return ValueObjectTypeItemStack.ValueItemStack.of(itemStack);
×
2330
            }).build());
1✔
2331

2332
    /**
2333
     * The item the given entity is currently holding in its off hand.
2334
     */
2335
    public static final IOperator OBJECT_ENTITY_HELDITEM_OFF = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.OBJECT_ITEMSTACK)
7✔
2336
            .symbol("held_item_2").operatorName("helditemoffhand").interactName("heldItemOffHand")
6✔
2337
            .function(variables -> {
1✔
2338
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2339
                ItemStack itemStack = ItemStack.EMPTY;
×
2340
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
×
2341
                    itemStack = ((LivingEntity) a.getRawValue().get()).getOffhandItem();
×
2342
                }
2343
                return ValueObjectTypeItemStack.ValueItemStack.of(itemStack);
×
2344
            }).build());
1✔
2345

2346
    /**
2347
     * The entity's mounted entity
2348
     */
2349
    public static final IOperator OBJECT_ENTITY_MOUNTED = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.LIST)
7✔
2350
            .symbolOperator("mounted").interactName("mounted")
4✔
2351
            .function(variables -> {
1✔
2352
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2353
                List<ValueObjectTypeEntity.ValueEntity> passengers = Lists.newArrayList();
×
2354
                if(a.getRawValue().isPresent()) {
×
2355
                    for (Entity passenger : a.getRawValue().get().getPassengers()) {
×
2356
                        passengers.add(ValueObjectTypeEntity.ValueEntity.of(passenger));
×
2357
                    }
×
2358
                }
2359
                return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_ENTITY, passengers);
×
2360
            }).build());
1✔
2361

2362
    /**
2363
     * The item frame's contents
2364
     */
2365
    public static final IOperator OBJECT_ITEMFRAME_CONTENTS = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.OBJECT_ITEMSTACK)
7✔
2366
            .symbol("itemframe_contents").operatorName("itemframecontents").interactName("itemFrameContents")
6✔
2367
            .function(variables -> {
1✔
2368
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2369
                ItemStack itemStack = ItemStack.EMPTY;
×
2370
                if(a.getRawValue().isPresent() && a.getRawValue().get() instanceof ItemFrame) {
×
2371
                    itemStack = ((ItemFrame) a.getRawValue().get()).getItem();
×
2372
                }
2373
                return ValueObjectTypeItemStack.ValueItemStack.of(itemStack);
×
2374
            }).build());
1✔
2375

2376
    /**
2377
     * The item frame's rotation
2378
     */
2379
    public static final IOperator OBJECT_ITEMFRAME_ROTATION = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.INTEGER)
7✔
2380
            .symbol("itemframe_rotation").operatorName("itemframerotation").interactName("itemFrameRotation")
6✔
2381
            .function(variables -> {
1✔
2382
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2383
                Integer rotation = 0;
×
2384
                if(a.getRawValue().isPresent() && a.getRawValue().get() instanceof ItemFrame) {
×
2385
                    rotation = ((ItemFrame) a.getRawValue().get()).getRotation();
×
2386
                }
2387
                return ValueTypeInteger.ValueInteger.of(rotation);
×
2388
            }).build());
1✔
2389

2390
    /**
2391
     * The hurtsound of this entity.
2392
     */
2393
    public static final IOperator OBJECT_ENTITY_HURTSOUND = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.STRING)
7✔
2394
            .symbolOperator("hurtsound").interactName("hurtSound")
4✔
2395
            .function(variables -> {
1✔
2396
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2397
                String hurtSound = "";
×
2398
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
×
2399
                    String sound = ((LivingEntity) a.getRawValue().get()).getHurtSound(a.getRawValue().get().damageSources().generic()).location().toString();
×
2400
                    if (sound != null) {
×
2401
                        hurtSound = sound;
×
2402
                    }
2403
                }
2404
                return ValueTypeString.ValueString.of(hurtSound);
×
2405
            }).build());
1✔
2406

2407
    /**
2408
     * The deathsound of this entity.
2409
     */
2410
    public static final IOperator OBJECT_ENTITY_DEATHSOUND = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.STRING)
7✔
2411
            .symbolOperator("deathsound").interactName("deathSound")
4✔
2412
            .function(variables -> {
1✔
2413
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2414
                String hurtSound = "";
×
2415
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
×
2416
                    String sound = ((LivingEntity) a.getRawValue().get()).getDeathSound().location().toString();
×
2417
                    if (sound != null) {
×
2418
                        hurtSound = sound;
×
2419
                    }
2420
                }
2421
                return ValueTypeString.ValueString.of(hurtSound);
×
2422
            }).build());
1✔
2423

2424
    /**
2425
     * The age of this entity.
2426
     */
2427
    public static final IOperator OBJECT_ENTITY_AGE = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.INTEGER)
7✔
2428
            .symbolOperatorInteract("age")
2✔
2429
            .function(variables -> {
1✔
2430
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2431
                int age = 0;
×
2432
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
×
2433
                    age = ((LivingEntity) a.getRawValue().get()).getNoActionTime();
×
2434
                }
2435
                return ValueTypeInteger.ValueInteger.of(age);
×
2436
            }).build());
1✔
2437

2438
    /**
2439
     * If the entity is a child.
2440
     */
2441
    public static final IOperator OBJECT_ENTITY_ISCHILD = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.BOOLEAN)
7✔
2442
            .symbol("is_child").operatorName("ischild").interactName("isChild")
6✔
2443
            .function(variables -> {
1✔
2444
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2445
                boolean child = false;
×
2446
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof LivingEntity) {
×
2447
                    child = ((LivingEntity) a.getRawValue().get()).isBaby();
×
2448
                }
2449
                return ValueTypeBoolean.ValueBoolean.of(child);
×
2450
            }).build());
1✔
2451

2452
    /**
2453
     * If the entity can be bred.
2454
     */
2455
    public static final IOperator OBJECT_ENTITY_CANBREED = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.BOOLEAN)
7✔
2456
            .symbol("canbreed").operatorName("canbreed").interactName("canBreed")
6✔
2457
            .function(variables -> {
1✔
2458
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2459
                boolean canBreed = false;
×
2460
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof AgeableMob) {
×
2461
                    canBreed = ((AgeableMob) a.getRawValue().get()).getAge() == 0;
×
2462
                }
2463
                return ValueTypeBoolean.ValueBoolean.of(canBreed);
×
2464
            }).build());
1✔
2465

2466
    /**
2467
     * If the entity is in love.
2468
     */
2469
    public static final IOperator OBJECT_ENTITY_ISINLOVE = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.BOOLEAN)
7✔
2470
            .symbol("is_in_love").operatorName("isinlove").interactName("isInLove")
6✔
2471
            .function(variables -> {
1✔
2472
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2473
                boolean inLove = false;
×
2474
                if (a.getRawValue().isPresent() && a.getRawValue().get() instanceof Animal) {
×
2475
                    inLove = ((Animal) a.getRawValue().get()).isInLove();
×
2476
                }
2477
                return ValueTypeBoolean.ValueBoolean.of(inLove);
×
2478
            }).build());
1✔
2479

2480
    /**
2481
     * If the entity can be bred with the given item.
2482
     */
2483
    public static final IOperator OBJECT_ENTITY_CANBREEDWITH = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
14✔
2484
            .inputTypes(ValueTypes.OBJECT_ENTITY, ValueTypes.OBJECT_ITEMSTACK)
2✔
2485
            .output(ValueTypes.BOOLEAN)
2✔
2486
            .symbol("can_breed_with").operatorName("canbreedwith").interactName("canBreedWith")
6✔
2487
            .renderPattern(IConfigRenderPattern.INFIX_LONG)
2✔
2488
            .function(variables -> {
1✔
2489
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2490
                ValueObjectTypeItemStack.ValueItemStack b = variables.getValue(1, ValueTypes.OBJECT_ITEMSTACK);
×
2491
                boolean canBreedWith = false;
×
2492
                if (a.getRawValue().isPresent() && !b.getRawValue().isEmpty() && a.getRawValue().get() instanceof Animal) {
×
2493
                    canBreedWith = ((Animal) a.getRawValue().get()).isFood(b.getRawValue());
×
2494
                }
2495
                return ValueTypeBoolean.ValueBoolean.of(canBreedWith);
×
2496
            }).build());
1✔
2497

2498
    /**
2499
     * If the entity is shearable.
2500
     */
2501
    public static final IOperator OBJECT_ENTITY_ISSHEARABLE = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG.output(ValueTypes.BOOLEAN)
7✔
2502
            .symbol("is_shearable").operatorName("isshearable").interactName("isShearable")
6✔
2503
            .function(variables -> {
1✔
2504
                ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2505
                return ValueTypeBoolean.ValueBoolean.of(a.getRawValue().isPresent()
×
2506
                        && a.getRawValue().get() instanceof IShearable
×
2507
                        && ((IShearable) a.getRawValue().get()).isShearable(null, ItemStack.EMPTY, null, null));
×
2508
            }).build());
1✔
2509

2510
    /**
2511
     * The entity serialized to NBT.
2512
     */
2513
    public static final IOperator OBJECT_ENTITY_NBT = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2514
            .output(ValueTypes.NBT).symbol("NBT()").operatorInteract("nbt")
6✔
2515
            .function(input -> {
1✔
2516
                ValueObjectTypeEntity.ValueEntity entity = input.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2517
                try {
2518
                    if (entity.getRawValue().isPresent()) {
×
2519
                        Entity e = entity.getRawValue().get();
×
2520
                        try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(e.problemPath(), LOGGER)) {
×
2521
                            TagValueOutput valueOutput = TagValueOutput.createWithContext(scopedCollector, e.level().registryAccess());
×
2522
                            e.save(valueOutput);
×
2523
                            return ValueTypeNbt.ValueNbt.of(valueOutput.buildResult());
×
2524
                        }
2525
                    }
2526
                } catch (Exception e) {
×
2527
                    // Catch possible errors during NBT writing
2528
                }
×
2529
                return ValueTypes.NBT.getDefault();
×
2530
            }).build());
1✔
2531

2532
    /**
2533
     * The entity type.
2534
     */
2535
    public static final IOperator OBJECT_ENTITY_TYPE = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2536
            .output(ValueTypes.STRING).symbol("entity_type").operatorName("entitytype").interactName("type")
8✔
2537
            .function(input -> {
1✔
2538
                ValueObjectTypeEntity.ValueEntity entity = input.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2539
                String entityType = "";
×
2540
                if (entity.getRawValue().isPresent()) {
×
2541
                    Entity e = entity.getRawValue().get();
×
2542
                    entityType = BuiltInRegistries.ENTITY_TYPE.getKey(e.getType()).toString();
×
2543
                }
2544
                return ValueTypeString.ValueString.of(entityType);
×
2545
            }).build());
1✔
2546

2547
    /**
2548
     * The entity items.
2549
     */
2550
    public static final IOperator OBJECT_ENTITY_ITEMS = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2551
            .output(ValueTypes.LIST).symbol("entity_items").operatorName("entityitems").interactName("items")
8✔
2552
            .function(input -> {
1✔
2553
                ValueObjectTypeEntity.ValueEntity valueEntity = input.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2554
                Optional<Entity> a = valueEntity.getRawValue();
×
2555
                if(a.isPresent()) {
×
2556
                    Entity entity = a.get();
×
2557
                    return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyEntityItems(entity.level(), entity, null));
×
2558
                } else {
2559
                    return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_ITEMSTACK, Collections.emptyList());
×
2560
                }
2561
            }).build());
1✔
2562

2563
    /**
2564
     * The entity fluids.
2565
     */
2566
    public static final IOperator OBJECT_ENTITY_FLUIDS = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2567
            .output(ValueTypes.LIST).symbol("entity_fluids").operatorName("entityfluids").interactName("fluids")
8✔
2568
            .function(input -> {
1✔
2569
                ValueObjectTypeEntity.ValueEntity valueEntity = input.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2570
                Optional<Entity> a = valueEntity.getRawValue();
×
2571
                if(a.isPresent()) {
×
2572
                    Entity entity = a.get();
×
2573
                    return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyEntityFluids(entity.level(), entity, null));
×
2574
                } else {
2575
                    return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_FLUIDSTACK, Collections.emptyList());
×
2576
                }
2577
            }).build());
1✔
2578

2579
    /**
2580
     * The entity energy stored.
2581
     */
2582
    public static final IOperator OBJECT_ENTITY_ENERGY_STORED = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2583
            .output(ValueTypes.LONG).symbol("entity_stored_energy").operatorName("entityenergystored").interactName("energy")
8✔
2584
            .function(input -> {
1✔
2585
                ValueObjectTypeEntity.ValueEntity valueEntity = input.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2586
                Optional<Entity> a = valueEntity.getRawValue();
×
2587
                if(a.isPresent()) {
×
2588
                    Entity entity = a.get();
×
2589
                    EnergyHandler energyStorage = entity.getCapability(Capabilities.Energy.ENTITY, null);
×
2590
                    return ValueTypeLong.ValueLong.of(energyStorage != null ? energyStorage.getAmountAsLong() : 0);
×
2591
                }
2592
                return ValueTypeLong.ValueLong.of(0);
×
2593
            }).build());
1✔
2594

2595
    /**
2596
     * The entity energy stored.
2597
     */
2598
    public static final IOperator OBJECT_ENTITY_ENERGY_CAPACITY = REGISTRY.register(OperatorBuilders.ENTITY_1_SUFFIX_LONG
5✔
2599
            .output(ValueTypes.LONG).symbol("entity_capacity_energy").operatorName("entityenergycapacity").interactName("energyCapacity")
8✔
2600
            .function(input -> {
1✔
2601
                ValueObjectTypeEntity.ValueEntity valueEntity = input.getValue(0, ValueTypes.OBJECT_ENTITY);
×
2602
                Optional<Entity> a = valueEntity.getRawValue();
×
2603
                if(a.isPresent()) {
×
2604
                    Entity entity = a.get();
×
2605
                    EnergyHandler energyStorage = entity.getCapability(Capabilities.Energy.ENTITY, null);
×
2606
                    return ValueTypeLong.ValueLong.of(energyStorage != null ? energyStorage.getCapacityAsLong() : 0);
×
2607
                }
2608
                return ValueTypeLong.ValueLong.of(0);
×
2609
            }).build());
1✔
2610

2611
    /**
2612
     * ----------------------------------- FLUID STACK OBJECT OPERATORS -----------------------------------
2613
     */
2614

2615
    /**
2616
     * The amount of fluid in the fluidstack
2617
     */
2618
    public static final IOperator OBJECT_FLUIDSTACK_AMOUNT = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2619
            .output(ValueTypes.INTEGER).symbolOperatorInteract("amount")
5✔
2620
            .function(OperatorBuilders.FUNCTION_FLUIDSTACK_TO_INT.build(
2✔
2621
                    FluidStack::getAmount
2622
            )).build());
1✔
2623

2624
    /**
2625
     * The block from the fluidstack
2626
     */
2627
    public static final IOperator OBJECT_FLUIDSTACK_BLOCK = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2628
            .output(ValueTypes.OBJECT_BLOCK).symbolOperatorInteract("block")
4✔
2629
            .function(variables -> {
1✔
2630
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
×
2631
                FluidStack a = valueFluidStack.getRawValue();
×
2632
                return ValueObjectTypeBlock.ValueBlock.of(!a.isEmpty() ? a.getFluid().getFluidType().getStateForPlacement(null, null, a).createLegacyBlock() : null);
×
2633
            }).build());
1✔
2634

2635
    /**
2636
     * The fluidstack luminosity
2637
     */
2638
    public static final IOperator OBJECT_FLUIDSTACK_LIGHT_LEVEL = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2639
            .output(ValueTypes.INTEGER).symbolOperator("light_level").interactName("lightLevel")
7✔
2640
            .function(OperatorBuilders.FUNCTION_FLUIDSTACK_TO_INT.build(
2✔
2641
                fluidStack -> fluidStack.getFluid().getFluidType().getLightLevel(fluidStack)
×
2642
            )).build());
1✔
2643

2644
    /**
2645
     * The fluidstack density
2646
     */
2647
    public static final IOperator OBJECT_FLUIDSTACK_DENSITY = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2648
            .output(ValueTypes.INTEGER).symbolOperatorInteract("density")
5✔
2649
            .function(OperatorBuilders.FUNCTION_FLUIDSTACK_TO_INT.build(
2✔
2650
                fluidStack -> fluidStack.getFluid().getFluidType().getDensity(fluidStack)
×
2651
            )).build());
1✔
2652

2653
    /**
2654
     * The fluidstack temperature
2655
     */
2656
    public static final IOperator OBJECT_FLUIDSTACK_TEMPERATURE = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2657
            .output(ValueTypes.INTEGER).symbolOperatorInteract("temperature")
5✔
2658
            .function(OperatorBuilders.FUNCTION_FLUIDSTACK_TO_INT.build(
2✔
2659
                    fluidStack -> fluidStack.getFluid().getFluidType().getTemperature(fluidStack)
×
2660
            )).build());
1✔
2661

2662
    /**
2663
     * The fluidstack viscosity
2664
     */
2665
    public static final IOperator OBJECT_FLUIDSTACK_VISCOSITY = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2666
            .output(ValueTypes.INTEGER).symbolOperatorInteract("viscosity")
5✔
2667
            .function(OperatorBuilders.FUNCTION_FLUIDSTACK_TO_INT.build(
2✔
2668
                fluidStack -> fluidStack.getFluid().getFluidType().getViscosity(fluidStack)
×
2669
            )).build());
1✔
2670

2671
    /**
2672
     * If the fluidstack is gaseous
2673
     */
2674
    public static final IOperator OBJECT_FLUIDSTACK_IS_LIGHTER_THAN_AIR = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2675
            .output(ValueTypes.BOOLEAN).symbolOperator("lighter_than_air").interactName("isLighterThanAir")
7✔
2676
            .function(OperatorBuilders.FUNCTION_FLUIDSTACK_TO_BOOLEAN.build(
2✔
2677
                fluidStack -> fluidStack.getFluid().getFluidType().isLighterThanAir()
×
2678
            )).build());
1✔
2679

2680
    /**
2681
     * The rarity of the fluidstack
2682
     */
2683
    public static final IOperator OBJECT_FLUIDSTACK_RARITY = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2684
            .output(ValueTypes.STRING).symbolOperatorInteract("rarity")
4✔
2685
            .function(variables -> {
1✔
2686
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
×
2687
                FluidStack a = valueFluidStack.getRawValue();
×
2688
                return ValueTypeString.ValueString.of(a.getFluid().getFluidType().getRarity(a).name());
×
2689
            }).build());
1✔
2690

2691
    /**
2692
     * The bucket empty sound of the fluidstack
2693
     */
2694
    public static final IOperator OBJECT_FLUIDSTACK_SOUND_BUCKET_EMPTY = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2695
            .output(ValueTypes.STRING).symbolOperator("sound_bucket_empty").interactName("bucketEmptySound")
6✔
2696
            .function(variables -> {
1✔
2697
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
×
2698
                FluidStack a = valueFluidStack.getRawValue();
×
2699
                return ValueTypeString.ValueString.of(Optional.ofNullable(a.getFluid().getFluidType().getSound(a, SoundActions.BUCKET_EMPTY))
×
2700
                        .map(soundEvent -> soundEvent.location().toString())
×
2701
                        .orElse(""));
×
2702
            }).build());
1✔
2703

2704
    /**
2705
     * The fluid vaporize sound of the fluidstack
2706
     */
2707
    public static final IOperator OBJECT_FLUIDSTACK_SOUND_FLUID_VAPORIZE = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2708
            .output(ValueTypes.STRING).symbolOperator("sound_fluid_vaporize").interactName("fluidVaporizeSound")
6✔
2709
            .function(variables -> {
1✔
2710
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
×
2711
                FluidStack a = valueFluidStack.getRawValue();
×
2712
                return ValueTypeString.ValueString.of(Optional.ofNullable(a.getFluid().getFluidType().getSound(a, SoundActions.FLUID_VAPORIZE))
×
2713
                        .map(soundEvent -> soundEvent.location().toString())
×
2714
                        .orElse(""));
×
2715
            }).build());
1✔
2716

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

2730
    /**
2731
     * The bucket of the fluidstack
2732
     */
2733
    public static final IOperator OBJECT_FLUIDSTACK_BUCKET = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2734
            .output(ValueTypes.OBJECT_ITEMSTACK).symbolOperatorInteract("bucket")
4✔
2735
            .function(variables -> {
1✔
2736
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
×
2737
                FluidStack a = valueFluidStack.getRawValue();
×
2738
                return ValueObjectTypeItemStack.ValueItemStack.of(a.getFluid().getFluidType().getBucket(a));
×
2739
            }).build());
1✔
2740

2741
    /**
2742
     * If the fluid types of the two given fluidstacks are equal
2743
     */
2744
    public static final IOperator OBJECT_FLUIDSTACK_ISRAWFLUIDEQUAL = REGISTRY.register(OperatorBuilders.FLUIDSTACK_2
5✔
2745
            .output(ValueTypes.BOOLEAN).symbol("=Raw=").operatorName("israwfluidequal").interactName("isRawEqual")
8✔
2746
            .function(variables -> {
1✔
2747
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack0 = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
×
2748
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack1 = variables.getValue(1, ValueTypes.OBJECT_FLUIDSTACK);
×
2749
                return ValueTypeBoolean.ValueBoolean.of(FluidStack.isSameFluid(valueFluidStack0.getRawValue(), valueFluidStack1.getRawValue()));
×
2750
            }).build());
1✔
2751

2752
    /**
2753
     * The name of the mod owning this fluid
2754
     */
2755
    public static final IOperator OBJECT_FLUIDSTACK_MODNAME = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG.output(ValueTypes.STRING)
7✔
2756
            .symbolOperatorInteract("mod")
13✔
2757
            .function(new IterativeFunction(Lists.newArrayList(
3✔
2758
                    (OperatorBase.SafeVariablesGetter variables) -> {
2759
                        ValueObjectTypeFluidStack.ValueFluidStack a = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
×
2760
                        return BuiltInRegistries.FLUID.getKey(a.getRawValue().getFluid());
×
2761
                    },
2762
                    OperatorBuilders.PROPAGATOR_RESOURCELOCATION_MODNAME
2763
            ))).build());
1✔
2764

2765
    /**
2766
     * The tag of the given fluidstack.
2767
     */
2768
    public static final IOperator OBJECT_FLUIDSTACK_DATA = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2769
            .output(ValueTypes.NBT).symbol("NBT()").operatorInteract("nbt")
6✔
2770
            .function(input -> {
1✔
2771
                ValueObjectTypeFluidStack.ValueFluidStack fluidStack = input.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
×
2772
                if (fluidStack.getRawValue().getComponentsPatch().isEmpty()) {
×
2773
                    return ValueTypeNbt.ValueNbt.of(Optional.empty());
×
2774
                }
2775
                return ValueTypeNbt.ValueNbt.of(DataComponentPatch.CODEC.encodeStart(ServerLifecycleHooks.getCurrentServer().registryAccess().createSerializationContext(NbtOps.INSTANCE), fluidStack.getRawValue().getComponentsPatch()).getOrThrow());
×
2776
            }).build());
1✔
2777

2778
    /**
2779
     * Create a new fluidstack with the given amount.
2780
     */
2781
    public static final IOperator OBJECT_FLUIDSTACK_WITH_AMOUNT = REGISTRY.register(OperatorBuilders.FLUIDSTACK_2
14✔
2782
            .inputTypes(ValueTypes.OBJECT_FLUIDSTACK, ValueTypes.INTEGER)
2✔
2783
            .output(ValueTypes.OBJECT_FLUIDSTACK).symbolOperator("with_amount").interactName("withAmount")
6✔
2784
            .function(variables -> {
1✔
2785
                ValueObjectTypeFluidStack.ValueFluidStack valueFluidStack = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
×
2786
                ValueTypeInteger.ValueInteger valueInteger = variables.getValue(1, ValueTypes.INTEGER);
×
2787
                FluidStack fluidStack = valueFluidStack.getRawValue().copy();
×
2788
                fluidStack.setAmount(valueInteger.getRawValue());
×
2789
                return ValueObjectTypeFluidStack.ValueFluidStack.of(fluidStack);
×
2790
            }).build());
1✔
2791

2792
    /**
2793
     * Get the data component keys of an fluidstack.
2794
     */
2795
    public static final IOperator OBJECT_FLUIDSTACK_DATA_KEYS = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2796
            .output(ValueTypes.LIST).symbol("data_keys").operatorName("datakeys").interactName("dataKeys")
8✔
2797
            .function(input -> {
1✔
2798
                ValueObjectTypeFluidStack.ValueFluidStack fluidStack = input.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
×
2799
                // Explicitly check for fluid emptiness first, because vanilla sometimes persists NBT when setting stacks to empty
2800
                return ValueTypeList.ValueList.ofList(ValueTypes.STRING,
×
2801
                        fluidStack.getRawValue().isEmpty() ?
×
2802
                                Lists.newArrayList() :
×
2803
                                fluidStack.getRawValue().getComponents().keySet().stream()
×
2804
                                        .filter(c -> !c.isTransient())
×
2805
                                        .map(c -> ValueTypeString.ValueString.of(BuiltInRegistries.DATA_COMPONENT_TYPE.getKey(c).toString()))
×
2806
                                        .sorted((o1, o2) -> o1.getRawValue().compareTo(o2.getRawValue()))
×
2807
                                        .toList());
×
2808
            }).build());
1✔
2809

2810
    /**
2811
     * Get the data component value by key
2812
     */
2813
    public static final IOperator OBJECT_FLUIDSTACK_DATA_VALUE = REGISTRY.register(OperatorBuilders.FLUIDSTACK_2_LONG
14✔
2814
            .inputTypes(ValueTypes.OBJECT_FLUIDSTACK, ValueTypes.STRING)
2✔
2815
            .output(ValueTypes.NBT).symbol("data_value").operatorName("datavalue").interactName("dataValue")
8✔
2816
            .function(input -> {
1✔
2817
                ValueObjectTypeFluidStack.ValueFluidStack fluidStack = input.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
×
2818

2819
                // Determine data component type
2820
                DataComponentType<?> dataComponentType;
2821
                try {
2822
                    dataComponentType = BuiltInRegistries.DATA_COMPONENT_TYPE.getValue(ResourceLocation.parse(input.getValue(1, ValueTypes.STRING).getRawValue()));
×
2823
                } catch (ResourceLocationException e) {
×
2824
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
2825
                }
×
2826

2827
                // Fetch component value
2828
                TypedDataComponent<?> typedComponent = fluidStack.getRawValue().getComponents().getTyped(dataComponentType);
×
2829
                if (typedComponent == null) {
×
2830
                    return ValueTypeNbt.ValueNbt.of((Tag) null);
×
2831
                }
2832

2833
                // Encode component value
2834
                try {
2835
                    Tag tag = typedComponent.encodeValue(ServerLifecycleHooks.getCurrentServer().registryAccess().createSerializationContext(NbtOps.INSTANCE)).getOrThrow();
×
2836
                    return ValueTypeNbt.ValueNbt.of(tag);
×
2837
                } catch (IllegalStateException e) {
×
2838
                    return ValueTypeNbt.ValueNbt.of((Tag) null);
×
2839
                }
2840
            }).build());
1✔
2841

2842
    /**
2843
     * Set the data component value by key
2844
     */
2845
    public static final IOperator OBJECT_FLUIDSTACK_WITH_DATA = REGISTRY.register(OperatorBuilders.FLUIDSTACK_3
18✔
2846
            .inputTypes(ValueTypes.OBJECT_FLUIDSTACK, ValueTypes.STRING, ValueTypes.NBT)
2✔
2847
            .output(ValueTypes.NBT).symbol("with_data").operatorName("withdata").interactName("withData")
8✔
2848
            .function(input -> {
1✔
2849
                ValueObjectTypeFluidStack.ValueFluidStack fluidStack = input.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
×
2850

2851
                // Skip further processing if input value is empty
2852
                Optional<Tag> tagOptional = input.getValue(2, ValueTypes.NBT).getRawValue();
×
2853
                if (!tagOptional.isPresent()) {
×
2854
                    return fluidStack;
×
2855
                }
2856

2857
                // Determine data component type
2858
                DataComponentType<?> dataComponentType;
2859
                try {
2860
                    dataComponentType = BuiltInRegistries.DATA_COMPONENT_TYPE.getValue(ResourceLocation.parse(input.getValue(1, ValueTypes.STRING).getRawValue()));
×
2861
                } catch (ResourceLocationException e) {
×
2862
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
2863
                }
×
2864

2865
                // Encode component value
2866
                try {
2867
                    Object value = dataComponentType.codec().decode(ServerLifecycleHooks.getCurrentServer().registryAccess().createSerializationContext(NbtOps.INSTANCE), tagOptional.get()).getOrThrow().getFirst();
×
2868
                    fluidStack = ValueObjectTypeFluidStack.ValueFluidStack.of(fluidStack.getRawValue().copy());
×
2869
                    fluidStack.getRawValue().set((DataComponentType) dataComponentType, value);
×
2870
                    return fluidStack;
×
2871
                } catch (IllegalStateException e) {
×
2872
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
2873
                }
2874
            }).build());
1✔
2875

2876
    /**
2877
     * The tag entries of the given fluidstack
2878
     */
2879
    public static final IOperator OBJECT_FLUIDSTACK_TAG = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_SUFFIX_LONG
5✔
2880
            .output(ValueTypes.LIST)
2✔
2881
            .symbol("fluid_tag_names").operatorName("tag").interactName("tags")
6✔
2882
            .function(variables -> {
1✔
2883
                ValueObjectTypeFluidStack.ValueFluidStack a = variables.getValue(0, ValueTypes.OBJECT_FLUIDSTACK);
×
2884
                ImmutableList.Builder<ValueTypeString.ValueString> builder = ImmutableList.builder();
×
2885
                if(!a.getRawValue().isEmpty()) {
×
2886
                    a.getRawValue().getFluid().builtInRegistryHolder().tags()
×
2887
                            .forEach(owningTag -> builder.add(ValueTypeString.ValueString
×
2888
                                    .of(owningTag.location().toString())));
×
2889
                }
2890
                return ValueTypeList.ValueList.ofList(ValueTypes.STRING, builder.build());
×
2891
            }).build());
1✔
2892

2893
    /**
2894
     * Get a list of fluidstacks that correspond to the given tag key.
2895
     */
2896
    public static final IOperator OBJECT_FLUIDSTACK_TAG_STACKS = REGISTRY.register(OperatorBuilders.STRING_1_PREFIX
5✔
2897
            .output(ValueTypes.LIST)
2✔
2898
            .symbol("fluid_tag_values").operatorName("fluidtag").interactName("fluidsByTag")
6✔
2899
            .symbol("fluid_tag_values").operatorName("fluidtag").interactName("fluidsByTag")
6✔
2900
            .inputType(ValueTypes.STRING).renderPattern(IConfigRenderPattern.SUFFIX_1_LONG)
4✔
2901
            .function(variables -> {
1✔
2902
                ValueTypeString.ValueString a = variables.getValue(0, ValueTypes.STRING);
×
2903
                ImmutableList.Builder<ValueObjectTypeFluidStack.ValueFluidStack> builder = ImmutableList.builder();
×
2904
                if (!StringUtil.isNullOrEmpty(a.getRawValue())) {
×
2905
                    try {
2906
                        Helpers.getFluidTagValues(a.getRawValue())
×
2907
                                .map(ValueObjectTypeFluidStack.ValueFluidStack::of)
×
2908
                                .forEach(builder::add);
×
2909
                    } catch (ResourceLocationException e) {
×
2910
                        throw new EvaluationException(Component.translatable(e.getMessage()));
×
2911
                    }
×
2912
                }
2913
                return ValueTypeList.ValueList.ofList(ValueTypes.OBJECT_FLUIDSTACK, builder.build());
×
2914
            }).build());
1✔
2915

2916
    /**
2917
     * Get an fluid by name.
2918
     */
2919
    public static final IOperator OBJECT_FLUIDSTACK_BY_NAME = REGISTRY.register(OperatorBuilders.FLUIDSTACK_1_PREFIX_LONG
5✔
2920
            .inputType(ValueTypes.STRING).output(ValueTypes.OBJECT_FLUIDSTACK)
4✔
2921
            .symbol("fluid_by_name").operatorName("fluidbyname").interactName("fluidByName")
7✔
2922
            .function(OperatorBuilders.FUNCTION_STRING_TO_RESOURCE_LOCATION
1✔
2923
                    .build(input -> {
1✔
2924
                        Fluid fluid = BuiltInRegistries.FLUID.getValue(input);
×
2925
                        FluidStack fluidStack = FluidStack.EMPTY;
×
2926
                        if (fluid != null) {
×
2927
                            fluidStack = new FluidStack(fluid, IModHelpersNeoForge.get().getFluidHelpers().getBucketVolume());
×
2928
                        }
2929
                        return ValueObjectTypeFluidStack.ValueFluidStack.of(fluidStack);
×
2930
                    })).build());
1✔
2931

2932
    /**
2933
     * ----------------------------------- OPERATOR OPERATORS -----------------------------------
2934
     */
2935

2936
    /**
2937
     * Apply for a given operator a given value.
2938
     */
2939
    public static final IOperator OPERATOR_APPLY = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
5✔
2940
            .conditionalOutputTypeDeriver(OperatorBuilders.OPERATOR_CONDITIONAL_OUTPUT_DERIVER)
2✔
2941
            .output(ValueTypes.CATEGORY_ANY).symbolOperatorInteract("apply")
9✔
2942
            .typeValidator(OperatorBuilders.createOperatorTypeValidator(ValueTypes.CATEGORY_ANY))
4✔
2943
            .function(OperatorBuilders.FUNCTION_OPERATOR_TAKE_OPERATOR.build(
2✔
2944
                    input -> {
2945
                        IOperator innerOperator = input.getLeft();
4✔
2946
                        OperatorBase.SafeVariablesGetter variables = input.getRight();
4✔
2947
                        IVariable variable = variables.getVariables()[0];
5✔
2948
                        return ValueHelpers.evaluateOperator(innerOperator, variable);
9✔
2949
                    })).build());
1✔
2950
    static {
2951
        REGISTRY.registerSerializer(new CurriedOperator.Serializer());
5✔
2952
    }
2953

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

2972
    /**
2973
     * Apply for a given operator the given 3 values.
2974
     */
2975
    public static final IOperator OPERATOR_APPLY_3 = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
5✔
2976
            .renderPattern(IConfigRenderPattern.INFIX_3)
2✔
2977
            .conditionalOutputTypeDeriver(OperatorBuilders.OPERATOR_CONDITIONAL_OUTPUT_DERIVER)
19✔
2978
            .inputTypes(ValueTypes.OPERATOR, ValueTypes.CATEGORY_ANY, ValueTypes.CATEGORY_ANY, ValueTypes.CATEGORY_ANY)
2✔
2979
            .output(ValueTypes.CATEGORY_ANY).symbolOperatorInteract("apply3")
17✔
2980
            .typeValidator(OperatorBuilders.createOperatorTypeValidator(ValueTypes.CATEGORY_ANY, ValueTypes.CATEGORY_ANY, ValueTypes.CATEGORY_ANY))
4✔
2981
            .function(OperatorBuilders.FUNCTION_OPERATOR_TAKE_OPERATOR.build(
2✔
2982
                    input -> {
2983
                        IOperator innerOperator = input.getLeft();
4✔
2984
                        OperatorBase.SafeVariablesGetter variables = input.getRight();
4✔
2985
                        IVariable variable0 = variables.getVariables()[0];
5✔
2986
                        IVariable variable1 = variables.getVariables()[1];
5✔
2987
                        IVariable variable2 = variables.getVariables()[2];
5✔
2988
                        return ValueHelpers.evaluateOperator(innerOperator, variable0, variable1, variable2);
17✔
2989
                    })).build());
1✔
2990

2991
    /**
2992
     * Apply for a given operator the given list of values.
2993
     */
2994
    public static final IOperator OPERATOR_APPLY_N = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
5✔
2995
            .conditionalOutputTypeDeriver(OperatorBuilders.OPERATOR_CONDITIONAL_OUTPUT_DERIVER_LIST)
11✔
2996
            .inputTypes(ValueTypes.OPERATOR, ValueTypes.LIST)
2✔
2997
            .output(ValueTypes.CATEGORY_ANY).symbolOperatorInteract("apply_n")
9✔
2998
            .typeValidator(OperatorBuilders.createOperatorTypeValidator(ValueTypes.LIST))
4✔
2999
            .function(OperatorBuilders.FUNCTION_OPERATOR_TAKE_OPERATOR_LIST.build(
2✔
3000
                    input -> {
3001
                        IOperator innerOperator = input.getLeft();
4✔
3002
                        OperatorBase.SafeVariablesGetter variables = input.getRight();
4✔
3003
                        IValueTypeListProxy<IValueType<IValue>, IValue> list = variables.getValue(0, ValueTypes.LIST).getRawValue();
7✔
3004
                        return ValueHelpers.evaluateOperator(innerOperator, Iterables.toArray(list, IValue.class));
7✔
3005
                    })).build());
1✔
3006

3007
    /**
3008
     * Apply for a given operator with zero arguments.
3009
     */
3010
    public static final IOperator OPERATOR_APPLY_0 = REGISTRY.register(OperatorBuilders.OPERATOR_1_PREFIX_LONG
5✔
3011
            .conditionalOutputTypeDeriver(OperatorBuilders.OPERATOR_CONDITIONAL_OUTPUT_DERIVER)
2✔
3012
            .output(ValueTypes.CATEGORY_ANY).symbolOperatorInteract("apply0")
5✔
3013
            .typeValidator(OperatorBuilders.createOperatorTypeValidator(new IValueType[0]))
4✔
3014
            .function(OperatorBuilders.FUNCTION_OPERATOR_TAKE_OPERATOR.build(
2✔
3015
                    input -> {
3016
                        IOperator innerOperator = input.getLeft();
4✔
3017
                        return ValueHelpers.evaluateOperator(innerOperator, new IVariable[0]);
5✔
3018
                    })).build());
1✔
3019

3020
    /**
3021
     * Apply the given operator on all elements of a list, resulting in a new list of mapped values.
3022
     */
3023
    public static final IOperator OPERATOR_MAP = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
14✔
3024
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.LIST})
2✔
3025
            .output(ValueTypes.LIST).symbolOperatorInteract("map")
5✔
3026
            .function(OperatorBuilders.FUNCTION_OPERATOR_TAKE_OPERATOR_LIST.build(
2✔
3027
                    input -> {
3028
                        final IOperator innerOperator = input.getLeft();
4✔
3029
                        OperatorBase.SafeVariablesGetter variables = input.getRight();
4✔
3030
                        ValueTypeList.ValueList inputList = variables.getValue(0, ValueTypes.LIST);
6✔
3031
                        return ValueTypeList.ValueList.ofFactory(
6✔
3032
                                new ValueTypeListProxyOperatorMapped(innerOperator, inputList.getRawValue()));
2✔
3033
                    })).build());
1✔
3034

3035
    /**
3036
     * Filter a list of elements by matching them all with the given predicate.
3037
     */
3038
    public static final IOperator OPERATOR_FILTER = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
14✔
3039
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.LIST})
2✔
3040
            .output(ValueTypes.LIST).symbolOperatorInteract("filter")
7✔
3041
            .function(OperatorBuilders.FUNCTION_OPERATOR_TAKE_OPERATOR_LIST.build(
2✔
3042
                    new IOperatorValuePropagator<Pair<IOperator, OperatorBase.SafeVariablesGetter>, IValue>() {
3✔
3043
                        @Override
3044
                        public IValue getOutput(Pair<IOperator, OperatorBase.SafeVariablesGetter> input) throws EvaluationException {
3045
                            final IOperator innerOperator = input.getLeft();
4✔
3046
                            OperatorBase.SafeVariablesGetter variables = input.getRight();
4✔
3047
                            ValueTypeList.ValueList<?, ?> inputList = variables.getValue(0, ValueTypes.LIST);
6✔
3048
                            List<IValue> filtered = Lists.newArrayList();
2✔
3049
                            for (IValue value : inputList.getRawValue()) {
11✔
3050
                                IValue result = ValueHelpers.evaluateOperator(innerOperator, value);
9✔
3051
                                ValueHelpers.validatePredicateOutput(innerOperator, result);
3✔
3052
                                if (((ValueTypeBoolean.ValueBoolean) result).getRawValue()) {
4✔
3053
                                    filtered.add(value);
4✔
3054
                                }
3055
                            }
1✔
3056
                            IValueType valueType = inputList.getRawValue().getValueType();
4✔
3057
                            return ValueTypeList.ValueList.ofList(valueType, filtered);
4✔
3058
                        }
3059
                    })).build());
1✔
3060

3061
    /**
3062
     * Takes the conjunction of two predicates.
3063
     */
3064
    public static final IOperator OPERATOR_CONJUNCTION = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
14✔
3065
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.OPERATOR})
2✔
3066
            .output(ValueTypes.OPERATOR).symbol(".&&.").operatorInteract("conjunction")
7✔
3067
            .function(OperatorBuilders.FUNCTION_TWO_PREDICATES.build(
2✔
3068
                input -> ValueTypeOperator.ValueOperator.of(CombinedOperator.Conjunction.asOperator(input.getLeft(), input.getRight()))
17✔
3069
            )).build());
1✔
3070
    static {
3071
        REGISTRY.registerSerializer(new CombinedOperator.Conjunction.Serializer());
5✔
3072
    }
3073

3074
    /**
3075
     * Takes the disjunction of two predicates.
3076
     */
3077
    public static final IOperator OPERATOR_DISJUNCTION = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
14✔
3078
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.OPERATOR})
2✔
3079
            .output(ValueTypes.OPERATOR).symbol(".||.").operatorInteract("disjunction")
7✔
3080
            .function(OperatorBuilders.FUNCTION_TWO_PREDICATES.build(
2✔
3081
                input -> ValueTypeOperator.ValueOperator.of(CombinedOperator.Disjunction.asOperator(input.getLeft(), input.getRight()))
17✔
3082
            )).build());
1✔
3083
    static {
3084
        REGISTRY.registerSerializer(new CombinedOperator.Disjunction.Serializer());
5✔
3085
    }
3086

3087
    /**
3088
     * Takes the negation of a predicate.
3089
     */
3090
    public static final IOperator OPERATOR_NEGATION = REGISTRY.register(OperatorBuilders.OPERATOR_1_PREFIX_LONG
5✔
3091
            .renderPattern(IConfigRenderPattern.PREFIX_1)
7✔
3092
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR})
2✔
3093
            .output(ValueTypes.OPERATOR).symbol("!.").operatorInteract("negation")
7✔
3094
            .function(OperatorBuilders.FUNCTION_ONE_PREDICATE.build(
2✔
3095
                input -> ValueTypeOperator.ValueOperator.of(CombinedOperator.Negation.asOperator(input))
4✔
3096
            )).build());
1✔
3097
    static {
3098
        REGISTRY.registerSerializer(new CombinedOperator.Negation.Serializer());
5✔
3099
    }
3100

3101
    /**
3102
     * Create a new operator that pipes the output from the first operator to the second operator.
3103
     */
3104
    public static final IOperator OPERATOR_PIPE = REGISTRY.register(OperatorBuilders.OPERATOR_2_INFIX_LONG
14✔
3105
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.OPERATOR})
2✔
3106
            .output(ValueTypes.OPERATOR).symbol(".").operatorInteract("pipe")
7✔
3107
            .function(OperatorBuilders.FUNCTION_TWO_OPERATORS.build(
2✔
3108
                input -> ValueTypeOperator.ValueOperator.of(CombinedOperator.Pipe.asOperator(input.getLeft(), input.getRight()))
17✔
3109
            )).build());
1✔
3110
    static {
3111
        REGISTRY.registerSerializer(new CombinedOperator.Pipe.Serializer());
5✔
3112
    }
3113

3114
    /**
3115
     * 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.
3116
     */
3117
    public static final IOperator OPERATOR_PIPE2 = REGISTRY.register(OperatorBuilders.OPERATOR
18✔
3118
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.OPERATOR, ValueTypes.OPERATOR})
2✔
3119
            .renderPattern(IConfigRenderPattern.INFIX_2_LATE)
2✔
3120
            .output(ValueTypes.OPERATOR).symbol(".2").operatorInteract("pipe2")
7✔
3121
            .function(OperatorBuilders.FUNCTION_THREE_OPERATORS.build(
2✔
3122
                input -> ValueTypeOperator.ValueOperator.of(CombinedOperator.Pipe2.asOperator(input.getLeft(), input.getMiddle(), input.getRight()))
23✔
3123
            )).build());
1✔
3124
    static {
3125
        REGISTRY.registerSerializer(new CombinedOperator.Pipe2.Serializer());
5✔
3126
    }
3127

3128
    /**
3129
     * Flip the input parameters of an operator with two inputs.
3130
     */
3131
    public static final IOperator OPERATOR_FLIP = REGISTRY.register(OperatorBuilders.OPERATOR_1_PREFIX_LONG
5✔
3132
            .renderPattern(IConfigRenderPattern.PREFIX_1)
7✔
3133
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR})
2✔
3134
            .output(ValueTypes.OPERATOR).symbolOperatorInteract("flip")
5✔
3135
            .function(OperatorBuilders.FUNCTION_ONE_OPERATOR.build(
2✔
3136
                input -> ValueTypeOperator.ValueOperator.of(CombinedOperator.Flip.asOperator(input))
4✔
3137
            )).build());
1✔
3138
    static {
3139
        REGISTRY.registerSerializer(new CombinedOperator.Flip.Serializer());
5✔
3140
    }
3141

3142
    /**
3143
     * Apply the given operator on all elements of a list to reduce the list to one value.
3144
     */
3145
    public static final IOperator OPERATOR_REDUCE = REGISTRY.register(OperatorBuilders.OPERATOR
18✔
3146
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.LIST, ValueTypes.CATEGORY_ANY})
2✔
3147
            .renderPattern(IConfigRenderPattern.PREFIX_3_LONG)
2✔
3148
            .output(ValueTypes.CATEGORY_ANY).symbolOperatorInteract("reduce")
4✔
3149
            .conditionalOutputTypeDeriver((operator, input) -> input[2].getType())
7✔
3150
            .function(variables -> {
1✔
3151
                IValue accumulator = variables.getValue(2);
4✔
3152
                final IOperator innerOperator = OperatorBuilders.getSafeOperator(
5✔
3153
                        variables.getValue(0, ValueTypes.OPERATOR), accumulator.getType());
4✔
3154
                ValueTypeList.ValueList<IValueType<IValue>, IValue> inputList = variables.getValue(1, ValueTypes.LIST);
6✔
3155
                for (IValue listValue : inputList.getRawValue()) {
11✔
3156
                    accumulator = ValueHelpers.evaluateOperator(innerOperator, accumulator, listValue);
13✔
3157
                }
1✔
3158
                return accumulator;
2✔
3159
            }).build());
1✔
3160

3161
    /**
3162
     * Apply the given operator on all elements of a list to reduce the list to one value.
3163
     */
3164
    public static final IOperator OPERATOR_REDUCE1 = REGISTRY.register(OperatorBuilders.OPERATOR
14✔
3165
            .inputTypes(new IValueType[]{ValueTypes.OPERATOR, ValueTypes.LIST})
2✔
3166
            .renderPattern(IConfigRenderPattern.PREFIX_2_LONG)
2✔
3167
            .output(ValueTypes.CATEGORY_ANY).symbolOperatorInteract("reduce1")
4✔
3168
            .conditionalOutputTypeDeriver((operator, input) -> {
2✔
3169
                try {
3170
                    IValueTypeListProxy a = ((ValueTypeList.ValueList) input[1].getValue()).getRawValue();
7✔
3171
                    return a.getValueType();
3✔
3172
                } catch (EvaluationException e) {
×
3173
                    return operator.getOutputType();
×
3174
                }
3175
            })
3176
            .function(variables -> {
1✔
3177
                ValueTypeList.ValueList valueList = variables.getValue(1, ValueTypes.LIST);
6✔
3178
                Iterator<IValue> iter = valueList.getRawValue().iterator();
4✔
3179
                if (!iter.hasNext()) {
3✔
3180
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_REDUCE_EMPTY));
6✔
3181
                }
3182

3183
                IValue accumulator = iter.next();
4✔
3184
                final IOperator innerOperator = OperatorBuilders.getSafeOperator(
5✔
3185
                        variables.getValue(0, ValueTypes.OPERATOR), accumulator.getType());
4✔
3186

3187
                while (iter.hasNext()) {
3✔
3188
                    IValue listValue = iter.next();
4✔
3189
                    accumulator = ValueHelpers.evaluateOperator(innerOperator, accumulator, listValue);
13✔
3190
                }
1✔
3191
                return accumulator;
2✔
3192
            }).build());
1✔
3193

3194
    /**
3195
     * Apply for a given operator a given value.
3196
     */
3197
    public static final IOperator OPERATOR_BY_NAME = REGISTRY.register(OperatorBuilders.OPERATOR_1_PREFIX_LONG
5✔
3198
            .inputType(ValueTypes.STRING).output(ValueTypes.OPERATOR)
4✔
3199
            .symbol("op_by_name").operatorName("by_name").interactName("operatorByName")
6✔
3200
            .function(input -> {
1✔
3201
                ValueTypeString.ValueString name = input.getValue(0, ValueTypes.STRING);
6✔
3202
                try {
3203
                    ResourceLocation id = ResourceLocation.parse(name.getRawValue());
4✔
3204
                    IOperator operator = Operators.REGISTRY.getOperator(id);
4✔
3205
                    if (operator == null) {
2✔
3206
                        throw new EvaluationException(Component.translatable(
11✔
3207
                                L10NValues.OPERATOR_ERROR_OPERATORNOTFOUND, name.getRawValue()));
2✔
3208
                    }
3209
                    return ValueTypeOperator.ValueOperator.of(operator);
3✔
3210
                } catch (ResourceLocationException e) {
×
3211
                    throw new EvaluationException(Component.literal(e.getMessage()));
×
3212
                }
3213
            }).build());
1✔
3214

3215
    /**
3216
     * ----------------------------------- NBT OPERATORS -----------------------------------
3217
     */
3218

3219
    /**
3220
     * The number of entries in an NBT tag
3221
     */
3222
    public static final IOperator NBT_COMPOUND_SIZE = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3223
            .output(ValueTypes.INTEGER).operatorName("compound_size").symbol("NBT{}.size").interactName("size")
9✔
3224
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_TO_INT.build(
2✔
3225
                opt -> opt.map(CompoundTag::size).orElse(0)
8✔
3226
            )).build());
1✔
3227

3228
    /**
3229
     * The list of keys in an NBT tag
3230
     */
3231
    public static final IOperator NBT_COMPOUND_KEYS = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3232
            .output(ValueTypes.LIST).operatorName("compound_keys").symbol("NBT{}.keys").interactName("keys")
8✔
3233
            .function(variables -> {
1✔
3234
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3235
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtKeys(value.getRawValue()));
7✔
3236
            }).build());
1✔
3237

3238
    /**
3239
     * If an NBT tag has the given key
3240
     */
3241
    public static final IOperator NBT_COMPOUND_HASKEY = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3242
            .output(ValueTypes.BOOLEAN).operatorName("compound_haskey").symbol("NBT{}.has_key").interactName("hasKey")
9✔
3243
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_BOOLEAN.build(
2✔
3244
                    Optional::isPresent
3245
            )).build());
1✔
3246

3247
    /**
3248
     * The NBT value type of an entry
3249
     */
3250
    public static final IOperator NBT_COMPOUND_VALUE_TYPE = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3251
            .output(ValueTypes.STRING).operatorName("compound_type").symbol("NBT{}.type").interactName("type")
9✔
3252
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_STRING.build(tag -> {
2✔
3253
                if (tag.isPresent()) {
3✔
3254
                    try {
3255
                        return TagTypes.getType(tag.get().getId()).getName();
7✔
3256
                    } catch (IndexOutOfBoundsException e) {
×
3257

3258
                    }
3259
                }
3260
                return "null";
2✔
3261
            })).build());
1✔
3262

3263
    /**
3264
     * The NBT tag value
3265
     */
3266
    public static final IOperator NBT_COMPOUND_VALUE_TAG = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3267
            .output(ValueTypes.NBT).operatorName("compound_value_tag").symbol("NBT{}.get_tag").interactName("getTag")
9✔
3268
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_NBT.build(o -> o)).build());
5✔
3269

3270
    /**
3271
     * The NBT boolean value
3272
     */
3273
    public static final IOperator NBT_COMPOUND_VALUE_BOOLEAN = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3274
            .output(ValueTypes.BOOLEAN).operatorName("compound_value_boolean").symbol("NBT{}.get_boolean").interactName("getBoolean")
9✔
3275
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_BOOLEAN.build(
2✔
3276
                    o -> o.flatMap(Tag::asBoolean).orElse(false)
8✔
3277
            )).build());
1✔
3278

3279
    /**
3280
     * The NBT integer value
3281
     */
3282
    public static final IOperator NBT_COMPOUND_VALUE_INTEGER = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3283
            .output(ValueTypes.INTEGER).operatorName("compound_value_integer").symbol("NBT{}.get_integer").interactName("getInteger")
9✔
3284
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_INT.build(
2✔
3285
                    o -> o.flatMap(Tag::asInt).orElse(0)
8✔
3286
            )).build());
1✔
3287

3288
    /**
3289
     * The NBT long value
3290
     */
3291
    public static final IOperator NBT_COMPOUND_VALUE_LONG = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3292
            .output(ValueTypes.LONG).operatorName("compound_value_long").symbol("NBT{}.get_long").interactName("getLong")
9✔
3293
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_LONG.build(
2✔
3294
                    o -> o.flatMap(Tag::asLong).orElse(0L)
8✔
3295
            )).build());
1✔
3296

3297
    /**
3298
     * The NBT double value
3299
     */
3300
    public static final IOperator NBT_COMPOUND_VALUE_DOUBLE = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3301
            .output(ValueTypes.DOUBLE).operatorName("compound_value_double").symbol("NBT{}.get_double").interactName("getDouble")
9✔
3302
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_DOUBLE.build(
2✔
3303
                    o -> o.flatMap(Tag::asDouble).orElse(0D)
8✔
3304
            )).build());
1✔
3305

3306
    /**
3307
     * The NBT string value
3308
     */
3309
    public static final IOperator NBT_COMPOUND_VALUE_STRING = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3310
            .output(ValueTypes.STRING).operatorName("compound_value_string").symbol("NBT{}.get_string").interactName("getString")
9✔
3311
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_STRING.build(
2✔
3312
                    o -> o.flatMap(Tag::asString).orElse("")
7✔
3313
            )).build());
1✔
3314

3315
    /**
3316
     * The NBT compound value
3317
     */
3318
    public static final IOperator NBT_COMPOUND_VALUE_COMPOUND = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3319
            .output(ValueTypes.NBT).operatorName("compound_value_compound").symbol("NBT{}.get_compound").interactName("getCompound")
9✔
3320
            .function(OperatorBuilders.FUNCTION_NBT_COMPOUND_ENTRY_TO_NBT.build(
2✔
3321
                    o -> o.map(tag -> tag instanceof CompoundTag ? (CompoundTag) tag : new CompoundTag())
11!
3322
            )).build());
1✔
3323

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

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

3346
    /**
3347
     * The NBT int list value
3348
     */
3349
    public static final IOperator NBT_COMPOUND_VALUE_LIST_INT = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3350
            .output(ValueTypes.LIST).operatorName("compound_value_list_int").symbol("NBT{}.get_list_int").interactName("getListInt")
8✔
3351
            .function(variables -> {
1✔
3352
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3353
                ValueTypeString.ValueString key = variables.getValue(1, ValueTypes.STRING);
6✔
3354
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtValueListInt(key.getRawValue(), value.getRawValue()));
9✔
3355
            }).build());
1✔
3356

3357
    /**
3358
     * The NBT long list value
3359
     */
3360
    public static final IOperator NBT_COMPOUND_VALUE_LIST_LONG = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3361
            .output(ValueTypes.LIST).operatorName("compound_value_list_long").symbol("NBT{}.get_list_long").interactName("getListLong")
8✔
3362
            .function(variables -> {
1✔
3363
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3364
                ValueTypeString.ValueString key = variables.getValue(1, ValueTypes.STRING);
6✔
3365
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtValueListLong(key.getRawValue(), value.getRawValue()));
9✔
3366
            }).build());
1✔
3367

3368
    /**
3369
     * Remove an entry from an NBT compound
3370
     */
3371
    public static final IOperator NBT_COMPOUND_WITHOUT = REGISTRY.register(OperatorBuilders.NBT_2
5✔
3372
            .output(ValueTypes.NBT).operatorName("compound_without").symbol("NBT{}.without").interactName("without")
8✔
3373
            .function(variables -> {
1✔
3374
                ValueTypeNbt.ValueNbt valueNbt = variables.getValue(0, ValueTypes.NBT);
6✔
3375
                Optional<Tag> tag = valueNbt.getRawValue();
3✔
3376
                if (tag.isPresent()) {
3!
3377
                    if (!(tag.get() instanceof CompoundTag)) {
4!
3378
                        return ValueTypeNbt.ValueNbt.of();
×
3379
                    }
3380
                    ValueTypeString.ValueString valueString = variables.getValue(1, ValueTypes.STRING);
6✔
3381
                    String key = valueString.getRawValue();
3✔
3382
                    CompoundTag tagCompound = (CompoundTag) tag.get();
4✔
3383
                    if (tagCompound.contains(key)) {
4!
3384
                        // Copy the tag to ensure immutability
3385
                        tagCompound = tagCompound.copy();
3✔
3386
                        tagCompound.remove(key);
3✔
3387
                    }
3388
                    return ValueTypeNbt.ValueNbt.of(tagCompound);
3✔
3389
                }
3390
                return valueNbt;
×
3391
            }).build());
1✔
3392

3393

3394

3395
    /**
3396
     * Set an NBT compound boolean value
3397
     */
3398
    public static final IOperator NBT_COMPOUND_WITH_BOOLEAN = REGISTRY.register(OperatorBuilders.NBT_3
5✔
3399
            .renderPattern(IConfigRenderPattern.INFIX_2_VERYLONG)
15✔
3400
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.BOOLEAN)
2✔
3401
            .operatorName("compound_with_boolean").symbol("NBT{}.with_boolean").interactName("withBoolean")
7✔
3402
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3403
                ValueTypeBoolean.ValueBoolean value = input.getRight().getValue(0, ValueTypes.BOOLEAN);
8✔
3404
                input.getLeft().ifPresent(tag -> tag.putBoolean(input.getMiddle(), value.getRawValue()));
15✔
3405
                return input.getLeft();
4✔
3406
            })).build());
1✔
3407

3408
    /**
3409
     * Set an NBT compound short value
3410
     */
3411
    public static final IOperator NBT_COMPOUND_WITH_SHORT = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3412
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.INTEGER)
2✔
3413
            .operatorName("compound_with_short").symbol("NBT{}.with_short").interactName("withShort")
7✔
3414
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3415
                ValueTypeInteger.ValueInteger value = input.getRight().getValue(0, ValueTypes.INTEGER);
8✔
3416
                input.getLeft().ifPresent(tag -> tag.putShort(input.getMiddle(), (short) value.getRawValue()));
16✔
3417
                return input.getLeft();
4✔
3418
            })).build());
1✔
3419

3420
    /**
3421
     * Set an NBT compound integer value
3422
     */
3423
    public static final IOperator NBT_COMPOUND_WITH_INTEGER = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3424
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.INTEGER)
2✔
3425
            .operatorName("compound_with_integer").symbol("NBT{}.with_integer").interactName("withInteger")
7✔
3426
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3427
                ValueTypeInteger.ValueInteger value = input.getRight().getValue(0, ValueTypes.INTEGER);
8✔
3428
                input.getLeft().ifPresent(tag -> tag.putInt(input.getMiddle(), value.getRawValue()));
15✔
3429
                return input.getLeft();
4✔
3430
            })).build());
1✔
3431

3432
    /**
3433
     * Set an NBT compound long value
3434
     */
3435
    public static final IOperator NBT_COMPOUND_WITH_LONG = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3436
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.LONG)
2✔
3437
            .operatorName("compound_with_long").symbol("NBT{}.with_long").interactName("withLong")
7✔
3438
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3439
                ValueTypeLong.ValueLong value = input.getRight().getValue(0, ValueTypes.LONG);
8✔
3440
                input.getLeft().ifPresent(tag -> tag.putLong(input.getMiddle(), value.getRawValue()));
15✔
3441
                return input.getLeft();
4✔
3442
            })).build());
1✔
3443

3444
    /**
3445
     * Set an NBT compound double value
3446
     */
3447
    public static final IOperator NBT_COMPOUND_WITH_DOUBLE = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3448
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.DOUBLE)
2✔
3449
            .operatorName("compound_with_double").symbol("NBT{}.with_double").interactName("withDouble")
7✔
3450
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3451
                ValueTypeDouble.ValueDouble value = input.getRight().getValue(0, ValueTypes.DOUBLE);
8✔
3452
                input.getLeft().ifPresent(tag -> tag.putDouble(input.getMiddle(), value.getRawValue()));
15✔
3453
                return input.getLeft();
4✔
3454
            })).build());
1✔
3455

3456
    /**
3457
     * Set an NBT compound float value
3458
     */
3459
    public static final IOperator NBT_COMPOUND_WITH_FLOAT = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3460
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.DOUBLE)
2✔
3461
            .operatorName("compound_with_float").symbol("NBT{}.with_float").interactName("withFloat")
7✔
3462
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3463
                ValueTypeDouble.ValueDouble value = input.getRight().getValue(0, ValueTypes.DOUBLE);
8✔
3464
                input.getLeft().ifPresent(tag -> tag.putFloat(input.getMiddle(), (float) value.getRawValue()));
16✔
3465
                return input.getLeft();
4✔
3466
            })).build());
1✔
3467

3468
    /**
3469
     * Set an NBT compound string value
3470
     */
3471
    public static final IOperator NBT_COMPOUND_WITH_STRING = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3472
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.STRING)
2✔
3473
            .operatorName("compound_with_string").symbol("NBT{}.with_string").interactName("withString")
7✔
3474
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3475
                ValueTypeString.ValueString value = input.getRight().getValue(0, ValueTypes.STRING);
8✔
3476
                input.getLeft().ifPresent(tag -> tag.putString(input.getMiddle(), value.getRawValue()));
15✔
3477
                return input.getLeft();
4✔
3478
            })).build());
1✔
3479

3480
    /**
3481
     * Set an NBT compound compound value
3482
     */
3483
    public static final IOperator NBT_COMPOUND_WITH_COMPOUND = REGISTRY.register(OperatorBuilders.NBT_3
18✔
3484
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.NBT)
2✔
3485
            .operatorName("compound_with_tag").symbol("NBT{}.with_tag").interactName("withTag")
7✔
3486
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(input -> {
2✔
3487
                ValueTypeNbt.ValueNbt value = input.getRight().getValue(0, ValueTypes.NBT);
8✔
3488
                input.getLeft()
6✔
3489
                        .ifPresent(tag -> value.getRawValue()
7✔
3490
                                .ifPresent(v -> tag.put(input.getMiddle(), v)));
9✔
3491
                return input.getLeft();
4✔
3492
            })).build());
1✔
3493

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

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

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

3545
    /**
3546
     * Set an NBT compound long list value
3547
     */
3548
    public static final IOperator NBT_COMPOUND_WITH_LIST_LONG = REGISTRY.register(OperatorBuilders.NBT_3
5✔
3549
            .renderPattern(IConfigRenderPattern.INFIX_2_VERYLONG)
15✔
3550
            .inputTypes(ValueTypes.NBT, ValueTypes.STRING, ValueTypes.LIST)
2✔
3551
            .operatorName("compound_with_list_long").symbol("NBT{}.with_list_long").interactName("withListLong")
9✔
3552
            .function(OperatorBuilders.FUNCTION_NBT_COPY_FOR_VALUE_TO_NBT.build(new IOperatorValuePropagator<Triple<Optional<CompoundTag>, String, OperatorBase.SafeVariablesGetter>, Optional<CompoundTag>>() {
5✔
3553
                @Override
3554
                public Optional<CompoundTag> getOutput(Triple<Optional<CompoundTag>, String, OperatorBase.SafeVariablesGetter> input) throws EvaluationException {
3555
                    ValueTypeList.ValueList<?, ?> value = input.getRight().getValue(0, ValueTypes.LIST);
8✔
3556
                    input.getLeft().ifPresent(tag -> tag.put(input.getMiddle(),
16✔
3557
                            NbtHelpers.getListNbtLong(value, NBT_COMPOUND_WITH_LIST_LONG.getLocalizedNameFull())));
2✔
3558
                    return input.getLeft();
4✔
3559
                }
3560
            })).build());
1✔
3561

3562
    /**
3563
     * Check if the first NBT compound tag is a subset of the second NBT compound tag.
3564
     */
3565
    public static final IOperator NBT_COMPOUND_SUBSET = REGISTRY.register(OperatorBuilders.NBT_2_NBT
5✔
3566
            .output(ValueTypes.BOOLEAN).operatorName("compound_subset").symbol("NBT{}.⊆").interactName("isSubset")
8✔
3567
            .function(variables -> {
1✔
3568
                ValueTypeNbt.ValueNbt valueNbt0 = variables.getValue(0, ValueTypes.NBT);
6✔
3569
                ValueTypeNbt.ValueNbt valueNbt1 = variables.getValue(1, ValueTypes.NBT);
6✔
3570
                if (valueNbt0.getRawValue().isPresent()
5!
3571
                        && valueNbt1.getRawValue().isPresent()
4!
3572
                        && valueNbt0.getRawValue().get() instanceof CompoundTag
5!
3573
                        && valueNbt1.getRawValue().get() instanceof CompoundTag) {
4!
3574
                    return ValueTypeBoolean.ValueBoolean.of(NbtHelpers.nbtMatchesSubset((CompoundTag) valueNbt0.getRawValue().get(), (CompoundTag) valueNbt1.getRawValue().get(), true));
12✔
3575
                }
3576
                return ValueTypeBoolean.ValueBoolean.of(false);
×
3577
            }).build());
1✔
3578

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

3596
    /**
3597
     * The intersection of the given NBT compound tags. Nested tags will be intersected recusively.
3598
     */
3599
    public static final IOperator NBT_COMPOUND_INTERSECTION = REGISTRY.register(OperatorBuilders.NBT_2_NBT
5✔
3600
            .output(ValueTypes.NBT).operatorName("compound_intersection").symbol("NBT{}.∩").interactName("intersection")
8✔
3601
            .function(variables -> {
1✔
3602
                ValueTypeNbt.ValueNbt valueNbt0 = variables.getValue(0, ValueTypes.NBT);
6✔
3603
                ValueTypeNbt.ValueNbt valueNbt1 = variables.getValue(1, ValueTypes.NBT);
6✔
3604
                if (valueNbt0.getRawValue().isPresent()
5!
3605
                        && valueNbt1.getRawValue().isPresent()
4!
3606
                        && valueNbt0.getRawValue().get() instanceof CompoundTag
5!
3607
                        && valueNbt1.getRawValue().get() instanceof CompoundTag) {
4!
3608
                    return ValueTypeNbt.ValueNbt.of(NbtHelpers.intersection((CompoundTag) valueNbt0.getRawValue().get(), (CompoundTag) valueNbt1.getRawValue().get()));
19✔
3609
                }
3610
                return ValueTypeNbt.ValueNbt.of();
×
3611
            }).build());
1✔
3612

3613
    /**
3614
     * The difference of the given NBT compound tags. Nested tags will be subtracted recusively.
3615
     */
3616
    public static final IOperator NBT_COMPOUND_MINUS = REGISTRY.register(OperatorBuilders.NBT_2_NBT
5✔
3617
            .output(ValueTypes.NBT).operatorName("compound_minus").symbol("NBT{}.∖").interactName("minus")
8✔
3618
            .function(variables -> {
1✔
3619
                ValueTypeNbt.ValueNbt valueNbt0 = variables.getValue(0, ValueTypes.NBT);
6✔
3620
                ValueTypeNbt.ValueNbt valueNbt1 = variables.getValue(1, ValueTypes.NBT);
6✔
3621
                if (valueNbt0.getRawValue().isPresent()
5!
3622
                        && valueNbt1.getRawValue().isPresent()
4!
3623
                        && valueNbt0.getRawValue().get() instanceof CompoundTag
5!
3624
                        && valueNbt1.getRawValue().get() instanceof CompoundTag) {
4!
3625
                    return ValueTypeNbt.ValueNbt.of(NbtHelpers.minus((CompoundTag) valueNbt0.getRawValue().get(), (CompoundTag) valueNbt1.getRawValue().get()));
11✔
3626
                }
3627
                return ValueTypeNbt.ValueNbt.of();
×
3628
            }).build());
1✔
3629

3630
    /**
3631
     * The boolean value of an NBT value
3632
     */
3633
    public static final IOperator NBT_AS_BOOLEAN = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3634
            .output(ValueTypes.BOOLEAN).operatorName("as_boolean").symbol("NBT.as_boolean").interactName("asBoolean")
9✔
3635
            .function(OperatorBuilders.FUNCTION_NBT_TO_BOOLEAN.build(
2✔
3636
                    o -> o.flatMap(Tag::asBoolean).orElse(false)
8✔
3637
            )).build());
1✔
3638

3639
    /**
3640
     * The byte value of an NBT value
3641
     */
3642
    public static final IOperator NBT_AS_BYTE = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3643
            .output(ValueTypes.INTEGER).operatorName("as_byte").symbol("NBT.as_byte").interactName("asByte")
9✔
3644
            .function(OperatorBuilders.FUNCTION_NBT_TO_INT.build(
2✔
3645
                    o -> o.flatMap(Tag::asByte).map(s -> (int) s).orElse(0)
14✔
3646
            )).build());
1✔
3647

3648
    /**
3649
     * The short value of an NBT value
3650
     */
3651
    public static final IOperator NBT_AS_SHORT = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3652
            .output(ValueTypes.INTEGER).operatorName("as_short").symbol("NBT.as_short").interactName("asShort")
9✔
3653
            .function(OperatorBuilders.FUNCTION_NBT_TO_INT.build(
2✔
3654
                    o -> o.flatMap(Tag::asShort).map(s -> (int) s).orElse(0)
14✔
3655
            )).build());
1✔
3656

3657
    /**
3658
     * The int value of an NBT value
3659
     */
3660
    public static final IOperator NBT_AS_INT = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3661
            .output(ValueTypes.INTEGER).operatorName("as_int").symbol("NBT.as_int").interactName("asInt")
9✔
3662
            .function(OperatorBuilders.FUNCTION_NBT_TO_INT.build(
2✔
3663
                    o -> o.flatMap(Tag::asInt).orElse(0)
8✔
3664
            )).build());
1✔
3665

3666
    /**
3667
     * The long value of an NBT value
3668
     */
3669
    public static final IOperator NBT_AS_LONG = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3670
            .output(ValueTypes.LONG).operatorName("as_long").symbol("NBT.as_long").interactName("asLong")
9✔
3671
            .function(OperatorBuilders.FUNCTION_NBT_TO_LONG.build(
2✔
3672
                    o -> o.flatMap(Tag::asLong).orElse(0L)
8✔
3673
            )).build());
1✔
3674

3675
    /**
3676
     * The double value of an NBT value
3677
     */
3678
    public static final IOperator NBT_AS_DOUBLE = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3679
            .output(ValueTypes.DOUBLE).operatorName("as_double").symbol("NBT.as_double").interactName("asDouble")
9✔
3680
            .function(OperatorBuilders.FUNCTION_NBT_TO_DOUBLE.build(
2✔
3681
                    o -> o.flatMap(Tag::asDouble).orElse(0D)
8✔
3682
            )).build());
1✔
3683

3684
    /**
3685
     * The float value of an NBT value
3686
     */
3687
    public static final IOperator NBT_AS_FLOAT = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3688
            .output(ValueTypes.DOUBLE).operatorName("as_float").symbol("NBT.as_float").interactName("asFloat")
9✔
3689
            .function(OperatorBuilders.FUNCTION_NBT_TO_DOUBLE.build(
2✔
3690
                    o -> o.flatMap(Tag::asFloat).map(f -> (double) f).orElse(0D)
15✔
3691
            )).build());
1✔
3692

3693
    /**
3694
     * The string value of an NBT value
3695
     */
3696
    public static final IOperator NBT_AS_STRING = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3697
            .output(ValueTypes.STRING).operatorName("as_string").symbol("NBT.as_string").interactName("asString")
9✔
3698
            .function(OperatorBuilders.FUNCTION_NBT_TO_STRING.build(
2✔
3699
                    o -> o.flatMap(Tag::asString).orElse("")
7✔
3700
            )).build());
1✔
3701

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

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

3722
    /**
3723
     * The int list value of an NBT value
3724
     */
3725
    public static final IOperator NBT_AS_INT_LIST = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3726
            .output(ValueTypes.LIST).operatorName("as_int_list").symbol("NBT.as_int_list").interactName("asIntList")
8✔
3727
            .function(variables -> {
1✔
3728
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3729
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtAsListInt(value.getRawValue()));
7✔
3730
            }).build());
1✔
3731

3732
    /**
3733
     * The long list value of an NBT value
3734
     */
3735
    public static final IOperator NBT_AS_LONG_LIST = REGISTRY.register(OperatorBuilders.NBT_1_SUFFIX_LONG
5✔
3736
            .output(ValueTypes.LIST).operatorName("as_long_list").symbol("NBT.as_long_list").interactName("asLongList")
8✔
3737
            .function(variables -> {
1✔
3738
                ValueTypeNbt.ValueNbt value = variables.getValue(0, ValueTypes.NBT);
6✔
3739
                return ValueTypeList.ValueList.ofFactory(new ValueTypeListProxyNbtAsListLong(value.getRawValue()));
7✔
3740
            }).build());
1✔
3741

3742
    /**
3743
     * The NBT value of a boolean value
3744
     */
3745
    public static final IOperator NBT_FROM_BOOLEAN = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3746
            .inputType(ValueTypes.BOOLEAN).output(ValueTypes.NBT)
4✔
3747
            .operatorName("from_boolean").symbol("NBT.from_boolean").interactName("asNbt")
6✔
3748
            .function(variables -> {
1✔
3749
                ValueTypeBoolean.ValueBoolean value = variables.getValue(0, ValueTypes.BOOLEAN);
6✔
3750
                return ValueTypeNbt.ValueNbt.of(ByteTag.valueOf(value.getRawValue()));
5✔
3751
            }).build());
1✔
3752

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

3764
    /**
3765
     * The NBT value of a byte value
3766
     */
3767
    public static final IOperator NBT_FROM_BYTE = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3768
            .inputType(ValueTypes.INTEGER).output(ValueTypes.NBT)
4✔
3769
            .operatorName("from_byte").symbol("NBT.from_byte").interactName("asNbt", "byte", true)
8✔
3770
            .function(variables -> {
1✔
3771
                ValueTypeInteger.ValueInteger value = variables.getValue(0, ValueTypes.INTEGER);
6✔
3772
                return ValueTypeNbt.ValueNbt.of(ByteTag.valueOf((byte) value.getRawValue()));
6✔
3773
            }).build());
1✔
3774

3775
    /**
3776
     * The NBT value of an int value
3777
     */
3778
    public static final IOperator NBT_FROM_INT = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3779
            .inputType(ValueTypes.INTEGER).output(ValueTypes.NBT)
4✔
3780
            .operatorName("from_int").symbol("NBT.from_int").interactName("asNbt")
6✔
3781
            .function(variables -> {
1✔
3782
                ValueTypeInteger.ValueInteger value = variables.getValue(0, ValueTypes.INTEGER);
6✔
3783
                return ValueTypeNbt.ValueNbt.of(IntTag.valueOf(value.getRawValue()));
5✔
3784
            }).build());
1✔
3785

3786
    /**
3787
     * The NBT value of a long value
3788
     */
3789
    public static final IOperator NBT_FROM_LONG = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3790
            .inputType(ValueTypes.LONG).output(ValueTypes.NBT)
4✔
3791
            .operatorName("from_long").symbol("NBT.from_long").interactName("asNbt")
6✔
3792
            .function(variables -> {
1✔
3793
                ValueTypeLong.ValueLong value = variables.getValue(0, ValueTypes.LONG);
6✔
3794
                return ValueTypeNbt.ValueNbt.of(LongTag.valueOf(value.getRawValue()));
5✔
3795
            }).build());
1✔
3796

3797
    /**
3798
     * The NBT value of a double value
3799
     */
3800
    public static final IOperator NBT_FROM_DOUBLE = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3801
            .inputType(ValueTypes.DOUBLE).output(ValueTypes.NBT)
4✔
3802
            .operatorName("from_double").symbol("NBT.from_double").interactName("asNbt")
6✔
3803
            .function(variables -> {
1✔
3804
                ValueTypeDouble.ValueDouble value = variables.getValue(0, ValueTypes.DOUBLE);
6✔
3805
                return ValueTypeNbt.ValueNbt.of(DoubleTag.valueOf(value.getRawValue()));
5✔
3806
            }).build());
1✔
3807

3808
    /**
3809
     * The NBT value of a float value
3810
     */
3811
    public static final IOperator NBT_FROM_FLOAT = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3812
            .inputType(ValueTypes.DOUBLE).output(ValueTypes.NBT)
4✔
3813
            .operatorName("from_float").symbol("NBT.from_float").interactName("asNbt", "float", true)
8✔
3814
            .function(variables -> {
1✔
3815
                ValueTypeDouble.ValueDouble value = variables.getValue(0, ValueTypes.DOUBLE);
6✔
3816
                return ValueTypeNbt.ValueNbt.of(FloatTag.valueOf((float) value.getRawValue()));
6✔
3817
            }).build());
1✔
3818

3819
    /**
3820
     * The NBT value of a string value
3821
     */
3822
    public static final IOperator NBT_FROM_STRING = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3823
            .inputType(ValueTypes.STRING).output(ValueTypes.NBT)
4✔
3824
            .operatorName("from_string").symbol("NBT.from_string").interactName("asNbt")
6✔
3825
            .function(variables -> {
1✔
3826
                ValueTypeString.ValueString value = variables.getValue(0, ValueTypes.STRING);
6✔
3827
                return ValueTypeNbt.ValueNbt.of(StringTag.valueOf(value.getRawValue()));
5✔
3828
            }).build());
1✔
3829

3830
    /**
3831
     * The NBT value of a tag list value
3832
     */
3833
    public static final IOperator NBT_FROM_TAG_LIST = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3834
            .inputType(ValueTypes.LIST).output(ValueTypes.NBT)
4✔
3835
            .operatorName("from_tag_list").symbol("NBT.from_tag_list").interactName("asNbt", "tagList", true)
10✔
3836
            .function(new OperatorBase.IFunction() {
4✔
3837
                @Override
3838
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
3839
                    ValueTypeList.ValueList value = variables.getValue(0, ValueTypes.LIST);
6✔
3840
                    return ValueTypeNbt.ValueNbt.of(NbtHelpers.getListNbtTag(value, NBT_FROM_TAG_LIST.getLocalizedNameFull()));
6✔
3841
                }
3842
            }).build());
1✔
3843

3844
    /**
3845
     * The NBT value of a byte list value
3846
     */
3847
    public static final IOperator NBT_FROM_BYTE_LIST = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3848
            .inputType(ValueTypes.LIST).output(ValueTypes.NBT)
4✔
3849
            .operatorName("from_byte_list").symbol("NBT.from_byte_list").interactName("asNbt", "byteList", true)
10✔
3850
            .function(new OperatorBase.IFunction() {
4✔
3851
                @Override
3852
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
3853
                    ValueTypeList.ValueList value = variables.getValue(0, ValueTypes.LIST);
6✔
3854
                    return ValueTypeNbt.ValueNbt.of(NbtHelpers.getListNbtByte(value, NBT_FROM_BYTE_LIST.getLocalizedNameFull()));
6✔
3855
                }
3856
            }).build());
1✔
3857

3858
    /**
3859
     * The NBT value of a int list value
3860
     */
3861
    public static final IOperator NBT_FROM_INT_LIST = REGISTRY.register(OperatorBuilders.NBT_1_PREFIX_LONG
5✔
3862
            .inputType(ValueTypes.LIST).output(ValueTypes.NBT)
4✔
3863
            .operatorName("from_int_list").symbol("NBT.from_int_list").interactName("asNbt", "intList", true)
10✔
3864
            .function(new OperatorBase.IFunction() {
4✔
3865
                @Override
3866
                public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws EvaluationException {
3867
                    ValueTypeList.ValueList value = variables.getValue(0, ValueTypes.LIST);
6✔
3868
                    return ValueTypeNbt.ValueNbt.of(NbtHelpers.getListNbtInt(value, NBT_FROM_INT_LIST.getLocalizedNameFull()));
6✔
3869
                }
3870
            }).build());
1✔
3871

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

3886
    /**
3887
     * Apply the given NBT path expression on the given NBT value and get the first result.
3888
     */
3889
    public static final IOperator NBT_PATH_MATCH_FIRST = REGISTRY.register(OperatorBuilders.NBT_2
14✔
3890
            .inputTypes(ValueTypes.STRING, ValueTypes.NBT).output(ValueTypes.NBT)
4✔
3891
            .operatorName("path_match_first").symbol("NBT.path_match_first").interactName("nbtPathMatchFirst")
6✔
3892
            .function(variables -> {
1✔
3893
                ValueTypeString.ValueString string = variables.getValue(0, ValueTypes.STRING);
6✔
3894
                ValueTypeNbt.ValueNbt nbt = variables.getValue(1, ValueTypes.NBT);
6✔
3895
                INbtPathExpression expression = null;
2✔
3896
                try {
3897
                    expression = NbtPath.parse(string.getRawValue());
4✔
3898
                } catch (NbtParseException e) {
×
3899
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_NBT_PATH_EXPRESSION,
×
3900
                            string.getRawValue(),
×
3901
                            e.getMessage()));
×
3902
                }
1✔
3903
                if (!nbt.getRawValue().isPresent()) {
4!
3904
                    return ValueTypeNbt.ValueNbt.of();
×
3905
                }
3906
                return ValueTypeNbt.ValueNbt.of(expression.match(nbt.getRawValue().get()).getMatches().findAny());
10✔
3907
            }).build());
1✔
3908

3909
    /**
3910
     * Apply the given NBT path expression on the given NBT value and get all results.
3911
     */
3912
    public static final IOperator NBT_PATH_MATCH_ALL = REGISTRY.register(OperatorBuilders.NBT_2
14✔
3913
            .inputTypes(ValueTypes.STRING, ValueTypes.NBT).output(ValueTypes.LIST)
4✔
3914
            .operatorName("path_match_all").symbol("NBT.path_match_all").interactName("nbtPathMatchAll")
6✔
3915
            .function(variables -> {
1✔
3916
                ValueTypeString.ValueString string = variables.getValue(0, ValueTypes.STRING);
6✔
3917
                ValueTypeNbt.ValueNbt nbt = variables.getValue(1, ValueTypes.NBT);
6✔
3918
                INbtPathExpression expression = null;
2✔
3919
                try {
3920
                    expression = NbtPath.parse(string.getRawValue());
4✔
3921
                } catch (NbtParseException e) {
×
3922
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_NBT_PATH_EXPRESSION,
×
3923
                            string.getRawValue(),
×
3924
                            e.getMessage()));
×
3925
                }
1✔
3926
                if (!nbt.getRawValue().isPresent()) {
4!
3927
                    return ValueTypeList.ValueList.ofAll(ValueTypes.NBT);
×
3928
                }
3929
                List<ValueTypeNbt.ValueNbt> matches = expression.match(nbt.getRawValue().get()).getMatches()
8✔
3930
                        .map(ValueTypeNbt.ValueNbt::of)
1✔
3931
                        .collect(Collectors.toList());
4✔
3932
                return ValueTypeList.ValueList.ofList(ValueTypes.NBT, matches);
4✔
3933
            }).build());
1✔
3934

3935
    /**
3936
     * Test the given NBT path expression on the given NBT value.
3937
     */
3938
    public static final IOperator NBT_PATH_TEST = REGISTRY.register(OperatorBuilders.NBT_2
14✔
3939
            .inputTypes(ValueTypes.STRING, ValueTypes.NBT).output(ValueTypes.BOOLEAN)
4✔
3940
            .operatorName("path_test").symbol("NBT.path_test").interactName("nbtPathTest")
6✔
3941
            .function(variables -> {
1✔
3942
                ValueTypeString.ValueString string = variables.getValue(0, ValueTypes.STRING);
6✔
3943
                ValueTypeNbt.ValueNbt nbt = variables.getValue(1, ValueTypes.NBT);
6✔
3944
                INbtPathExpression expression = null;
2✔
3945
                try {
3946
                    expression = NbtPath.parse(string.getRawValue());
4✔
3947
                } catch (NbtParseException e) {
×
3948
                    throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_NBT_PATH_EXPRESSION,
×
3949
                            string.getRawValue(),
×
3950
                            e.getMessage()));
×
3951
                }
1✔
3952
                if (!nbt.getRawValue().isPresent()) {
4!
3953
                    return ValueTypeBoolean.ValueBoolean.of(false);
×
3954
                }
3955
                return ValueTypeBoolean.ValueBoolean.of(expression.test(nbt.getRawValue().get()));
8✔
3956
            }).build());
1✔
3957

3958
    /**
3959
     * ----------------------------------- INGREDIENTS OPERATORS -----------------------------------
3960
     */
3961

3962
    /**
3963
     * The list of items.
3964
     */
3965
    public static final IOperator INGREDIENTS_ITEMS = REGISTRY.register(OperatorBuilders.INGREDIENTS_1_PREFIX_LONG
5✔
3966
            .output(ValueTypes.LIST).operatorInteract("items").symbol("Ingr.items")
6✔
3967
            .function(OperatorBuilders.createFunctionIngredientsList(() -> IngredientComponent.ITEMSTACK))
2✔
3968
            .build());
1✔
3969

3970
    /**
3971
     * The list of fluids
3972
     */
3973
    public static final IOperator INGREDIENTS_FLUIDS = REGISTRY.register(OperatorBuilders.INGREDIENTS_1_PREFIX_LONG
5✔
3974
            .output(ValueTypes.LIST).operatorInteract("fluids").symbol("Ingr.fluids")
6✔
3975
            .function(OperatorBuilders.createFunctionIngredientsList(() -> IngredientComponent.FLUIDSTACK))
2✔
3976
            .build());
1✔
3977

3978
    /**
3979
     * The list of fluids
3980
     */
3981
    public static final IOperator INGREDIENTS_ENERGIES = REGISTRY.register(OperatorBuilders.INGREDIENTS_1_PREFIX_LONG
5✔
3982
            .output(ValueTypes.LIST).operatorInteract("energies").symbol("Ingr.energies")
6✔
3983
            .function(OperatorBuilders.createFunctionIngredientsList(() -> IngredientComponent.ENERGY))
2✔
3984
            .build());
1✔
3985

3986
    /**
3987
     * Set an ingredient item
3988
     */
3989
    public static final IOperator INGREDIENTS_WITH_ITEM = REGISTRY.register(OperatorBuilders.INGREDIENTS_3_ITEMSTACK
5✔
3990
            .operatorName("with_item").symbol("Ingr.with_item").interactName("withItem")
6✔
3991
            .function(variables -> {
1✔
3992
                ValueObjectTypeIngredients.ValueIngredients value = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
×
3993
                ValueTypeInteger.ValueInteger index = variables.getValue(1, ValueTypes.INTEGER);
×
3994
                ValueObjectTypeItemStack.ValueItemStack itemStack = variables.getValue(2, ValueTypes.OBJECT_ITEMSTACK);
×
3995
                if (value.getRawValue().isEmpty()) {
×
3996
                    value = ValueObjectTypeIngredients.ValueIngredients.of(new MixedIngredients(Maps.newIdentityHashMap()));
×
3997
                }
3998
                IMixedIngredients baseIngredients = value.getRawValue().get();
×
3999
                return ValueObjectTypeIngredients.ValueIngredients.of(new ExtendedIngredientsSingle<>(baseIngredients,
×
4000
                        index.getRawValue(), IngredientComponent.ITEMSTACK, itemStack.getRawValue()));
×
4001
            }).build());
1✔
4002

4003
    /**
4004
     * Set an ingredient fluid
4005
     */
4006
    public static final IOperator INGREDIENTS_WITH_FLUID = REGISTRY.register(OperatorBuilders.INGREDIENTS_3_FLUIDSTACK
5✔
4007
            .operatorName("with_fluid").symbol("Ingr.with_fluid").interactName("withFluid")
6✔
4008
            .function(variables -> {
1✔
4009
                ValueObjectTypeIngredients.ValueIngredients value = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
×
4010
                ValueTypeInteger.ValueInteger index = variables.getValue(1, ValueTypes.INTEGER);
×
4011
                ValueObjectTypeFluidStack.ValueFluidStack fluidStack = variables.getValue(2, ValueTypes.OBJECT_FLUIDSTACK);
×
4012
                if (value.getRawValue().isEmpty()) {
×
4013
                    value = ValueObjectTypeIngredients.ValueIngredients.of(new MixedIngredients(Maps.newIdentityHashMap()));
×
4014
                }
4015
                IMixedIngredients baseIngredients = value.getRawValue().get();
×
4016
                return ValueObjectTypeIngredients.ValueIngredients.of(new ExtendedIngredientsSingle<>(baseIngredients,
×
4017
                        index.getRawValue(), IngredientComponent.FLUIDSTACK, fluidStack.getRawValue()));
×
4018
            }).build());
1✔
4019

4020
    /**
4021
     * Set an ingredient energy
4022
     */
4023
    public static final IOperator INGREDIENTS_WITH_ENERGY = REGISTRY.register(OperatorBuilders.INGREDIENTS_3_LONG
5✔
4024
            .operatorName("with_energy").symbol("Ingr.with_energy").interactName("withEnergy")
6✔
4025
            .function(variables -> {
1✔
4026
                ValueObjectTypeIngredients.ValueIngredients value = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
×
4027
                ValueTypeInteger.ValueInteger index = variables.getValue(1, ValueTypes.INTEGER);
×
4028
                ValueTypeLong.ValueLong energy = variables.getValue(2, ValueTypes.LONG);
×
4029
                if (value.getRawValue().isEmpty()) {
×
4030
                    value = ValueObjectTypeIngredients.ValueIngredients.of(new MixedIngredients(Maps.newIdentityHashMap()));
×
4031
                }
4032
                IMixedIngredients baseIngredients = value.getRawValue().get();
×
4033
                return ValueObjectTypeIngredients.ValueIngredients.of(new ExtendedIngredientsSingle<>(baseIngredients,
×
4034
                        index.getRawValue(), IngredientComponent.ENERGY, energy.getRawValue()));
×
4035
            }).build());
1✔
4036

4037
    /**
4038
     * Set the list of items
4039
     */
4040
    public static final IOperator INGREDIENTS_WITH_ITEMS = REGISTRY.register(OperatorBuilders.INGREDIENTS_2_LIST
5✔
4041
            .operatorName("with_items").symbol("Ingr.with_items").interactName("withItems")
6✔
4042
            .function(variables -> {
1✔
4043
                ValueObjectTypeIngredients.ValueIngredients valueIngredients = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
×
4044
                ValueTypeList.ValueList<ValueObjectTypeItemStack, ValueObjectTypeItemStack.ValueItemStack> list = variables.getValue(1, ValueTypes.LIST);
×
4045
                if (valueIngredients.getRawValue().isEmpty()) {
×
4046
                    valueIngredients = ValueObjectTypeIngredients.ValueIngredients.of(new MixedIngredients(Maps.newIdentityHashMap()));
×
4047
                }
4048
                IMixedIngredients baseIngredients = valueIngredients.getRawValue().get();
×
4049
                return ValueObjectTypeIngredients.ValueIngredients.of(new ExtendedIngredientsList<>(baseIngredients,
×
4050
                        IngredientComponent.ITEMSTACK, OperatorBuilders.unwrapIngredientComponentList(IngredientComponent.ITEMSTACK, list)));
×
4051
            }).build());
1✔
4052

4053
    /**
4054
     * Set the list of fluids
4055
     */
4056
    public static final IOperator INGREDIENTS_WITH_FLUIDS = REGISTRY.register(OperatorBuilders.INGREDIENTS_2_LIST
5✔
4057
            .operatorName("with_fluids").symbol("Ingr.with_fluids").interactName("withFluids")
6✔
4058
            .function(variables -> {
1✔
4059
                ValueObjectTypeIngredients.ValueIngredients valueIngredients = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
×
4060
                ValueTypeList.ValueList<ValueObjectTypeFluidStack, ValueObjectTypeFluidStack.ValueFluidStack> list = variables.getValue(1, ValueTypes.LIST);
×
4061
                if (valueIngredients.getRawValue().isEmpty()) {
×
4062
                    valueIngredients = ValueObjectTypeIngredients.ValueIngredients.of(new MixedIngredients(Maps.newIdentityHashMap()));
×
4063
                }
4064
                IMixedIngredients baseIngredients = valueIngredients.getRawValue().get();
×
4065
                return ValueObjectTypeIngredients.ValueIngredients.of(new ExtendedIngredientsList<>(baseIngredients,
×
4066
                        IngredientComponent.FLUIDSTACK, OperatorBuilders.unwrapIngredientComponentList(IngredientComponent.FLUIDSTACK, list)));
×
4067
            }).build());
1✔
4068

4069
    /**
4070
     * Set the list of energies
4071
     */
4072
    public static final IOperator INGREDIENTS_WITH_ENERGIES = REGISTRY.register(OperatorBuilders.INGREDIENTS_2_LIST
5✔
4073
            .renderPattern(IConfigRenderPattern.INFIX_VERYLONG)
2✔
4074
            .operatorName("with_energies").symbol("Ingr.with_energies").interactName("withEnergies")
6✔
4075
            .function(variables -> {
1✔
4076
                ValueObjectTypeIngredients.ValueIngredients valueIngredients = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
×
4077
                ValueTypeList.ValueList<ValueTypeInteger, ValueTypeInteger.ValueInteger> list = variables.getValue(1, ValueTypes.LIST);
×
4078
                if (valueIngredients.getRawValue().isEmpty()) {
×
4079
                    valueIngredients = ValueObjectTypeIngredients.ValueIngredients.of(new MixedIngredients(Maps.newIdentityHashMap()));
×
4080
                }
4081
                IMixedIngredients baseIngredients = valueIngredients.getRawValue().get();
×
4082
                return ValueObjectTypeIngredients.ValueIngredients.of(new ExtendedIngredientsList<>(baseIngredients,
×
4083
                        IngredientComponent.ENERGY, OperatorBuilders.unwrapIngredientComponentList(IngredientComponent.ENERGY, list)));
×
4084
            }).build());
1✔
4085

4086
    /**
4087
     * ----------------------------------- RECIPE OPERATORS -----------------------------------
4088
     */
4089

4090
    /**
4091
     * The input ingredients of a recipe
4092
     */
4093
    public static final IOperator RECIPE_INPUT = REGISTRY.register(OperatorBuilders.RECIPE_1_SUFFIX_LONG
5✔
4094
            .output(ValueTypes.OBJECT_INGREDIENTS)
2✔
4095
            .operatorInteract("input").symbol("recipe_in")
4✔
4096
            .function(variables -> {
1✔
4097
                ValueObjectTypeRecipe.ValueRecipe value = variables.getValue(0, ValueTypes.OBJECT_RECIPE);
×
4098
                if (value.getRawValue().isPresent()) {
×
4099
                    return ValueObjectTypeIngredients.ValueIngredients.of(MixedIngredients.fromRecipeInput(value.getRawValue().get()));
×
4100
                }
4101
                return ValueObjectTypeIngredients.ValueIngredients.of(null);
×
4102
            }).build());
1✔
4103

4104
    /**
4105
     * The output ingredients of a recipe
4106
     */
4107
    public static final IOperator RECIPE_OUTPUT = REGISTRY.register(OperatorBuilders.RECIPE_1_SUFFIX_LONG
5✔
4108
            .output(ValueTypes.OBJECT_INGREDIENTS)
2✔
4109
            .operatorInteract("output").symbol("recipe_out")
4✔
4110
            .function(variables -> {
1✔
4111
                ValueObjectTypeRecipe.ValueRecipe value = variables.getValue(0, ValueTypes.OBJECT_RECIPE);
×
4112
                if (value.getRawValue().isPresent()) {
×
4113
                    return ValueObjectTypeIngredients.ValueIngredients.of(value.getRawValue().get().getOutput());
×
4114
                }
4115
                return ValueObjectTypeIngredients.ValueIngredients.of(null);
×
4116
            }).build());
1✔
4117

4118
    /**
4119
     * Set the input ingredients of a recipe
4120
     */
4121
    public static final IOperator RECIPE_WITH_INPUT = REGISTRY.register(OperatorBuilders.RECIPE_2_INFIX
5✔
4122
            .output(ValueTypes.OBJECT_RECIPE)
2✔
4123
            .operatorName("with_input").symbol("Recipe.with_in").interactName("withInput")
6✔
4124
            .function(variables -> {
1✔
4125
                ValueObjectTypeRecipe.ValueRecipe valueRecipe = variables.getValue(0, ValueTypes.OBJECT_RECIPE);
×
4126
                ValueObjectTypeIngredients.ValueIngredients valueIngredients = variables.getValue(1, ValueTypes.OBJECT_INGREDIENTS);
×
4127
                if (valueRecipe.getRawValue().isPresent() && valueIngredients.getRawValue().isPresent()) {
×
4128
                    IMixedIngredients ingredients = valueIngredients.getRawValue().get();
×
4129
                    Map<IngredientComponent<?, ?>, List<IPrototypedIngredientAlternatives<?, ?>>> inputs = Maps.newIdentityHashMap();
×
4130
                    for (IngredientComponent<?, ?> component : ingredients.getComponents()) {
×
4131
                        IIngredientMatcher matcher = component.getMatcher();
×
4132
                        inputs.put(component, (List) ingredients.getInstances(component)
×
4133
                                .stream()
×
4134
                                .map(instance -> new PrototypedIngredientAlternativesList(Collections.singletonList(new PrototypedIngredient(component, instance, matcher.getExactMatchCondition()))))
×
4135
                                .collect(Collectors.toList()));
×
4136
                    }
×
4137
                    return ValueObjectTypeRecipe.ValueRecipe.of(new RecipeDefinition(
×
4138
                            inputs,
4139
                            valueRecipe.getRawValue().get().getOutput()
×
4140
                    ));
4141
                }
4142
                return ValueObjectTypeRecipe.ValueRecipe.of(null);
×
4143
            }).build());
1✔
4144

4145
    /**
4146
     * Set the output ingredients of a recipe
4147
     */
4148
    public static final IOperator RECIPE_WITH_OUTPUT = REGISTRY.register(OperatorBuilders.RECIPE_2_INFIX
5✔
4149
            .output(ValueTypes.OBJECT_RECIPE)
2✔
4150
            .operatorName("with_output").symbol("Recipe.with_out").interactName("withOutput")
6✔
4151
            .function(variables -> {
1✔
4152
                ValueObjectTypeRecipe.ValueRecipe valueRecipe = variables.getValue(0, ValueTypes.OBJECT_RECIPE);
×
4153
                ValueObjectTypeIngredients.ValueIngredients valueIngredients = variables.getValue(1, ValueTypes.OBJECT_INGREDIENTS);
×
4154
                if (valueRecipe.getRawValue().isPresent() && valueIngredients.getRawValue().isPresent()) {
×
4155
                    IRecipeDefinition recipe = valueRecipe.getRawValue().get();
×
4156
                    Map<IngredientComponent<?, ?>, List<IPrototypedIngredientAlternatives<?, ?>>> inputs = Maps.newIdentityHashMap();
×
4157
                    for (IngredientComponent<?, ?> component : recipe.getInputComponents()) {
×
4158
                        inputs.put(component, (List) recipe.getInputs(component));
×
4159
                    }
×
4160
                    return ValueObjectTypeRecipe.ValueRecipe.of(new RecipeDefinition(
×
4161
                            inputs,
4162
                            valueIngredients.getRawValue().get()
×
4163
                    ));
4164
                }
4165
                return ValueObjectTypeRecipe.ValueRecipe.of(null);
×
4166
            }).build());
1✔
4167

4168
    /**
4169
     * Create a recipe from two the given I/O ingredients
4170
     */
4171
    public static final IOperator RECIPE_WITH_INPUT_OUTPUT = REGISTRY.register(OperatorBuilders.RECIPE_2_PREFIX
5✔
4172
            .output(ValueTypes.OBJECT_RECIPE)
2✔
4173
            .operatorName("with_input_output").symbol("Recipe.with_io").interactName("withInputOutput")
6✔
4174
            .function(variables -> {
1✔
4175
                ValueObjectTypeIngredients.ValueIngredients valueIn = variables.getValue(0, ValueTypes.OBJECT_INGREDIENTS);
×
4176
                ValueObjectTypeIngredients.ValueIngredients valueOut = variables.getValue(1, ValueTypes.OBJECT_INGREDIENTS);
×
4177
                if (valueIn.getRawValue().isPresent() && valueOut.getRawValue().isPresent()) {
×
4178
                    IMixedIngredients ingredients = valueIn.getRawValue().get();
×
4179
                    Map<IngredientComponent<?, ?>, List<IPrototypedIngredientAlternatives<?, ?>>> inputs = Maps.newIdentityHashMap();
×
4180
                    for (IngredientComponent<?, ?> component : ingredients.getComponents()) {
×
4181
                        IIngredientMatcher matcher = component.getMatcher();
×
4182
                        inputs.put(component, (List) ingredients.getInstances(component)
×
4183
                                .stream()
×
4184
                                .map(instance -> new PrototypedIngredientAlternativesList(Collections.singletonList(new PrototypedIngredient(component, instance, matcher.getExactMatchCondition()))))
×
4185
                                .collect(Collectors.toList()));
×
4186
                    }
×
4187
                    try {
4188
                        return ValueObjectTypeRecipe.ValueRecipe.of(new RecipeDefinition(
×
4189
                                inputs,
4190
                                valueOut.getRawValue().get()
×
4191
                        ));
4192
                    } catch (IllegalArgumentException e) {
×
4193
                        throw new EvaluationException(Component.literal(e.getMessage()));
×
4194
                    }
4195
                }
4196
                return ValueObjectTypeRecipe.ValueRecipe.of(null);
×
4197
            }).build());
1✔
4198

4199
    /**
4200
     * ------------------------------------ PARSE OPERATORS ------------------------------------
4201
     */
4202

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

4212
    /**
4213
     * Double Parse operator which takes a string of a form Double.parseDouble(),
4214
     * `/([+-]?)(Inf(inity)?|\u221E)/i`, or Long.decode() can consume.
4215
     */
4216
    public static final IOperator PARSE_DOUBLE = Operators.REGISTRY.register(new ParseOperator<>(ValueTypes.DOUBLE, v -> {
8✔
4217
      ValueTypeString.ValueString value = v.getValue(0, ValueTypes.STRING);
6✔
4218
      try {
4219
        return ValueTypeDouble.ValueDouble.of(Double.parseDouble(value.getRawValue()));
5✔
4220
      } catch (NumberFormatException e) {
1✔
4221
        try {
4222
          // \u221E = infinity symbol
4223
          Pattern p = Pattern.compile("\\A([+-]?)(Inf(inity)?|\u221E)\\z", Pattern.CASE_INSENSITIVE);
4✔
4224
          Matcher m = p.matcher(value.getRawValue().trim());
6✔
4225
          if (m.matches()){
3✔
4226
            if (m.group(1).equals("-")){
6✔
4227
              return ValueTypeDouble.ValueDouble.of(Double.NEGATIVE_INFINITY);
3✔
4228
            }
4229
            return ValueTypeDouble.ValueDouble.of(Double.POSITIVE_INFINITY);
3✔
4230
          }
4231
          // Try as a long
4232
          return ValueTypeDouble.ValueDouble.of((double) Long.decode(value.getRawValue()));
7✔
4233
        } catch (NumberFormatException e2) {
1✔
4234
            throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_PARSE, value.getRawValue(),
16✔
4235
                    Component.translatable(ValueTypes.DOUBLE.getTranslationKey())));
3✔
4236
        }
4237
      }
4238
    }));
4239

4240
    /**
4241
     * Integer Parse operator which takes a string of a form Integer.decode() can consume.
4242
     */
4243
    public static final IOperator PARSE_INTEGER = Operators.REGISTRY.register(new ParseOperator<>(ValueTypes.INTEGER, v -> {
8✔
4244
      ValueTypeString.ValueString value = v.getValue(0, ValueTypes.STRING);
6✔
4245
      try{
4246
        return ValueTypeInteger.ValueInteger.of(Integer.decode(value.getRawValue()));
6✔
4247
      } catch (NumberFormatException e) {
1✔
4248
          throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_PARSE, value.getRawValue(),
16✔
4249
                  Component.translatable(ValueTypes.INTEGER.getTranslationKey())));
3✔
4250
      }
4251
    }));
4252

4253
    /**
4254
     * Long Parse operator which takes a string of a form Long.decode() can consume.
4255
     */
4256
    public static final IOperator PARSE_LONG = Operators.REGISTRY.register(new ParseOperator<>(ValueTypes.LONG, v -> {
8✔
4257
      ValueTypeString.ValueString value = v.getValue(0, ValueTypes.STRING);
6✔
4258
      try {
4259
        return ValueTypeLong.ValueLong.of(Long.decode(value.getRawValue()));
6✔
4260
      } catch (NumberFormatException e) {
1✔
4261
          throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_PARSE, value.getRawValue(),
16✔
4262
                  Component.translatable(ValueTypes.LONG.getTranslationKey())));
3✔
4263
      }
4264
    }));
4265

4266
    /**
4267
     * NBT Parse operator which takes a string of a form ValueTypeNbt().deserialize() can consume.
4268
     */
4269
    public static final IOperator PARSE_NBT = Operators.REGISTRY.register(new ParseOperator<>(ValueTypes.NBT, v -> {
8✔
4270
      ValueTypeString.ValueString value = v.getValue(0, ValueTypes.STRING);
6✔
4271
      try {
4272
        return ValueTypeNbt.ValueNbt.of(Helpers.TAG_PARSER.parseFully(value.getRawValue()));
7✔
4273
      } catch (CommandSyntaxException e) {
1✔
4274
        throw new EvaluationException(Component.translatable(L10NValues.OPERATOR_ERROR_PARSE, value.getRawValue(),
16✔
4275
                Component.translatable(ValueTypes.NBT.getTranslationKey())));
3✔
4276
      }
4277
    }));
4278

4279
    /**
4280
     * ----------------------------------- GENERAL OPERATORS -----------------------------------
4281
     */
4282

4283
    /**
4284
     * Choice operator with one boolean input, two any inputs and one output any.
4285
     */
4286
    public static final GeneralOperator GENERAL_CHOICE = REGISTRY.register(new GeneralChoiceOperator("?", "choice", "choice"));
10✔
4287

4288
    /**
4289
     * Identity operator with one any input and one any output
4290
     */
4291
    public static final GeneralOperator GENERAL_IDENTITY = REGISTRY.register(new GeneralIdentityOperator("id", "identity", "identity"));
10✔
4292

4293
    /**
4294
     * Constant operator with two any inputs and one any output
4295
     */
4296
    public static final GeneralOperator GENERAL_CONSTANT = REGISTRY.register(new GeneralConstantOperator("K", "constant", "constant"));
11✔
4297

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