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

CyclopsMC / IntegratedDynamics / 22182377337

19 Feb 2026 12:46PM UTC coverage: 44.49% (-1.7%) from 46.183%
22182377337

push

github

rubensworks
Fix performance workflow failing

2663 of 8850 branches covered (30.09%)

Branch coverage included in aggregate %.

12028 of 24171 relevant lines covered (49.76%)

2.36 hits per line

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

80.77
/src/main/java/org/cyclops/integrateddynamics/core/evaluate/InventoryVariableEvaluator.java
1
package org.cyclops.integrateddynamics.core.evaluate;
2

3
import com.google.common.collect.Lists;
4
import net.minecraft.network.chat.Component;
5
import net.minecraft.network.chat.MutableComponent;
6
import net.minecraft.world.Container;
7
import net.minecraft.world.item.ItemStack;
8
import org.cyclops.integrateddynamics.IntegratedDynamics;
9
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
10
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueType;
11
import org.cyclops.integrateddynamics.api.evaluate.variable.IVariable;
12
import org.cyclops.integrateddynamics.api.evaluate.variable.ValueDeseralizationContext;
13
import org.cyclops.integrateddynamics.api.item.IVariableFacade;
14
import org.cyclops.integrateddynamics.api.item.IVariableFacadeHandlerRegistry;
15
import org.cyclops.integrateddynamics.api.network.INetwork;
16
import org.cyclops.integrateddynamics.api.network.IPartNetwork;
17
import org.cyclops.integrateddynamics.core.helper.L10NValues;
18
import org.cyclops.integrateddynamics.core.helper.NetworkHelpers;
19
import org.cyclops.integrateddynamics.core.network.event.VariableContentsUpdatedEvent;
20

21
import javax.annotation.Nullable;
22
import java.util.List;
23
import java.util.function.Supplier;
24

25
/**
26
 * A convenience holder class for getting variables from variable cards in a certain inventory slot.
27
 * @param <V> The variable value type
28
 * @author rubensworks
29
 */
30
public class InventoryVariableEvaluator<V extends IValue> implements IVariableFacade.IValidator {
31

32
    private final IVariableFacadeHandlerRegistry handler = IntegratedDynamics._instance.getRegistryManager()
4✔
33
            .getRegistry(IVariableFacadeHandlerRegistry.class);
3✔
34
    private final Container inventory;
35
    private final int slot;
36
    private final Supplier<ValueDeseralizationContext> valueDeseralizationContext;
37
    private final IValueType containingValueType;
38

39
    private IVariableFacade variableStored = null;
3✔
40
    private List<MutableComponent> errors = Lists.newLinkedList();
3✔
41

42
    public InventoryVariableEvaluator(Container inventory, int slot, Supplier<ValueDeseralizationContext> valueDeseralizationContext, IValueType<V> containingValueType) {
2✔
43
        this.inventory = inventory;
3✔
44
        this.slot = slot;
3✔
45
        this.valueDeseralizationContext = valueDeseralizationContext;
3✔
46
        this.containingValueType = containingValueType;
3✔
47
    }
1✔
48

49
    public InventoryVariableEvaluator(Container inventory, int slot, ValueDeseralizationContext valueDeseralizationContext, IValueType<V> containingValueType) {
50
        this(inventory, slot, () -> valueDeseralizationContext, containingValueType);
7✔
51
    }
1✔
52

53
    /**
54
     * @return If the configured slot has an item.
55
     */
56
    public boolean hasVariable() {
57
        return !inventory.getItem(slot).isEmpty();
9!
58
    }
59

60
    /**
61
     * Refresh the variable reference by checking the inventory,
62
     * and validating the containing variable.
63
     * @param network The network.
64
     * @param sendVariablesUpdateEvent If a {@link VariableContentsUpdatedEvent} event must be sent
65
     *                                 if the variable has changed.
66
     */
67
    public void refreshVariable(@Nullable INetwork network, boolean sendVariablesUpdateEvent) {
68
        IPartNetwork partNetwork = NetworkHelpers.getPartNetwork(network).orElse(null);
6✔
69

70
        int lastVariabledId = this.variableStored == null ? -1 : this.variableStored.getId();
9✔
71
        int variableId = -1;
2✔
72
        if (!inventory.getItem(slot).isEmpty() && NetworkHelpers.shouldWork()) {
9!
73
            // Update proxy input
74
            ItemStack itemStack = inventory.getItem(slot);
6✔
75
            this.variableStored = handler.handle(valueDeseralizationContext.get(), itemStack);
10✔
76
            if(this.variableStored != null) {
3!
77
                variableId = this.variableStored.getId();
4✔
78
            }
79
        } else {
1✔
80
            this.variableStored = null;
3✔
81
        }
82

83
        clearErrors();
2✔
84
        if (partNetwork == null) {
2!
85
            addError(Component.translatable(L10NValues.GENERAL_ERROR_NONETWORK));
×
86
        } else if (this.variableStored != null) {
3✔
87
            preValidate();
2✔
88
            try {
89
                variableStored.validate(network, partNetwork, this, containingValueType);
8✔
90
            } catch (IllegalArgumentException e) {
×
91
                addError(Component.translatable(e.getMessage()));
×
92
            }
1✔
93
        }
94
        if(sendVariablesUpdateEvent && partNetwork != null && lastVariabledId != variableId) {
7!
95
            network.getEventBus().post(new VariableContentsUpdatedEvent(network));
7✔
96
        }
97
    }
1✔
98

99
    @Nullable
100
    public IVariable<V> getVariable(INetwork network) {
101
        return getVariable(network, NetworkHelpers.getPartNetworkChecked(network));
6✔
102
    }
103

104
    @Nullable
105
    public IVariable<V> getVariable(INetwork network, IPartNetwork partNetwork) {
106
        if(getVariableFacade() == null || !getErrors().isEmpty()) return null;
9!
107
        try {
108
            return getVariableFacade().getVariable(network, partNetwork);
6✔
109
        } catch (IllegalArgumentException e) {
×
110
            addError(Component.translatable(e.getMessage()));
×
111
            return null;
×
112
        }
113
    }
114

115
    public IVariableFacade getVariableFacade() {
116
        return variableStored;
3✔
117
    }
118

119
    protected void preValidate() {
120

121
    }
1✔
122

123
    public void clearErrors() {
124
        this.errors.clear();
3✔
125
        onErrorsChanged();
2✔
126
    }
1✔
127

128
    public void setErrors(List<MutableComponent> errors) {
129
        this.errors = errors;
×
130
        onErrorsChanged();
×
131
    }
×
132

133
    public List<MutableComponent> getErrors() {
134
        return errors;
3✔
135
    }
136

137
    @Override
138
    public void addError(MutableComponent error) {
139
        errors.add(error);
5✔
140
        onErrorsChanged();
2✔
141
    }
1✔
142

143
    public void onErrorsChanged() {
144

145
    }
1✔
146
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc