• 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

25.37
/src/main/java/org/cyclops/integrateddynamics/core/evaluate/variable/ValueTypeRegistry.java
1
package org.cyclops.integrateddynamics.core.evaluate.variable;
2

3
import com.google.common.collect.Maps;
4
import com.mojang.logging.LogUtils;
5
import net.minecraft.nbt.CompoundTag;
6
import net.minecraft.resources.ResourceLocation;
7
import net.minecraft.util.ProblemReporter;
8
import net.minecraft.world.level.storage.TagValueInput;
9
import net.minecraft.world.level.storage.TagValueOutput;
10
import net.minecraft.world.level.storage.ValueInput;
11
import org.cyclops.cyclopscore.helper.IModHelpers;
12
import org.cyclops.integrateddynamics.IntegratedDynamics;
13
import org.cyclops.integrateddynamics.Reference;
14
import org.cyclops.integrateddynamics.api.advancement.criterion.ValuePredicate;
15
import org.cyclops.integrateddynamics.api.advancement.criterion.VariableFacadePredicate;
16
import org.cyclops.integrateddynamics.api.evaluate.variable.*;
17
import org.cyclops.integrateddynamics.api.item.IValueTypeVariableFacade;
18
import org.cyclops.integrateddynamics.api.item.IVariableFacade;
19
import org.cyclops.integrateddynamics.api.item.IVariableFacadeHandlerRegistry;
20
import org.cyclops.integrateddynamics.api.item.TagPathElement;
21
import org.cyclops.integrateddynamics.core.item.ValueTypeVariableFacade;
22
import org.slf4j.Logger;
23

24
import java.util.*;
25

26
/**
27
 * Registry for {@link IValueType}.
28
 * @author rubensworks
29
 */
30
public final class ValueTypeRegistry implements IValueTypeRegistry {
31

32
    private static final Logger LOGGER = LogUtils.getLogger();
2✔
33
    private static ValueTypeRegistry INSTANCE = new ValueTypeRegistry();
4✔
34
    private static final IValueTypeVariableFacade INVALID_FACADE = new ValueTypeVariableFacade(false, null, (IValue) null);
9✔
35

36
    private final Map<String, IValueType> valueTypes = Maps.newHashMap();
3✔
37
    private ValueTypeRegistryClient client;
38

39
    private ValueTypeRegistry() {
2✔
40
        if(IModHelpers.get().getMinecraftHelpers().isModdedEnvironment()) {
4!
41
            if(IModHelpers.get().getMinecraftHelpers().isClientSide()) {
4!
42
                client = new ValueTypeRegistryClient();
×
43
            }
44
            IntegratedDynamics._instance.getRegistryManager().getRegistry(IVariableFacadeHandlerRegistry.class).registerHandler(this);
7✔
45
        }
46
    }
1✔
47

48
    /**
49
     * @return The unique instance.
50
     */
51
    public static ValueTypeRegistry getInstance() {
52
        return INSTANCE;
2✔
53
    }
54

55
    @Override
56
    public IValueTypeRegistryClient getClient() {
57
        return this.client;
×
58
    }
59

60
    @Override
61
    public <V extends IValue, T extends IValueType<V>> T register(T valueType) {
62
        valueTypes.put(valueType.getUniqueName().toString(), valueType);
8✔
63
        return valueType;
2✔
64
    }
65

66
    @Override
67
    public <V extends IValue, T extends IValueTypeCategory<V>> T registerCategory(T category) {
68
        return register(category);
5✔
69
    }
70

71
    @Override
72
    public IValueType getValueType(ResourceLocation name) {
73
        return valueTypes.get(name.toString());
7✔
74
    }
75

76
    @Override
77
    public Collection<IValueType> getValueTypes() {
78
        return Collections.unmodifiableCollection(valueTypes.values());
×
79
    }
80

81
    @Override
82
    public ResourceLocation getUniqueName() {
83
        return ResourceLocation.fromNamespaceAndPath(Reference.MOD_ID, "valuetype");
4✔
84
    }
85

86
    @Override
87
    public IValueTypeVariableFacade getVariableFacade(ValueDeseralizationContext valueDeseralizationContext, int id, CompoundTag tag) {
88
        if(!tag.contains("typeName") || !tag.contains("value")) {
×
89
            return INVALID_FACADE;
×
90
        }
91
        IValueType type = getValueType(ResourceLocation.parse(tag.getString("typeName").orElseThrow()));
×
92
        if(type == null) {
×
93
            return INVALID_FACADE;
×
94
        }
95
        IValue value;
96
        try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(new TagPathElement(tag), LOGGER)) {
×
97
            ValueInput input = TagValueInput.create(
×
98
                    scopedCollector,
99
                    valueDeseralizationContext.holderLookupProvider(),
×
100
                    tag.getCompound("value").orElseThrow()
×
101
            );
102
            value = ValueHelpers.deserializeRaw(input, type);
×
103
        } catch (IllegalArgumentException | NoSuchElementException e) {
×
104
            return INVALID_FACADE;
×
105
        }
×
106
        return new ValueTypeVariableFacade(id, type, value);
×
107
    }
108

109
    @Override
110
    public void setVariableFacade(ValueDeseralizationContext valueDeseralizationContext, CompoundTag tag, IValueTypeVariableFacade variableFacade) {
111
        tag.putString("typeName", variableFacade.getValueType().getUniqueName().toString());
×
112
        try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(new TagPathElement(tag), LOGGER)) {
×
113
            TagValueOutput valueOutput = TagValueOutput.createWithContext(scopedCollector, valueDeseralizationContext.holderLookupProvider());
×
114
            ValueHelpers.serializeRaw(valueOutput, variableFacade.getValue());
×
115
            tag.put("value", valueOutput.buildResult());
×
116
        }
117
    }
×
118

119
    @Override
120
    public boolean isInstance(IVariableFacade variableFacade) {
121
        return variableFacade instanceof IValueTypeVariableFacade;
×
122
    }
123

124
    @Override
125
    public boolean isInstance(IVariable<?> variable) {
126
        return variable instanceof IVariable;
×
127
    }
128

129
    public static class ValueTypeVariableFacadePredicate extends VariableFacadePredicate<IValueTypeVariableFacade> {
130

131
        private final Optional<IValueType> valueType;
132
        private final Optional<ValuePredicate> valuePredicate;
133

134
        public ValueTypeVariableFacadePredicate(Optional<IValueType> valueType, Optional<ValuePredicate> valuePredicate) {
135
            super(IValueTypeVariableFacade.class);
×
136
            this.valueType = valueType;
×
137
            this.valuePredicate = valuePredicate;
×
138
        }
×
139

140
        public Optional<IValueType> getValueType() {
141
            return valueType;
×
142
        }
143

144
        public Optional<ValuePredicate> getValuePredicate() {
145
            return valuePredicate;
×
146
        }
147

148
        @Override
149
        protected boolean testTyped(IValueTypeVariableFacade variableFacade) {
150
            return super.testTyped(variableFacade)
×
151
                    && (valueType.isEmpty() || ValueHelpers.correspondsTo(variableFacade.getValueType(), valueType.get()))
×
152
                    && valuePredicate.orElse(ValuePredicate.ANY).test(variableFacade.getValue());
×
153
        }
154
    }
155
}
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