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

CyclopsMC / IntegratedDynamics / 16552051255

27 Jul 2025 01:58PM UTC coverage: 53.206% (+8.0%) from 45.161%
16552051255

push

github

rubensworks
Resolve minor TODOs

2888 of 8740 branches covered (33.04%)

Branch coverage included in aggregate %.

17341 of 29280 relevant lines covered (59.22%)

3.08 hits per line

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

66.67
/src/main/java/org/cyclops/integrateddynamics/core/evaluate/variable/ValueTypeNbt.java
1
package org.cyclops.integrateddynamics.core.evaluate.variable;
2

3
import com.mojang.brigadier.exceptions.CommandSyntaxException;
4
import net.minecraft.ChatFormatting;
5
import net.minecraft.nbt.CompoundTag;
6
import net.minecraft.nbt.Tag;
7
import net.minecraft.network.chat.Component;
8
import net.minecraft.network.chat.MutableComponent;
9
import net.minecraft.util.ExtraCodecs;
10
import net.minecraft.world.level.storage.ValueInput;
11
import net.minecraft.world.level.storage.ValueOutput;
12
import org.cyclops.cyclopscore.helper.IModHelpers;
13
import org.cyclops.integrateddynamics.GeneralConfig;
14
import org.cyclops.integrateddynamics.api.evaluate.EvaluationException;
15
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueTypeNamed;
16
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueTypeNullable;
17
import org.cyclops.integrateddynamics.core.helper.Helpers;
18

19
import javax.annotation.Nullable;
20
import java.util.Optional;
21

22
/**
23
 * Value type with values that are NBT tags.
24
 * @author rubensworks
25
 */
26
public class ValueTypeNbt extends ValueTypeBase<ValueTypeNbt.ValueNbt>
27
        implements IValueTypeNullable<ValueTypeNbt.ValueNbt>, IValueTypeNamed<ValueTypeNbt.ValueNbt> {
28

29
    public ValueTypeNbt() {
30
        super("nbt", IModHelpers.get().getBaseHelpers().RGBToInt(0, 170, 170), ChatFormatting.DARK_AQUA, ValueTypeNbt.ValueNbt.class);
11✔
31
    }
1✔
32

33
    @Override
34
    public ValueNbt getDefault() {
35
        return ValueNbt.of();
×
36
    }
37

38
    @Override
39
    public MutableComponent toCompactString(ValueNbt value) {
40
        return Component.literal(toString(value));
×
41
    }
42

43
    @Override
44
    public void serialize(ValueOutput valueOutput, ValueNbt value) {
45
        if (value.getRawValue().isPresent()) {
4✔
46
            valueOutput.store("v", ExtraCodecs.NBT, value.getRawValue().get());
8✔
47
        }
48
    }
1✔
49

50
    @Override
51
    public ValueNbt deserialize(ValueInput valueInput) {
52
        return ValueNbt.of(valueInput.read("v", ExtraCodecs.NBT));
6✔
53
    }
54

55
    @Override
56
    public String toString(ValueNbt value) {
57
        return value.getRawValue().map(Object::toString).orElse("");
8✔
58
    }
59

60
    @Override
61
    public ValueNbt parseString(String value) throws EvaluationException {
62
        if (value.isEmpty()) {
3✔
63
            return ValueNbt.of();
2✔
64
        }
65
        try {
66
            return ValueNbt.of(Helpers.TAG_PARSER.parseFully(value));
6✔
67
        } catch (CommandSyntaxException e) {
1✔
68
            throw new EvaluationException(Component.literal(e.getMessage()));
7✔
69
        }
70
    }
71

72
    @Override
73
    public boolean isNull(ValueNbt a) {
74
        return !a.getRawValue().isPresent();
×
75
    }
76

77
    /**
78
     * Filter away the blacklisted tags from the given NBT tag.
79
     * This won't modify the original tag.
80
     * @param tag The tag.
81
     * @return The tag where all blacklisted tags have been removed.
82
     */
83
    public Tag filterBlacklistedTags(Tag tag) {
84
        if (tag instanceof CompoundTag) {
3✔
85
            boolean copied = false;
2✔
86
            CompoundTag compountTag = (CompoundTag) tag;
3✔
87
            for (String key : GeneralConfig.nbtTagBlacklist) {
6!
88
                if (compountTag.contains(key)) {
×
89
                    if (!copied) {
×
90
                        copied = true;
×
91
                        compountTag = compountTag.copy();
×
92
                    }
93
                    compountTag.remove(key);
×
94
                }
95
            }
×
96
            return compountTag;
2✔
97
        }
98
        return tag;
2✔
99
    }
100

101
    @Override
102
    public String getName(ValueNbt value) {
103
        return toCompactString(value).getString();
×
104
    }
105

106
    public static class ValueNbt extends ValueOptionalBase<Tag> {
107

108
        private ValueNbt(Tag value) {
109
            super(ValueTypes.NBT, value);
4✔
110
        }
1✔
111

112
        @Nullable
113
        @Override
114
        protected Tag preprocessValue(@Nullable Tag value) {
115
            if (value != null) {
2✔
116
                return ValueTypes.NBT.filterBlacklistedTags(value);
4✔
117
            }
118
            return null;
2✔
119
        }
120

121
        public static ValueNbt of(@Nullable Tag value) {
122
            return new ValueNbt(value);
5✔
123
        }
124

125
        public static ValueNbt of(Optional<Tag> value) {
126
            return of(value.orElse(null));
6✔
127
        }
128

129
        public static ValueNbt of() {
130
            return of((Tag) null);
4✔
131
        }
132

133
        @Override
134
        protected boolean isEqual(Tag a, Tag b) {
135
            return a.equals(b);
4✔
136
        }
137

138
        @Override
139
        public String toString() {
140
            return getRawValue().map(Tag::toString).orElse("none");
×
141
        }
142
    }
143

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