• 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

0.0
/src/main/java/org/cyclops/integrateddynamics/gametest/integration/TestVariables.java
1
package org.cyclops.integrateddynamics.gametest.integration;
2

3
import com.google.common.collect.Lists;
4
import com.google.common.collect.Maps;
5
import com.google.gson.JsonParseException;
6
import net.minecraft.nbt.*;
7
import net.minecraft.world.item.Item;
8
import net.minecraft.world.item.ItemStack;
9
import net.minecraft.world.item.Items;
10
import net.minecraft.world.level.block.Blocks;
11
import net.minecraft.world.level.material.Fluids;
12
import net.neoforged.neoforge.fluids.FluidStack;
13
import org.cyclops.commoncapabilities.api.capability.itemhandler.ItemMatch;
14
import org.cyclops.commoncapabilities.api.capability.recipehandler.IRecipeDefinition;
15
import org.cyclops.commoncapabilities.api.capability.recipehandler.RecipeDefinition;
16
import org.cyclops.commoncapabilities.api.ingredient.*;
17
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueObjectTypeIngredients;
18
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueObjectTypeRecipe;
19
import org.cyclops.integrateddynamics.core.test.IntegrationTest;
20
import org.cyclops.integrateddynamics.core.test.TestHelpers;
21

22
import java.util.Collections;
23
import java.util.List;
24
import java.util.Map;
25

26
import static org.cyclops.integrateddynamics.core.test.TestHelpers.deserialize;
27
import static org.cyclops.integrateddynamics.core.test.TestHelpers.serialize;
28

29
/**
30
 * Test the different variable types.
31
 * @author rubensworks
32
 */
33
public class TestVariables {
×
34

35
    protected static Tag serializeStack(ItemStack itemStack) {
36
        return ItemStack.OPTIONAL_CODEC.encodeStart(NbtOps.INSTANCE, itemStack)
×
37
                .getOrThrow(JsonParseException::new);
×
38
    }
39

40
    protected static Tag serializeFluidStack(FluidStack fluidStack) {
41
        return FluidStack.OPTIONAL_CODEC.encodeStart(NbtOps.INSTANCE, fluidStack)
×
42
                .getOrThrow(JsonParseException::new);
×
43
    }
44

45
    @IntegrationTest
46
    public void testIngredientsType() {
47
        DummyVariableIngredients inull = new DummyVariableIngredients(ValueObjectTypeIngredients.ValueIngredients.of(null));
×
48
        TestHelpers.assertEqual(inull.getValue().getRawValue().orElse(null), null, "null value is null");
×
49

50
        IMixedIngredients ingredients1 =
×
51
                MixedIngredients.ofInstances(IngredientComponent.ITEMSTACK, Lists.newArrayList(
×
52
                        ItemStack.EMPTY, new ItemStack(Items.OAK_BOAT), new ItemStack(Blocks.STONE), ItemStack.EMPTY));
53
        DummyVariableIngredients i0 = new DummyVariableIngredients(ValueObjectTypeIngredients.ValueIngredients
×
54
                .of(ingredients1));
×
55
        TestHelpers.assertEqual(i0.getValue().getRawValue().get(), ingredients1, "ingredient value is ingredient");
×
56

57
        CompoundTag tag = new CompoundTag();
×
58
        ListTag itemStacks = new ListTag();
×
59
        CompoundTag itemStack1 = new CompoundTag();
×
60
        itemStack1.put("i", serializeStack(ItemStack.EMPTY));
×
61
        itemStacks.add(itemStack1);
×
62
        CompoundTag itemStack2 = new CompoundTag();
×
63
        itemStack2.put("i", serializeStack(new ItemStack(Items.OAK_BOAT)));
×
64
        itemStacks.add(itemStack2);
×
65
        CompoundTag itemStack3 = new CompoundTag();
×
66
        itemStack3.put("i", serializeStack(new ItemStack(Blocks.STONE)));
×
67
        itemStacks.add(itemStack3);
×
68
        CompoundTag itemStack4 = new CompoundTag();
×
69
        itemStack4.put("i", serializeStack(ItemStack.EMPTY));
×
70
        itemStacks.add(itemStack4);
×
71
        ListTag ingredientsList = new ListTag();
×
72
        CompoundTag ingredientsListItemStacks = new CompoundTag();
×
73
        ingredientsListItemStacks.putString("component", "minecraft:itemstack");
×
74
        ingredientsListItemStacks.put("instances", itemStacks);
×
75
        ingredientsList.add(ingredientsListItemStacks);
×
76
        tag.put("v", ingredientsList);
×
77

78
        CompoundTag tagRoot = new CompoundTag();
×
79
        tagRoot.put("v", tag);
×
80

81
        TestHelpers.assertEqual(serialize(o -> i0.getType().serialize(o, i0.getValue())), tagRoot, "Serialization is correct");
×
82
        TestHelpers.assertEqual(deserialize(tagRoot, i0.getType()::deserialize), i0.getValue(), "Deserialization is correct");
×
83
    }
×
84

85
    @IntegrationTest
86
    public void testRecipeType() {
87
        DummyVariableRecipe rnull = new DummyVariableRecipe(ValueObjectTypeRecipe.ValueRecipe.of(null));
×
88
        TestHelpers.assertEqual(rnull.getValue().getRawValue().orElse(null), null, "null value is null");
×
89

90
        List<List<IPrototypedIngredient<ItemStack, Integer>>> ingredientsIn = Lists.newArrayList();
×
91
        ingredientsIn.add(Collections.singletonList(new PrototypedIngredient<>(IngredientComponent.ITEMSTACK, ItemStack.EMPTY, ItemMatch.EXACT)));
×
92
        ingredientsIn.add(Collections.singletonList(new PrototypedIngredient<>(IngredientComponent.ITEMSTACK, new ItemStack(Items.OAK_BOAT), ItemMatch.EXACT)));
×
93
        ingredientsIn.add(Collections.singletonList(new PrototypedIngredient<>(IngredientComponent.ITEMSTACK, new ItemStack(Blocks.STONE), ItemMatch.EXACT)));
×
94
        ingredientsIn.add(Collections.singletonList(new PrototypedIngredient<>(IngredientComponent.ITEMSTACK, ItemStack.EMPTY, ItemMatch.EXACT)));
×
95

96
        Map<IngredientComponent<?, ?>, List<?>> ingredientsOut = Maps.newIdentityHashMap();
×
97
        ingredientsOut.put(IngredientComponent.ENERGY, Lists.newArrayList(777L));
×
98
        ingredientsOut.put(IngredientComponent.FLUIDSTACK, Lists.newArrayList(new FluidStack(Fluids.WATER, 123)));
×
99
        ingredientsOut.put(IngredientComponent.ITEMSTACK, Lists.newArrayList(new ItemStack(Items.OAK_BOAT), new ItemStack(Item.byBlock(Blocks.STONE))));
×
100
        DummyVariableIngredients iMainOut = new DummyVariableIngredients(ValueObjectTypeIngredients.ValueIngredients.of(
×
101
                new MixedIngredients(ingredientsOut)));
102
        IRecipeDefinition rawRecipe = RecipeDefinition.ofIngredients(
×
103
                IngredientComponent.ITEMSTACK,
104
                ingredientsIn,
105
                iMainOut.getValue().getRawValue().get()
×
106
        );
107
        DummyVariableRecipe r0 = new DummyVariableRecipe(ValueObjectTypeRecipe.ValueRecipe.of(rawRecipe));
×
108
        TestHelpers.assertEqual(r0.getValue().getRawValue().get(), rawRecipe, "recipe value is recipe");
×
109

110
        CompoundTag tag = new CompoundTag();
×
111

112
        CompoundTag output = new CompoundTag();
×
113
        ListTag outputList = new ListTag();
×
114
        output.put("v", outputList);
×
115
        ListTag energies = new ListTag();
×
116
        CompoundTag energy = new CompoundTag();
×
117
        energy.putLong("i", 777L);
×
118
        energies.add(energy);
×
119
        CompoundTag outputListEnergy = new CompoundTag();
×
120
        outputListEnergy.putString("component", "minecraft:energy");
×
121
        outputListEnergy.put("instances", energies);
×
122
        outputList.add(outputListEnergy);
×
123
        ListTag fluidStacks = new ListTag();
×
124
        CompoundTag fluidStack1 = new CompoundTag();
×
125
        fluidStack1.put("i", serializeFluidStack(new FluidStack(Fluids.WATER, 123)));
×
126
        fluidStacks.add(fluidStack1);
×
127
        CompoundTag outputListFluidStack = new CompoundTag();
×
128
        outputListFluidStack.putString("component", "minecraft:fluidstack");
×
129
        outputListFluidStack.put("instances", fluidStacks);
×
130
        outputList.add(outputListFluidStack);
×
131
        ListTag itemStacks = new ListTag();
×
132
        CompoundTag itemStack1 = new CompoundTag();
×
133
        itemStack1.put("i", serializeStack(new ItemStack(Items.OAK_BOAT)));
×
134
        itemStacks.add(itemStack1);
×
135
        CompoundTag itemStack2 = new CompoundTag();
×
136
        itemStack2.put("i", serializeStack(new ItemStack(Blocks.STONE)));
×
137
        itemStacks.add(itemStack2);
×
138
        CompoundTag outputListItemStack = new CompoundTag();
×
139
        outputListItemStack.putString("component", "minecraft:itemstack");
×
140
        outputListItemStack.put("instances", itemStacks);
×
141
        outputList.add(outputListItemStack);
×
142

143
        ListTag input = new ListTag();
×
144
        ListTag itemStacksIn = new ListTag();
×
145
        itemStacksIn.add(new CompoundTag());
×
146
        itemStacksIn.add(new CompoundTag());
×
147
        itemStacksIn.add(new CompoundTag());
×
148
        itemStacksIn.add(new CompoundTag());
×
149

150
        ListTag val0 = new ListTag();
×
151
        val0.add(serialize(o -> IPrototypedIngredient.serialize(o, ingredientsIn.get(0).get(0))));
×
152
        val0.getCompound(0).get().remove("ingredientComponent");
×
153
        CompoundTag val0l = new CompoundTag();
×
154
        val0l.put("l", val0);
×
155
        itemStacksIn.getCompound(0).get().put("val", val0l);
×
156
        itemStacksIn.getCompound(0).get().putByte("type", (byte) 0);
×
157

158
        ListTag val1 = new ListTag();
×
159
        val1.add(serialize(o -> IPrototypedIngredient.serialize(o, ingredientsIn.get(1).get(0))));
×
160
        val1.getCompound(0).get().remove("ingredientComponent");
×
161
        CompoundTag val1l = new CompoundTag();
×
162
        val1l.put("l", val1);
×
163
        itemStacksIn.getCompound(1).get().put("val", val1l);
×
164
        itemStacksIn.getCompound(1).get().putByte("type", (byte) 0);
×
165

166
        ListTag val2 = new ListTag();
×
167
        val2.add(serialize(o -> IPrototypedIngredient.serialize(o, ingredientsIn.get(2).get(0))));
×
168
        val2.getCompound(0).get().remove("ingredientComponent");
×
169
        CompoundTag val2l = new CompoundTag();
×
170
        val2l.put("l", val2);
×
171
        itemStacksIn.getCompound(2).get().put("val", val2l);
×
172
        itemStacksIn.getCompound(2).get().putByte("type", (byte) 0);
×
173

174
        ListTag val3 = new ListTag();
×
175
        val3.add(serialize(o -> IPrototypedIngredient.serialize(o, ingredientsIn.get(3).get(0))));
×
176
        val3.getCompound(0).get().remove("ingredientComponent");
×
177
        CompoundTag val3l = new CompoundTag();
×
178
        val3l.put("l", val3);
×
179
        itemStacksIn.getCompound(3).get().put("val", val3l);
×
180
        itemStacksIn.getCompound(3).get().putByte("type", (byte) 0);
×
181

182
        CompoundTag ingredientsListItemStacks = new CompoundTag();
×
183
        ingredientsListItemStacks.putString("component", "minecraft:itemstack");
×
184
        ingredientsListItemStacks.put("instances", itemStacksIn);
×
185
        input.add(ingredientsListItemStacks);
×
186

187
        int[] reusableBytes = new int[]{0, 0, 0, 0};
×
188
        IntArrayTag itemStacksReusable = new IntArrayTag(reusableBytes);
×
189
        ingredientsListItemStacks.put("reusable", itemStacksReusable);
×
190

191
        tag.put("output", output);
×
192
        tag.put("input", input);
×
193

194
        CompoundTag topTag = new CompoundTag();
×
195
        topTag.put("v", tag);
×
196

197
        TestHelpers.assertEqual(serialize(o -> r0.getType().serialize(o, r0.getValue())), topTag, "Serialization is correct");
×
198
        TestHelpers.assertEqual(deserialize(topTag, r0.getType()::deserialize), r0.getValue(), "Deserialization is correct");
×
199
    }
×
200

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