Skip to content

Commit 24515a3

Browse files
committed
Recipe loading: Implement output itemstack loading
1 parent d351bbd commit 24515a3

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

src/main/java/com/robotgryphon/compactcrafting/recipes/MiniaturizationRecipe.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
import net.minecraft.util.math.vector.Vector3d;
1616
import net.minecraft.world.IWorldReader;
1717

18-
import java.util.Arrays;
19-
import java.util.HashMap;
20-
import java.util.Map;
21-
import java.util.Optional;
18+
import java.util.*;
2219
import java.util.stream.Stream;
2320

2421
public class MiniaturizationRecipe {
@@ -240,7 +237,14 @@ public ResourceLocation getRegistryName() {
240237
return registryName;
241238
}
242239

243-
public void setRegistryName(ResourceLocation registryName) {
244-
this.registryName = registryName;
240+
public void addOutput(ItemStack itemStack) {
241+
List<ItemStack> oTmp = new ArrayList<>(Arrays.asList(this.outputs));
242+
oTmp.add(itemStack);
243+
244+
this.outputs = oTmp.toArray(new ItemStack[0]);
245+
}
246+
247+
public int getNumberComponents() {
248+
return this.components.size();
245249
}
246250
}

src/main/java/com/robotgryphon/compactcrafting/recipes/json/MiniaturizationPatternLoader.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,17 @@ protected void apply(Map<ResourceLocation, JsonElement> objectIn, IResourceManag
4949
if(!layersLoaded)
5050
continue;
5151

52-
loadComponents(root, recipe);
52+
// Load Components - If nothing was loaded, skip the recipe
53+
boolean componentsLoaded = loadComponents(root, recipe);
54+
if(!componentsLoaded || recipe.getNumberComponents() == 0)
55+
continue;
5356

54-
loadCatalyst(recipe, root);
57+
boolean catalystsLoaded = loadCatalyst(recipe, root);
58+
if(!catalystsLoaded)
59+
continue;
5560

5661
loadOutputs(recipe, root);
57-
62+
5863
MiniaturizationRecipeManager.add(rl, recipe);
5964
}
6065
}
@@ -66,7 +71,19 @@ private boolean loadOutputs(MiniaturizationRecipe recipe, JsonObject root) {
6671
}
6772

6873
JsonArray outputs = root.getAsJsonArray("outputs");
69-
return false;
74+
for(JsonElement output : outputs) {
75+
if(!output.isJsonObject())
76+
continue;
77+
78+
JsonObject op = output.getAsJsonObject();
79+
Optional<ItemStack> oStack = RecipeLoaderUtil.getItemStack(op);
80+
if(!oStack.isPresent())
81+
continue;
82+
83+
recipe.addOutput(oStack.get());
84+
}
85+
86+
return true;
7087
}
7188

7289
private boolean loadCatalyst(MiniaturizationRecipe recipe, JsonObject root) {
@@ -112,23 +129,25 @@ private boolean loadLayers(MiniaturizationRecipe recipe, JsonObject root) {
112129
return true;
113130
}
114131

115-
private void loadComponents(JsonObject root, MiniaturizationRecipe recipe) {
132+
private boolean loadComponents(JsonObject root, MiniaturizationRecipe recipe) {
116133
JsonObject components = root.get("components").getAsJsonObject();
117134
if(components.size() == 0) {
118135
throw new JsonParseException("Error: No components defined.");
119136
}
120137

121-
components.entrySet().forEach(component -> {
138+
for(Map.Entry<String, JsonElement> component : components.entrySet()) {
122139
String key = component.getKey();
123140
Optional<BlockState> state = RecipeLoaderUtil.extractComponentDefinition(key, component.getValue());
124141

125142
if(key.isEmpty() || !state.isPresent()) {
126143
CompactCrafting.LOGGER.warn("Failed to process blockstate for component {}; definition not found.", key);
127-
return;
144+
continue;
128145
}
129146

130147
recipe.addComponent(key, state.get());
131-
});
148+
}
149+
150+
return true;
132151
}
133152

134153
}

0 commit comments

Comments
 (0)