Skip to content

Commit a39d66c

Browse files
Fix dust disassembly recipes (#4456)
1 parent 7075fc0 commit a39d66c

4 files changed

Lines changed: 80 additions & 17 deletions

File tree

src/main/java/com/gregtechceu/gtceu/api/recipe/StrictShapedRecipe.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import net.minecraft.world.level.Level;
1717

1818
import com.google.gson.JsonObject;
19+
import lombok.Getter;
1920
import org.jetbrains.annotations.NotNull;
2021

2122
import java.util.Map;
@@ -28,13 +29,18 @@ public class StrictShapedRecipe extends ShapedRecipe {
2829

2930
public static final RecipeSerializer<StrictShapedRecipe> SERIALIZER = new Serializer();
3031

32+
@Getter
33+
private final boolean matchSize;
34+
3135
public StrictShapedRecipe(ResourceLocation id, String group, CraftingBookCategory category, int width, int height,
32-
NonNullList<Ingredient> recipeItems, ItemStack result) {
36+
NonNullList<Ingredient> recipeItems, ItemStack result, boolean matchSize) {
3337
super(id, group, category, width, height, recipeItems, result);
38+
this.matchSize = matchSize;
3439
}
3540

3641
@Override
3742
public boolean matches(CraftingContainer inv, Level level) {
43+
if (matchSize && (inv.getWidth() != this.getWidth() || inv.getHeight() != this.getHeight())) return false;
3844
for (int i = 0; i <= inv.getWidth() - this.getWidth(); ++i) {
3945
for (int j = 0; j <= inv.getHeight() - this.getHeight(); ++j) {
4046
if (this.matches(inv, i, j)) {
@@ -82,7 +88,9 @@ public StrictShapedRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
8288
int j = strings.length;
8389
NonNullList<Ingredient> nonNullList = ShapedRecipeAccessor.callDissolvePattern(strings, map, i, j);
8490
ItemStack itemStack = StrictShapedRecipe.itemStackFromJson(GsonHelper.getAsJsonObject(json, "result"));
85-
return new StrictShapedRecipe(recipeId, string, craftingBookCategory, i, j, nonNullList, itemStack);
91+
boolean matchSize = json.get("matchSize").getAsBoolean();
92+
return new StrictShapedRecipe(recipeId, string, craftingBookCategory, i, j, nonNullList, itemStack,
93+
matchSize);
8694
}
8795

8896
@Override
@@ -94,7 +102,9 @@ public StrictShapedRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf
94102
NonNullList<Ingredient> nonNullList = NonNullList.withSize(i * j, Ingredient.EMPTY);
95103
nonNullList.replaceAll(ignored -> Ingredient.fromNetwork(buffer));
96104
ItemStack itemStack = buffer.readItem();
97-
return new StrictShapedRecipe(recipeId, string, craftingBookCategory, i, j, nonNullList, itemStack);
105+
boolean matchSize = buffer.readBoolean();
106+
return new StrictShapedRecipe(recipeId, string, craftingBookCategory, i, j, nonNullList, itemStack,
107+
matchSize);
98108
}
99109

100110
@Override
@@ -107,6 +117,7 @@ public void toNetwork(FriendlyByteBuf buffer, StrictShapedRecipe recipe) {
107117
ingredient.toNetwork(buffer);
108118
}
109119
buffer.writeItem(((ShapedRecipeAccessor) recipe).getResult());
120+
buffer.writeBoolean(recipe.matchSize);
110121
}
111122
}
112123
}

src/main/java/com/gregtechceu/gtceu/data/recipe/VanillaRecipeHelper.java

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,31 +224,31 @@ public static void addShapedNBTClearingRecipe(Consumer<FinishedRecipe> provider,
224224
}
225225

226226
/**
227-
* @see #addShapedRecipe(Consumer, boolean, boolean, ResourceLocation, ItemStack, Object...)
227+
* @see #addShapedRecipe(Consumer, boolean, boolean, boolean, ResourceLocation, ItemStack, Object...)
228228
*/
229229
public static void addShapedRecipe(Consumer<FinishedRecipe> provider, @NotNull String regName,
230230
@NotNull ItemStack result, @NotNull Object... recipe) {
231231
addShapedRecipe(provider, GTCEu.id(regName), result, recipe);
232232
}
233233

234234
/**
235-
* @see #addShapedRecipe(Consumer, boolean, boolean, ResourceLocation, ItemStack, Object...)
235+
* @see #addShapedRecipe(Consumer, boolean, boolean, boolean, ResourceLocation, ItemStack, Object...)
236236
*/
237237
public static void addShapedRecipe(Consumer<FinishedRecipe> provider, @NotNull ResourceLocation regName,
238238
@NotNull ItemStack result, @NotNull Object... recipe) {
239239
addShapedRecipe(provider, false, regName, result, recipe);
240240
}
241241

242242
/**
243-
* @see #addShapedRecipe(Consumer, boolean, boolean, ResourceLocation, ItemStack, Object...)
243+
* @see #addShapedRecipe(Consumer, boolean, boolean, boolean, ResourceLocation, ItemStack, Object...)
244244
*/
245245
public static void addStrictShapedRecipe(Consumer<FinishedRecipe> provider, @NotNull String regName,
246246
@NotNull ItemStack result, @NotNull Object... recipe) {
247247
addStrictShapedRecipe(provider, GTCEu.id(regName), result, recipe);
248248
}
249249

250250
/**
251-
* @see #addShapedRecipe(Consumer, boolean, boolean, ResourceLocation, ItemStack, Object...)
251+
* @see #addShapedRecipe(Consumer, boolean, boolean, boolean, ResourceLocation, ItemStack, Object...)
252252
*/
253253
public static void addStrictShapedRecipe(Consumer<FinishedRecipe> provider, boolean setMaterialInfoData,
254254
@NotNull String regName,
@@ -257,13 +257,38 @@ public static void addStrictShapedRecipe(Consumer<FinishedRecipe> provider, bool
257257
}
258258

259259
/**
260-
* @see #addShapedRecipe(Consumer, boolean, boolean, ResourceLocation, ItemStack, Object...)
260+
* @see #addShapedRecipe(Consumer, boolean, boolean, boolean, ResourceLocation, ItemStack, Object...)
261261
*/
262262
public static void addStrictShapedRecipe(Consumer<FinishedRecipe> provider, @NotNull ResourceLocation regName,
263263
@NotNull ItemStack result, @NotNull Object... recipe) {
264264
addStrictShapedRecipe(provider, false, regName, result, recipe);
265265
}
266266

267+
/**
268+
* @see #addShapedRecipe(Consumer, boolean, boolean, boolean, ResourceLocation, ItemStack, Object...)
269+
*/
270+
public static void addStrictSizeShapedRecipe(Consumer<FinishedRecipe> provider, @NotNull String regName,
271+
@NotNull ItemStack result, @NotNull Object... recipe) {
272+
addStrictSizeShapedRecipe(provider, GTCEu.id(regName), result, recipe);
273+
}
274+
275+
/**
276+
* @see #addShapedRecipe(Consumer, boolean, boolean, boolean, ResourceLocation, ItemStack, Object...)
277+
*/
278+
public static void addStrictSizeShapedRecipe(Consumer<FinishedRecipe> provider, boolean setMaterialInfoData,
279+
@NotNull String regName,
280+
@NotNull ItemStack result, @NotNull Object... recipe) {
281+
addStrictSizeShapedRecipe(provider, setMaterialInfoData, GTCEu.id(regName), result, recipe);
282+
}
283+
284+
/**
285+
* @see #addShapedRecipe(Consumer, boolean, boolean, boolean, ResourceLocation, ItemStack, Object...)
286+
*/
287+
public static void addStrictSizeShapedRecipe(Consumer<FinishedRecipe> provider, @NotNull ResourceLocation regName,
288+
@NotNull ItemStack result, @NotNull Object... recipe) {
289+
addStrictSizeShapedRecipe(provider, false, regName, result, recipe);
290+
}
291+
267292
/**
268293
* Adds Shaped Crafting Recipes.
269294
* <p/>
@@ -284,17 +309,20 @@ public static void addStrictShapedRecipe(Consumer<FinishedRecipe> provider, @Not
284309
* <li>{@code 'w'} - {@code craftingToolWrench}</li>
285310
* <li>{@code 'x'} - {@code craftingToolWireCutter}</li>
286311
* </ul>
287-
*
312+
*
288313
* @param setMaterialInfoData whether to add material decomposition information to the recipe output
314+
*
315+
* @param matchSize
289316
* @param regName the registry name for the recipe
290317
* @param result the output for the recipe
291318
* @param recipe the contents of the recipe
292319
*/
293320
public static void addShapedRecipe(Consumer<FinishedRecipe> provider, boolean setMaterialInfoData, boolean isStrict,
294-
@NotNull ResourceLocation regName, @NotNull ItemStack result,
321+
boolean matchSize, @NotNull ResourceLocation regName, @NotNull ItemStack result,
295322
@NotNull Object... recipe) {
296323
var builder = new ShapedRecipeBuilder(regName).output(result);
297324
builder.isStrict(isStrict);
325+
builder.matchSize(matchSize);
298326
final CharSet tools = ToolHelper.getToolSymbols();
299327
CharSet foundTools = new CharArraySet(9);
300328
for (int i = 0; i < recipe.length; i++) {
@@ -354,29 +382,38 @@ public static void addShapedRecipe(Consumer<FinishedRecipe> provider, boolean se
354382
}
355383

356384
/**
357-
* @see #addShapedRecipe(Consumer, boolean, boolean, ResourceLocation, ItemStack, Object...)
385+
* @see #addShapedRecipe(Consumer, boolean, boolean, boolean, ResourceLocation, ItemStack, Object...)
358386
*/
359387
public static void addShapedRecipe(Consumer<FinishedRecipe> provider, boolean setMaterialInfoData,
360388
@NotNull String regName, @NotNull ItemStack result, @NotNull Object... recipe) {
361389
addShapedRecipe(provider, setMaterialInfoData, GTCEu.id(regName), result, recipe);
362390
}
363391

364392
/**
365-
* @see #addShapedRecipe(Consumer, boolean, boolean, ResourceLocation, ItemStack, Object...)
393+
* @see #addShapedRecipe(Consumer, boolean, boolean, boolean, ResourceLocation, ItemStack, Object...)
366394
*/
367395
public static void addShapedRecipe(Consumer<FinishedRecipe> provider, boolean setMaterialInfoData,
368396
@NotNull ResourceLocation regName, @NotNull ItemStack result,
369397
@NotNull Object... recipe) {
370-
addShapedRecipe(provider, setMaterialInfoData, false, regName, result, recipe);
398+
addShapedRecipe(provider, setMaterialInfoData, false, false, regName, result, recipe);
371399
}
372400

373401
/**
374-
* @see #addShapedRecipe(Consumer, boolean, boolean, ResourceLocation, ItemStack, Object...)
402+
* @see #addShapedRecipe(Consumer, boolean, boolean, boolean, ResourceLocation, ItemStack, Object...)
375403
*/
376404
public static void addStrictShapedRecipe(Consumer<FinishedRecipe> provider, boolean setMaterialInfoData,
377405
@NotNull ResourceLocation regName, @NotNull ItemStack result,
378406
@NotNull Object... recipe) {
379-
addShapedRecipe(provider, setMaterialInfoData, true, regName, result, recipe);
407+
addShapedRecipe(provider, setMaterialInfoData, true, false, regName, result, recipe);
408+
}
409+
410+
/**
411+
* @see #addShapedRecipe(Consumer, boolean, boolean, boolean, ResourceLocation, ItemStack, Object...)
412+
*/
413+
public static void addStrictSizeShapedRecipe(Consumer<FinishedRecipe> provider, boolean setMaterialInfoData,
414+
@NotNull ResourceLocation regName, @NotNull ItemStack result,
415+
@NotNull Object... recipe) {
416+
addShapedRecipe(provider, setMaterialInfoData, true, true, regName, result, recipe);
380417
}
381418

382419
public static void addShapelessRecipe(Consumer<FinishedRecipe> provider, @NotNull String regName,

src/main/java/com/gregtechceu/gtceu/data/recipe/builder/ShapedRecipeBuilder.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class ShapedRecipeBuilder extends Builder<Ingredient, ShapedRecipeBuilder
3030
protected ResourceLocation id;
3131
protected String group;
3232
protected boolean isStrict;
33+
protected boolean matchSize;
3334

3435
public ShapedRecipeBuilder(@Nullable ResourceLocation id) {
3536
this.id = id;
@@ -97,6 +98,12 @@ public ShapedRecipeBuilder isStrict(boolean isStrict) {
9798
return this;
9899
}
99100

101+
public ShapedRecipeBuilder matchSize(boolean matchSize) {
102+
if (matchSize) this.isStrict = true;
103+
this.matchSize = matchSize;
104+
return this;
105+
}
106+
100107
@Override
101108
public ShapedRecipeBuilder shallowCopy() {
102109
var builder = super.shallowCopy();
@@ -125,6 +132,8 @@ public void toJson(JsonObject json) {
125132
json.add("key", key);
126133
}
127134

135+
json.addProperty("matchSize", matchSize);
136+
128137
if (output.isEmpty()) {
129138
GTCEu.LOGGER.error("shaped recipe {} output is empty", id);
130139
throw new IllegalArgumentException(id + ": output items is empty");

src/main/java/com/gregtechceu/gtceu/data/recipe/generated/MaterialRecipeHandler.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,12 @@ private static void processSmallDust(@NotNull Consumer<FinishedRecipe> provider,
254254
ItemStack smallDustStack = ChemicalHelper.get(dustSmall, material);
255255
ItemStack dustStack = ChemicalHelper.get(dust, material);
256256

257-
VanillaRecipeHelper.addStrictShapedRecipe(provider,
257+
VanillaRecipeHelper.addStrictSizeShapedRecipe(provider,
258258
String.format("small_dust_disassembling_%s", material.getName()),
259259
smallDustStack.copyWithCount(4), " X", " ", 'X', new MaterialEntry(dust, material));
260+
VanillaRecipeHelper.addStrictSizeShapedRecipe(provider,
261+
String.format("small_dust_disassembling_3x3_%s", material.getName()),
262+
smallDustStack.copyWithCount(4), " X ", " ", " ", 'X', new MaterialEntry(dust, material));
260263
VanillaRecipeHelper.addShapedRecipe(provider, String.format("small_dust_assembling_%s", material.getName()),
261264
dustStack, "XX", "XX", 'X', new MaterialEntry(dustSmall, material));
262265

@@ -282,9 +285,12 @@ private static void processTinyDust(@NotNull Consumer<FinishedRecipe> provider,
282285
ItemStack tinyDustStack = ChemicalHelper.get(dustTiny, material);
283286
ItemStack dustStack = ChemicalHelper.get(dust, material);
284287

285-
VanillaRecipeHelper.addStrictShapedRecipe(provider,
288+
VanillaRecipeHelper.addStrictSizeShapedRecipe(provider,
286289
String.format("tiny_dust_disassembling_%s", material.getName()),
287290
tinyDustStack.copyWithCount(9), "X ", " ", 'X', new MaterialEntry(dust, material));
291+
VanillaRecipeHelper.addStrictSizeShapedRecipe(provider,
292+
String.format("tiny_dust_disassembling_3x3_%s", material.getName()),
293+
tinyDustStack.copyWithCount(9), "X ", " ", " ", 'X', new MaterialEntry(dust, material));
288294
VanillaRecipeHelper.addShapedRecipe(provider, String.format("tiny_dust_assembling_%s", material.getName()),
289295
dustStack, "XXX", "XXX", "XXX", 'X', new MaterialEntry(dustTiny, material));
290296

0 commit comments

Comments
 (0)