• 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

0.0
/src/main/java/org/cyclops/integrateddynamics/core/evaluate/operator/PositionedOperatorRecipeHandler.java
1
package org.cyclops.integrateddynamics.core.evaluate.operator;
2

3
import com.google.common.collect.Lists;
4
import net.minecraft.core.Direction;
5
import org.cyclops.commoncapabilities.api.capability.recipehandler.IRecipeHandler;
6
import org.cyclops.commoncapabilities.api.ingredient.IMixedIngredients;
7
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
8
import org.cyclops.cyclopscore.datastructure.DimPos;
9
import org.cyclops.integrateddynamics.api.evaluate.operator.IOperator;
10
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
11
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueType;
12
import org.cyclops.integrateddynamics.api.logicprogrammer.IConfigRenderPattern;
13
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypes;
14

15
import java.util.List;
16
import java.util.Optional;
17

18
/**
19
 * An operator related to a recipe handler.
20
 * @author rubensworks
21
 */
22
public class PositionedOperatorRecipeHandler<T extends IValueType<V>, V extends IValue> extends PositionedOperator {
23

24
    private final String unlocalizedType;
25

26
    public PositionedOperatorRecipeHandler(String name, Function function, IValueType output, DimPos pos, Direction side) {
27
        super(name, name, name, new IValueType[]{ValueTypes.OBJECT_INGREDIENTS},
×
28
                output, function, IConfigRenderPattern.PREFIX_1, pos, side);
29
        this.unlocalizedType = "virtual";
×
30
        ((Function) this.getFunction()).setOperator(this);
×
31
    }
×
32

33
    public PositionedOperatorRecipeHandler(String name, Function function, DimPos pos, Direction side) {
34
        super(name, name, name, new IValueType[]{ValueTypes.OBJECT_INGREDIENTS},
×
35
                ValueTypes.OBJECT_INGREDIENTS, function, IConfigRenderPattern.PREFIX_1, pos, side);
36
        this.unlocalizedType = "virtual";
×
37
        ((Function) this.getFunction()).setOperator(this);
×
38
    }
×
39

40
    protected Optional<IRecipeHandler> getRecipeHandler() {
41
        return Optional.ofNullable(getPos().getLevel(true).getCapability(org.cyclops.commoncapabilities.api.capability.Capabilities.RecipeHandler.BLOCK, getPos().getBlockPos(), getSide()));
×
42
    }
43

44
    @Override
45
    protected String getUnlocalizedType() {
46
        return unlocalizedType;
×
47
    }
48

49
    @Override
50
    public IOperator materialize() {
51
        return this;
×
52
    }
53

54
    public static abstract class Function implements IFunction {
×
55

56
        private PositionedOperatorRecipeHandler operator;
57

58
        public void setOperator(PositionedOperatorRecipeHandler operator) {
59
            this.operator = operator;
×
60
        }
×
61

62
        public PositionedOperatorRecipeHandler getOperator() {
63
            return operator;
×
64
        }
65
    }
66

67
    public static boolean validateIngredientsExact(IMixedIngredients ingredients, IMixedIngredients givenIngredients) {
68
        for (IngredientComponent component : ingredients.getComponents()) {
×
69
            List<?> actualComponents = ingredients.getInstances(component);
×
70
            List<?> givenComponents = givenIngredients.getInstances(component);
×
71

72
            if (actualComponents.size() != givenComponents.size()) {
×
73
                return false;
×
74
            }
75

76
            // All components must be valid
77
            for (int i = 0; i < actualComponents.size(); i++) {
×
78
                Object actualIngredient = actualComponents.get(i);
×
79
                Object givenIngredient = givenComponents.get(i);
×
80
                if (!component.getMatcher().matchesExactly(givenIngredient, actualIngredient)) {
×
81
                    return false;
×
82
                }
83
            }
84
        }
×
85
        return true;
×
86
    }
87

88
    public static boolean validateIngredientsPartial(IMixedIngredients ingredients, IMixedIngredients givenIngredients) {
89
        for (IngredientComponent component : ingredients.getComponents()) {
×
90
            List<?> actualComponents = ingredients.getInstances(component);
×
91
            List<?> givenComponents = givenIngredients.getInstances(component);
×
92

93
            // At least all given components must match,
94
            // the actual component count may be larger.
95
            if (actualComponents.size() < givenComponents.size()) {
×
96
                return false;
×
97
            }
98

99
            // All GIVEN ingredients must match,
100
            // and all actual components may only be matched at most ONCE.
101
            List<Integer> actualIndexBlacklist = Lists.newLinkedList();
×
102
            for (Object givenIngredient : givenComponents) {
×
103
                boolean match = false;
×
104
                for (int i = 0; i < actualComponents.size(); i++) {
×
105
                    if (!actualIndexBlacklist.contains(i)
×
106
                            && component.getMatcher().matchesExactly(givenIngredient, actualComponents.get(i))) {
×
107
                        match = true;
×
108
                        break;
×
109
                    }
110
                }
111
                if (!match) {
×
112
                    return false;
×
113
                }
114
            }
×
115
        }
×
116
        return true;
×
117
    }
118

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