• 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

2.99
/src/main/java/org/cyclops/integrateddynamics/core/evaluate/variable/ValueObjectTypeItemStack.java
1
package org.cyclops.integrateddynamics.core.evaluate.variable;
2

3
import lombok.ToString;
4
import net.minecraft.advancements.critereon.ItemPredicate;
5
import net.minecraft.core.registries.BuiltInRegistries;
6
import net.minecraft.network.chat.Component;
7
import net.minecraft.network.chat.MutableComponent;
8
import net.minecraft.world.item.ItemStack;
9
import net.minecraft.world.level.storage.ValueInput;
10
import net.minecraft.world.level.storage.ValueOutput;
11
import org.cyclops.commoncapabilities.api.capability.itemhandler.ItemMatch;
12
import org.cyclops.cyclopscore.helper.IModHelpers;
13
import org.cyclops.integrateddynamics.api.advancement.criterion.ValuePredicate;
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.api.evaluate.variable.IValueTypeUniquelyNamed;
18
import org.cyclops.integrateddynamics.core.logicprogrammer.ValueTypeItemStackLPElement;
19
import org.cyclops.integrateddynamics.core.logicprogrammer.ValueTypeLPElementBase;
20

21
import java.util.Objects;
22
import java.util.Optional;
23

24
/**
25
 * Value type with values that are itemstacks.
26
 * @author rubensworks
27
 */
28
public class ValueObjectTypeItemStack extends ValueObjectTypeBase<ValueObjectTypeItemStack.ValueItemStack> implements
29
        IValueTypeNamed<ValueObjectTypeItemStack.ValueItemStack>,
30
        IValueTypeUniquelyNamed<ValueObjectTypeItemStack.ValueItemStack>,
31
        IValueTypeNullable<ValueObjectTypeItemStack.ValueItemStack> {
32

33
    public ValueObjectTypeItemStack() {
34
        super("itemstack", ValueObjectTypeItemStack.ValueItemStack.class);
4✔
35
    }
1✔
36

37
    public static MutableComponent getItemStackDisplayNameUsSafe(ItemStack itemStack) throws NoSuchMethodException {
38
        return !itemStack.isEmpty()
×
39
                ? (itemStack.getHoverName().copy().append((itemStack.getCount() > 1 ? " (" + itemStack.getCount() + ")" : "")))
×
40
                : Component.literal("");
×
41
    }
42

43
    public static MutableComponent getItemStackDisplayNameSafe(ItemStack itemStack) {
44
        // Certain mods may call client-side only methods,
45
        // so call a server-side-safe fallback method if that fails.
46
        try {
47
            return getItemStackDisplayNameUsSafe(itemStack);
×
48
        } catch (NoSuchMethodException e) {
×
49
            return Component.translatable(itemStack.getItem().getDescriptionId());
×
50
        }
51
    }
52

53
    @Override
54
    public ValueItemStack getDefault() {
55
        return ValueItemStack.of(ItemStack.EMPTY);
×
56
    }
57

58
    @Override
59
    public MutableComponent toCompactString(ValueItemStack value) {
60
        return ValueObjectTypeItemStack.getItemStackDisplayNameSafe(value.getRawValue());
×
61
    }
62

63
    @Override
64
    public void serialize(ValueOutput valueOutput, ValueItemStack value) {
65
        valueOutput = valueOutput.child("v");
×
66
        ItemStack itemStack;
67
        itemStack = value.getRawValue();
×
68
        int count = itemStack.getCount();
×
69
        if (itemStack.getCount() > 99) {
×
70
            itemStack = itemStack.copy();
×
71
            itemStack.setCount(99);
×
72
        }
73
        if (count > 99) {
×
74
            valueOutput.putInt("ExtendedCount", count);
×
75
        }
76
        valueOutput.store("stack", ItemStack.OPTIONAL_CODEC, itemStack);
×
77
    }
×
78

79
    @Override
80
    public ValueItemStack deserialize(ValueInput valueInput) {
81
        valueInput = valueInput.child("v").orElseThrow();
×
82
        ItemStack itemStack = valueInput.read("stack", ItemStack.OPTIONAL_CODEC).orElseThrow();
×
83
        valueInput.getInt("ExtendedCount").ifPresent(itemStack::setCount);
×
84
        return ValueItemStack.of(itemStack);
×
85
    }
86

87
    @Override
88
    public String getName(ValueItemStack a) {
89
        return toCompactString(a).getString();
×
90
    }
91

92
    @Override
93
    public boolean isNull(ValueItemStack a) {
94
        return a.getRawValue().isEmpty();
×
95
    }
96

97
    @Override
98
    public ValueTypeLPElementBase createLogicProgrammerElement() {
99
        return new ValueTypeItemStackLPElement<>(this, new ValueTypeItemStackLPElement.IItemStackToValue<ValueObjectTypeItemStack.ValueItemStack>() {
×
100
            @Override
101
            public boolean isNullable() {
102
                return true;
×
103
            }
104

105
            @Override
106
            public Component validate(ItemStack itemStack) {
107
                return null;
×
108
            }
109

110
            @Override
111
            public ValueObjectTypeItemStack.ValueItemStack getValue(ItemStack itemStack) {
112
                return ValueObjectTypeItemStack.ValueItemStack.of(itemStack);
×
113
            }
114

115
            @Override
116
            public ItemStack getValueAsItemStack(ValueItemStack value) {
117
                return value.getRawValue();
×
118
            }
119
        });
120
    }
121

122
    @Override
123
    public ValueItemStack materialize(ValueItemStack value) throws EvaluationException {
124
        return ValueItemStack.of(value.getRawValue().copy());
×
125
    }
126

127
    @Override
128
    public String getUniqueName(ValueItemStack value) {
129
        ItemStack itemStack = value.getRawValue();
×
130
        return !itemStack.isEmpty() ? BuiltInRegistries.ITEM.getKey(itemStack.getItem()).toString() : "";
×
131
    }
132

133
    @ToString
×
134
    public static class ValueItemStack extends ValueBase {
135

136
        private final ItemStack itemStack;
137

138
        private ValueItemStack(ItemStack itemStack) {
139
            super(ValueTypes.OBJECT_ITEMSTACK);
×
140
            this.itemStack = Objects.requireNonNull(itemStack, "Attempted to create a ValueItemStack for a null ItemStack.");
×
141
        }
×
142

143
        public static ValueItemStack of(ItemStack itemStack) {
144
            return new ValueItemStack(itemStack);
×
145
        }
146

147
        public ItemStack getRawValue() {
148
            return itemStack;
×
149
        }
150

151
        @Override
152
        public boolean equals(Object o) {
153
            return o instanceof ValueItemStack && ItemMatch.areItemStacksEqual(((ValueItemStack) o).itemStack, this.itemStack, ItemMatch.EXACT);
×
154
        }
155

156
        @Override
157
        public int hashCode() {
158
            return 37 + IModHelpers.get().getItemStackHelpers().getItemStackHashCode(itemStack);
×
159
        }
160
    }
161

162
    public static class ValueItemStackPredicate extends ValuePredicate<ValueItemStack> {
163

164
        private final Optional<ItemPredicate> itemPredicate;
165

166
        public ValueItemStackPredicate(Optional<ItemPredicate> itemPredicate) {
167
            super(Optional.of(ValueTypes.OBJECT_ITEMSTACK), Optional.empty(), Optional.empty());
×
168
            this.itemPredicate = itemPredicate;
×
169
        }
×
170

171
        public Optional<ItemPredicate> getItemPredicate() {
172
            return itemPredicate;
×
173
        }
174

175
        @Override
176
        protected boolean testTyped(ValueItemStack value) {
177
            return super.testTyped(value) && (itemPredicate.isEmpty() || itemPredicate.get().test(value.getRawValue()));
×
178
        }
179
    }
180

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