• 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/part/aspect/LazyAspectVariable.java
1
package org.cyclops.integrateddynamics.core.part.aspect;
2

3
import lombok.Getter;
4
import lombok.NonNull;
5
import net.minecraft.network.chat.Component;
6
import org.apache.commons.lang3.tuple.Pair;
7
import org.cyclops.integrateddynamics.api.evaluate.EvaluationException;
8
import org.cyclops.integrateddynamics.api.evaluate.expression.VariableAdapter;
9
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
10
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueType;
11
import org.cyclops.integrateddynamics.api.part.IPartState;
12
import org.cyclops.integrateddynamics.api.part.IPartType;
13
import org.cyclops.integrateddynamics.api.part.PartPos;
14
import org.cyclops.integrateddynamics.api.part.PartTarget;
15
import org.cyclops.integrateddynamics.api.part.aspect.IAspectRead;
16
import org.cyclops.integrateddynamics.api.part.aspect.IAspectVariable;
17
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
18
import org.cyclops.integrateddynamics.core.helper.L10NValues;
19

20
import java.util.function.Supplier;
21

22
/**
23
 * Variable for a specific aspect from a part that calculates its target value only maximum once per ticking interval.
24
 * No calculations will be done if the value of this variable is not called.
25
 * @author rubensworks
26
 */
27
public abstract class LazyAspectVariable<V extends IValue> extends VariableAdapter<V> implements IAspectVariable<V> {
28

29
    @Getter private final IValueType<V> type;
×
30
    private final Supplier<PartTarget> targetSupplier;
31
    @Getter private final IAspectRead<V, ?> aspect;
×
32
    @NonNull private V value;
33
    private IAspectProperties cachedProperties = null;
×
34

35
    private boolean isGettingValue = false;
×
36

37
    public LazyAspectVariable(IValueType<V> type, Supplier<PartTarget> targetSupplier, IAspectRead<V, ?> aspect) {
×
38
        this.type = type;
×
39
        this.targetSupplier = targetSupplier;
×
40
        this.aspect = aspect;
×
41
    }
×
42

43
    public PartTarget getTarget() {
44
        return targetSupplier.get();
×
45
    }
46

47
    @Override
48
    public void invalidate() {
49
        if (value != null) {
×
50
            value = null;
×
51
            cachedProperties = null;
×
52
            super.invalidate();
×
53
        }
54
    }
×
55

56
    @Override
57
    public V getValue() throws EvaluationException {
58
        if(value == null) {
×
59
            if(this.isGettingValue) {
×
60
                throw new EvaluationException(Component.translatable(L10NValues.VARIABLE_ERROR_RECURSION,
×
61
                        Component.translatable(getAspect().getTranslationKey())));
×
62
            }
63
            this.isGettingValue = true;
×
64
            try {
65
                this.value = getValueLazy();
×
66
            } catch (EvaluationException e) {
×
67
                this.isGettingValue = false;
×
68
                throw e;
×
69
            }
×
70
            this.isGettingValue = false;
×
71
        }
72
        return this.value;
×
73
    }
74

75
    protected IAspectProperties getAspectProperties() {
76
        if(cachedProperties == null && getAspect().hasProperties()) {
×
77
            PartPos pos = getTarget().getCenter();
×
78
            Pair<IPartType, IPartState> partData = PartPos.getPartData(pos);
×
79
            if (partData != null) {
×
80
                cachedProperties = getAspect().getProperties(partData.getLeft(), getTarget(), partData.getRight());
×
81
            }
82
        }
83
        return cachedProperties;
×
84
    }
85

86
    /**
87
     * Calculate the current value for this variable.
88
     * It will only be called when required.
89
     * @return The current value of this variable.
90
     * @throws EvaluationException If evaluation has gone wrong.
91
     */
92
    public abstract V getValueLazy() throws EvaluationException;
93

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