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

CyclopsMC / IntegratedDynamics / 20379848724

19 Dec 2025 07:04PM UTC coverage: 45.108% (-0.05%) from 45.158%
20379848724

push

github

rubensworks
Bump mod version

2611 of 8556 branches covered (30.52%)

Branch coverage included in aggregate %.

11852 of 23507 relevant lines covered (50.42%)

2.39 hits per line

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

6.45
/src/main/java/org/cyclops/integrateddynamics/core/evaluate/variable/ValueObjectTypeRecipe.java
1
package org.cyclops.integrateddynamics.core.evaluate.variable;
2

3
import com.google.common.collect.Iterables;
4
import com.google.gson.JsonParseException;
5
import com.mojang.blaze3d.vertex.PoseStack;
6
import lombok.ToString;
7
import net.minecraft.client.Minecraft;
8
import net.minecraft.client.multiplayer.ClientLevel;
9
import net.minecraft.client.renderer.MultiBufferSource;
10
import net.minecraft.client.resources.model.BakedModel;
11
import net.minecraft.nbt.CompoundTag;
12
import net.minecraft.nbt.Tag;
13
import net.minecraft.network.chat.Component;
14
import net.minecraft.network.chat.MutableComponent;
15
import net.minecraft.world.entity.LivingEntity;
16
import net.minecraft.world.item.ItemDisplayContext;
17
import net.minecraft.world.item.ItemStack;
18
import net.neoforged.api.distmarker.Dist;
19
import net.neoforged.api.distmarker.OnlyIn;
20
import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions;
21
import org.cyclops.commoncapabilities.api.capability.recipehandler.IPrototypedIngredientAlternatives;
22
import org.cyclops.commoncapabilities.api.capability.recipehandler.IRecipeDefinition;
23
import org.cyclops.commoncapabilities.api.ingredient.IPrototypedIngredient;
24
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
25
import org.cyclops.cyclopscore.helper.MinecraftHelpers;
26
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
27
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueTypeNamed;
28
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueTypeNullable;
29
import org.cyclops.integrateddynamics.api.evaluate.variable.ValueDeseralizationContext;
30
import org.cyclops.integrateddynamics.api.ingredient.IIngredientComponentHandler;
31
import org.cyclops.integrateddynamics.core.ingredient.IngredientComponentHandlers;
32
import org.cyclops.integrateddynamics.core.logicprogrammer.ValueTypeLPElementBase;
33
import org.cyclops.integrateddynamics.core.logicprogrammer.ValueTypeRecipeLPElement;
34

35
import javax.annotation.Nullable;
36
import java.util.List;
37

38
/**
39
 * Value type with values that are recipes.
40
 * @author rubensworks
41
 */
42
public class ValueObjectTypeRecipe extends ValueObjectTypeBase<ValueObjectTypeRecipe.ValueRecipe> implements
43
        IValueTypeNamed<ValueObjectTypeRecipe.ValueRecipe>, IValueTypeNullable<ValueObjectTypeRecipe.ValueRecipe> {
44

45
    public ValueObjectTypeRecipe() {
46
        super("recipe", ValueObjectTypeRecipe.ValueRecipe.class);
4✔
47
    }
1✔
48

49
    @Override
50
    public ValueRecipe getDefault() {
51
        return ValueRecipe.of(null);
×
52
    }
53

54
    @Override
55
    public MutableComponent toCompactString(ValueRecipe value) {
56
        if (value.getRawValue().isPresent()) {
×
57
            IRecipeDefinition recipe = value.getRawValue().get();
×
58
            MutableComponent sb = Component.literal("");
×
59

60
            sb.append(ValueObjectTypeIngredients.ingredientsToTextComponent(recipe.getOutput()));
×
61
            sb.append(Component.literal(" <- "));
×
62
            boolean first = true;
×
63

64
            for (IngredientComponent<?, ?> component : recipe.getInputComponents()) {
×
65
                IIngredientComponentHandler handler = IngredientComponentHandlers.REGISTRY.getComponentHandler(component);
×
66
                int i = 0;
×
67
                for (IPrototypedIngredientAlternatives<?, ?> instances : recipe.getInputs(component)) {
×
68
                    IPrototypedIngredient<?, ?> prototypedIngredient = Iterables.getFirst(instances.getAlternatives(), null);
×
69
                    IValue v;
70
                    if (prototypedIngredient == null) {
×
71
                        v  = handler.getValueType().getDefault();
×
72
                    } else {
73
                        v = handler.toValue(prototypedIngredient.getPrototype());
×
74
                    }
75
                    if (!first) {
×
76
                        sb.append(Component.literal(", "));
×
77
                    } else {
78
                        first = false;
×
79
                    }
80
                    sb.append(handler.toCompactString(v));
×
81
                    if (recipe.isInputReusable(component, i)) {
×
82
                        sb.append("*");
×
83
                    }
84
                    i++;
×
85
                }
×
86
            }
×
87
            return sb;
×
88
        }
89
        return Component.literal("");
×
90
    }
91

92
    @Override
93
    public Tag serialize(ValueDeseralizationContext valueDeseralizationContext, ValueRecipe value) {
94
        if(!value.getRawValue().isPresent()) return new CompoundTag();
×
95
        return IRecipeDefinition.serialize(valueDeseralizationContext.holderLookupProvider(), value.getRawValue().get());
×
96
    }
97

98
    @Override
99
    public ValueRecipe deserialize(ValueDeseralizationContext valueDeseralizationContext, Tag value) {
100
        if (value.getId() == Tag.TAG_END || (value.getId() == Tag.TAG_COMPOUND && ((CompoundTag) value).isEmpty())) {
×
101
            return ValueRecipe.of(null);
×
102
        }
103
        try {
104
            return ValueRecipe.of(IRecipeDefinition.deserialize(valueDeseralizationContext.holderLookupProvider(), (CompoundTag) value));
×
105
        } catch (IllegalArgumentException | JsonParseException e) {
×
106
            return ValueRecipe.of(null);
×
107
        }
108
    }
109

110
    @Override
111
    public String getName(ValueRecipe a) {
112
        return toCompactString(a).getString();
×
113
    }
114

115
    @Override
116
    public boolean isNull(ValueRecipe a) {
117
        return !a.getRawValue().isPresent();
×
118
    }
119

120
    @Override
121
    public ValueTypeLPElementBase createLogicProgrammerElement() {
122
        return new ValueTypeRecipeLPElement();
×
123
    }
124

125
    @Nullable
126
    @Override
127
    @OnlyIn(Dist.CLIENT)
128
    public BakedModel getVariableItemOverrideModel(ValueRecipe value, BakedModel model, ItemStack stack, @Nullable ClientLevel world, @Nullable LivingEntity livingEntity) {
129
        if (!MinecraftHelpers.isShifted()) {
×
130
            return null;
×
131
        }
132
        return value.getRawValue()
×
133
                .map((recipe) -> {
×
134
                    List<ItemStack> itemStacks = recipe.getOutput().getInstances(IngredientComponent.ITEMSTACK);
×
135
                    if (!itemStacks.isEmpty()) {
×
136
                        return Minecraft.getInstance().getItemRenderer().getModel(itemStacks.get(0), world, livingEntity, 0);
×
137
                    }
138
                    return null;
×
139
                })
140
                .orElse(null);
×
141
    }
142

143
    @Override
144
    @OnlyIn(Dist.CLIENT)
145
    public void renderISTER(ValueRecipe value, ItemStack stack, ItemDisplayContext transformType, PoseStack matrixStack, MultiBufferSource buffer, int combinedLight, int combinedOverlay) {
146
        if (MinecraftHelpers.isShifted()) {
×
147
            value.getRawValue()
×
148
                    .ifPresent((recipe) -> {
×
149
                        List<ItemStack> itemStacks = recipe.getOutput().getInstances(IngredientComponent.ITEMSTACK);
×
150
                        if (!itemStacks.isEmpty()) {
×
151
                            ItemStack actualStack = itemStacks.get(0);
×
152
                            IClientItemExtensions.of(actualStack)
×
153
                                    .getCustomRenderer()
×
154
                                    .renderByItem(actualStack, transformType, matrixStack, buffer, combinedLight, combinedOverlay);
×
155
                        }
156
                    });
×
157
        }
158
    }
×
159

160
    @ToString
×
161
    public static class ValueRecipe extends ValueOptionalBase<IRecipeDefinition> {
162

163
        private ValueRecipe(IRecipeDefinition recipe) {
164
            super(ValueTypes.OBJECT_RECIPE, recipe);
4✔
165
        }
1✔
166

167
        public static ValueRecipe of(IRecipeDefinition recipe) {
168
            return new ValueRecipe(recipe);
5✔
169
        }
170

171
        @Override
172
        protected boolean isEqual(IRecipeDefinition a, IRecipeDefinition b) {
173
            return a.equals(b);
4✔
174
        }
175
    }
176

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