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

CyclopsMC / CommonCapabilities / #479006779

28 Dec 2024 02:23PM UTC coverage: 39.947% (+0.2%) from 39.763%
#479006779

push

github

rubensworks
Update to MC 1.21.4

908 of 2273 relevant lines covered (39.95%)

0.4 hits per line

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

94.59
/src/main/java/org/cyclops/commoncapabilities/ingredient/IngredientMatcherItemStack.java
1
package org.cyclops.commoncapabilities.ingredient;
2

3
import net.minecraft.core.registries.BuiltInRegistries;
4
import net.minecraft.network.chat.MutableComponent;
5
import net.minecraft.world.item.Item;
6
import net.minecraft.world.item.ItemStack;
7
import org.cyclops.commoncapabilities.api.capability.itemhandler.ItemMatch;
8
import org.cyclops.commoncapabilities.api.ingredient.IIngredientMatcher;
9
import org.cyclops.cyclopscore.helper.IModHelpers;
10

11
/**
12
 * Matcher for ItemStacks.
13
 * @author rubensworks
14
 */
15
public class IngredientMatcherItemStack implements IIngredientMatcher<ItemStack, Integer> {
1✔
16
    @Override
17
    public boolean isInstance(Object object) {
18
        return object instanceof ItemStack;
1✔
19
    }
20

21
    @Override
22
    public Integer getAnyMatchCondition() {
23
        return ItemMatch.ANY;
1✔
24
    }
25

26
    @Override
27
    public Integer getExactMatchCondition() {
28
        return ItemMatch.EXACT;
1✔
29
    }
30

31
    @Override
32
    public Integer getExactMatchNoQuantityCondition() {
33
        return ItemMatch.ITEM | ItemMatch.DATA;
1✔
34
    }
35

36
    @Override
37
    public Integer withCondition(Integer matchCondition, Integer with) {
38
        return matchCondition | with;
1✔
39
    }
40

41
    @Override
42
    public Integer withoutCondition(Integer matchCondition, Integer without) {
43
        return matchCondition & ~without;
1✔
44
    }
45

46
    @Override
47
    public boolean hasCondition(Integer matchCondition, Integer searchCondition) {
48
        return (matchCondition & searchCondition) > 0;
1✔
49
    }
50

51
    @Override
52
    public boolean matches(ItemStack a, ItemStack b, Integer matchCondition) {
53
        return ItemMatch.areItemStacksEqual(a, b, matchCondition);
1✔
54
    }
55

56
    @Override
57
    public ItemStack getEmptyInstance() {
58
        return ItemStack.EMPTY;
1✔
59
    }
60

61
    @Override
62
    public boolean isEmpty(ItemStack instance) {
63
        return instance.isEmpty();
1✔
64
    }
65

66
    @Override
67
    public int hash(ItemStack instance) {
68
        return IModHelpers.get().getItemStackHelpers().getItemStackHashCode(instance);
1✔
69
    }
70

71
    @Override
72
    public ItemStack copy(ItemStack instance) {
73
        return instance.copy();
1✔
74
    }
75

76
    @Override
77
    public long getQuantity(ItemStack instance) {
78
        return instance.getCount();
1✔
79
    }
80

81
    @Override
82
    public ItemStack withQuantity(ItemStack instance, long quantity) {
83
        if (instance.getCount() == quantity) {
1✔
84
            return instance;
1✔
85
        }
86
        ItemStack copy = instance.copy();
1✔
87
        copy.setCount(IModHelpers.get().getBaseHelpers().castSafe(quantity));
1✔
88
        return copy;
1✔
89
    }
90

91
    @Override
92
    public long getMaximumQuantity() {
93
        return Integer.MAX_VALUE;
1✔
94
    }
95

96
    @Override
97
    public int conditionCompare(Integer a, Integer b) {
98
        return Integer.compare(a, b);
1✔
99
    }
100

101
    @Override
102
    public String localize(ItemStack instance) {
103
        return instance.getHoverName().getString();
×
104
    }
105

106
    @Override
107
    public MutableComponent getDisplayName(ItemStack instance) {
108
        return (MutableComponent) instance.getHoverName();
×
109
    }
110

111
    @Override
112
    public String toString(ItemStack instance) {
113
        return String.format("%s %s %s", BuiltInRegistries.ITEM.getKey(instance.getItem()), instance.getCount(), instance.getComponents());
1✔
114
    }
115

116
    @Override
117
    public int compare(ItemStack o1, ItemStack o2) {
118
        if (o1.isEmpty()) {
1✔
119
            if (o2.isEmpty()) {
1✔
120
                return 0;
1✔
121
            } else {
122
                return -1;
1✔
123
            }
124
        } else if (o2.isEmpty()) {
1✔
125
            return 1;
1✔
126
        } else if (o1.getItem() == o2.getItem()) {
1✔
127
            int c1 = o1.getCount();
1✔
128
            int c2 = o2.getCount();
1✔
129
            if (c1 == c2) {
1✔
130
                return IngredientHelpers.compareData(o1.getComponents(), o2.getComponents());
1✔
131
            }
132
            return c1 - c2;
1✔
133
        }
134
        return Item.getId(o1.getItem()) - Item.getId(o2.getItem());
1✔
135
    }
136
}
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