[1.21] Custom ingredients break shapeless crafting
Closed this issue ยท 3 comments
Shapeless recipes normally ignore empty slots in the crafting grid, but I've found that when you have a custom ingredient in the recipe for which requiresTesting() returns true empty slots become significant when trying to match shapeless recipes.
As a result you can only craft the recipe if all of the recipe's ingredients are lined up one after another in the grid with no gaps.
Eg.
With requiresTesting() == true
With requiresTesting() == false
Ingredient code:
public record ExclusiveIngredient(Ingredient include, Ingredient exclude) implements CustomIngredient {
public static final MapCodec<ExclusiveIngredient> CODEC = RecordCodecBuilder.mapCodec(i -> i.group(
Ingredient.DISALLOW_EMPTY_CODEC.fieldOf("include").forGetter(ExclusiveIngredient::include),
Ingredient.DISALLOW_EMPTY_CODEC.fieldOf("exclude").forGetter(ExclusiveIngredient::exclude)
).apply(i, ExclusiveIngredient::new));
public static final PacketCodec<RegistryByteBuf, ExclusiveIngredient> PACKET_CODEC = PacketCodec.tuple(
Ingredient.PACKET_CODEC, ExclusiveIngredient::include,
Ingredient.PACKET_CODEC, ExclusiveIngredient::exclude,
ExclusiveIngredient::new
);
@Override
public boolean test(ItemStack stack) {
return include.test(stack) && !exclude.test(stack);
}
@Override
public List<ItemStack> getMatchingStacks() {
return Arrays.stream(include.getMatchingStacks()).filter(this::test).toList();
}
@Override
public boolean requiresTesting() {
return false; // change this and restart game to test both cases
}
@Override
public CustomIngredientSerializer<?> getSerializer() {
return URecipes.EXCLUSIVE_INGREDIENT_SERIALIZER;
}
}
Recipe json:
{
"type": "minecraft:crafting_shapeless",
"category": "misc",
"group": "bed_sheet_convert",
"ingredients": [
{
"fabric:type": "unicopia:exclusive",
"exclude": {
"item": "unicopia:apple_bed_sheets"
},
"include": {
"tag": "unicopia:wool_bed_sheets"
}
},
{
"item": "minecraft:green_wool"
},
{
"item": "minecraft:lime_wool"
},
{
"item": "minecraft:green_wool"
},
{
"item": "minecraft:lime_wool"
},
{
"item": "minecraft:lime_wool"
},
{
"item": "minecraft:lime_wool"
},
{
"item": "minecraft:green_wool"
}
],
"result": {
"count": 2,
"id": "unicopia:apple_bed_sheets"
}
}
This was almost certainly fixed by #4287 by its change to ShapelessRecipeMixin. However, that PR targeted 1.21.4 and was not backported. If the same issue affects earlier versions, the fix can be backported.
The regression was introduced in 0af3f5a, which is a 1.21 porting commit, and so this issue affects 1.21-1.21.3. Do you need the fix on specifically 1.21 or is backporting it to only 1.21.1 sufficient?
The regression was introduced in 0af3f5a, which is a 1.21 porting commit, and so this issue affects 1.21-1.21.3. Do you need the fix on specifically 1.21 or is backporting it to only 1.21.1 sufficient?
My builds are technically supporting as far back as 1.21.0 but I believe everyone is using at least 1.21.1 so that will be fine.