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

CyclopsMC / CommonCapabilities / #479006705

21 Mar 2024 03:43PM UTC coverage: 39.629% (-0.3%) from 39.919%
#479006705

push

github

rubensworks
Fix failing unit tests

877 of 2213 relevant lines covered (39.63%)

0.4 hits per line

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

94.44
/src/main/java/org/cyclops/commoncapabilities/ingredient/IngredientSerializerItemStack.java
1
package org.cyclops.commoncapabilities.ingredient;
2

3
import com.google.gson.JsonParseException;
4
import net.minecraft.nbt.CompoundTag;
5
import net.minecraft.nbt.IntTag;
6
import net.minecraft.nbt.NbtOps;
7
import net.minecraft.nbt.Tag;
8
import net.minecraft.world.item.ItemStack;
9
import org.cyclops.commoncapabilities.api.ingredient.IIngredientSerializer;
10

11
/**
12
 * Serializer for ItemStacks.
13
 * @author rubensworks
14
 */
15
public class IngredientSerializerItemStack implements IIngredientSerializer<ItemStack, Integer> {
1✔
16
    @Override
17
    public Tag serializeInstance(ItemStack instance) {
18
        Tag tag = ItemStack.CODEC.encodeStart(NbtOps.INSTANCE, instance)
1✔
19
                .getOrThrow(false, JsonParseException::new);
1✔
20
        if (instance.getCount() > 127) {
1✔
21
            ((CompoundTag) tag).putInt("ExtendedCount", instance.getCount());
1✔
22
            ((CompoundTag) tag).putByte("Count", (byte)1);
1✔
23
        }
24
        return tag;
1✔
25
    }
26

27
    @Override
28
    public ItemStack deserializeInstance(Tag tag) throws IllegalArgumentException {
29
        ItemStack itemStack = ItemStack.CODEC.parse(NbtOps.INSTANCE, tag)
1✔
30
                .getOrThrow(false, JsonParseException::new);
1✔
31

32

33
        if (!(tag instanceof CompoundTag stackTag)) {
1✔
34
            throw new IllegalArgumentException("This deserializer only accepts NBTTagCompound");
×
35
        }
36
        if (stackTag.contains("ExtendedCount", Tag.TAG_INT)) {
1✔
37
            itemStack.setCount(stackTag.getInt("ExtendedCount"));
1✔
38
        }
39

40
        return itemStack;
1✔
41
    }
42

43
    @Override
44
    public Tag serializeCondition(Integer matchCondition) {
45
        return IntTag.valueOf(matchCondition);
1✔
46
    }
47

48
    @Override
49
    public Integer deserializeCondition(Tag tag) throws IllegalArgumentException {
50
        if (!(tag instanceof IntTag)) {
1✔
51
            throw new IllegalArgumentException("This deserializer only accepts NBTTagInt");
1✔
52
        }
53
        return ((IntTag) tag).getAsInt();
1✔
54
    }
55
}
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