Patch CoFH Core to not rely on Ingredient.itemStacks

This commit is contained in:
embeddedt 2025-05-02 17:25:20 -04:00
parent eed320b055
commit 7398b48345
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
2 changed files with 46 additions and 0 deletions

View File

@ -60,6 +60,7 @@ dependencies {
modCompileOnly("curse.maven:supermartijncore-454372:4455391")
modCompileOnly("vazkii.patchouli:Patchouli:1.19.2-77")
modCompileOnly("curse.maven:cofhcore-69162:5374122")
// runtime remapping at home
for (extraModJar in fileTree(dir: extraModsDir, include: '*.jar')) {

View File

@ -0,0 +1,45 @@
package org.embeddedt.modernfix.forge.mixin.perf.faster_ingredients;
import cofh.lib.util.crafting.IngredientWithCount;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import org.embeddedt.modernfix.annotation.RequiresMod;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import java.util.stream.Stream;
@Mixin(IngredientWithCount.class)
@RequiresMod("cofh_core")
public class CofhIngredientWithCountMixin extends Ingredient {
@Shadow @Final private Ingredient wrappedIngredient;
@Shadow @Final private int count;
@Unique
private ItemStack[] mfix$itemStacksWithAdjustedCount;
protected CofhIngredientWithCountMixin(Stream<? extends Value> values) {
super(values);
}
/**
* @author embeddedt
* @reason reimplement in a way that doesn't rely on the itemStacks implementation detail of the wrapped ingredient
*/
@Overwrite
public ItemStack[] getItems() {
if (this.mfix$itemStacksWithAdjustedCount == null) {
ItemStack[] originalItems = this.wrappedIngredient.getItems();
var newItems = new ItemStack[originalItems.length];
for (int i = 0; i < originalItems.length; i++) {
newItems[i] = originalItems[i].copy();
newItems[i].setCount(this.count);
}
this.mfix$itemStacksWithAdjustedCount = newItems;
}
return this.mfix$itemStacksWithAdjustedCount;
}
}