diff --git a/src/main/java/io/pyke/vitri/finorza/inference/mixin/ClientRecipeBookMixin.java b/src/main/java/io/pyke/vitri/finorza/inference/mixin/ClientRecipeBookMixin.java index e22cf4e..166a538 100644 --- a/src/main/java/io/pyke/vitri/finorza/inference/mixin/ClientRecipeBookMixin.java +++ b/src/main/java/io/pyke/vitri/finorza/inference/mixin/ClientRecipeBookMixin.java @@ -1,37 +1,45 @@ package io.pyke.vitri.finorza.inference.mixin; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Map; +import java.util.*; +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import net.minecraft.client.ClientRecipeBook; import net.minecraft.client.RecipeBookCategories; import net.minecraft.world.item.crafting.Recipe; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import org.spongepowered.asm.mixin.Overwrite; @Mixin(ClientRecipeBook.class) public class ClientRecipeBookMixin { - @Inject( - method = "categorizeAndGroupRecipes(Ljava/lang/Iterable;)Ljava/util/Map;", - at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Ljava/util/ArrayList;add(Ljava/lang/Object;)Z"), - locals = LocalCapture.CAPTURE_FAILHARD - ) - private static void injectCategorize( - Iterable> iterable, - CallbackInfoReturnable>>>> cir, - ArrayList> list - ) { - list.sort(Comparator.comparing(r -> r.getResultItem().toString())); - } - - @Inject(method = "categorizeAndGroupRecipes(Ljava/lang/Iterable;)Ljava/util/Map;", at = @At("RETURN"), cancellable = true) - private static void injectSorted(CallbackInfoReturnable>>>> cir) { - final Map>>> map = cir.getReturnValue(); + /** + * @author + * @reason + */ + @Overwrite + private static Map>>> categorizeAndGroupRecipes(Iterable> iterable) { + HashMap>>> map = Maps.newHashMap(); + HashBasedTable table = HashBasedTable.create(); + for (Recipe recipe : iterable) { + if (recipe.isSpecial()) continue; + RecipeBookCategories recipeBookCategories2 = ClientRecipeBook.getCategory(recipe); + String string = recipe.getGroup(); + if (string.isEmpty()) { + map.computeIfAbsent(recipeBookCategories2, recipeBookCategories -> Lists.newArrayList()).add( + ImmutableList.of(recipe)); + continue; + } + ArrayList> list = (ArrayList>)table.get((Object)recipeBookCategories2, string); + if (list == null) { + list = Lists.newArrayList(); + table.put(recipeBookCategories2, string, list); + map.computeIfAbsent(recipeBookCategories2, recipeBookCategories -> Lists.newArrayList()).add(list); + } + list.add(recipe); + list.sort(Comparator.comparing(r -> r.getResultItem().toString())); + } for (final List>> recipeList : map.values()) { for (final List> subList : recipeList) { if (subList.size() > 1) { @@ -40,6 +48,6 @@ private static void injectSorted(CallbackInfoReturnable r.get(0).getResultItem().getItem().toString())); } - cir.setReturnValue(map); + return map; } } diff --git a/src/main/resources/finorza.accesswidener b/src/main/resources/finorza.accesswidener index a8d32d4..7e83659 100644 --- a/src/main/resources/finorza.accesswidener +++ b/src/main/resources/finorza.accesswidener @@ -2,6 +2,7 @@ accessWidener v2 named accessible method net/minecraft/server/MinecraftServer haveTime ()Z accessible method net/minecraft/server/MinecraftServer waitUntilNextTick ()V +accessible method net/minecraft/client/ClientRecipeBook getCategory (Lnet/minecraft/world/item/crafting/Recipe;)Lnet/minecraft/client/RecipeBookCategories; accessible field net/minecraft/server/MinecraftServer isReady Z accessible field net/minecraft/server/MinecraftServer mayHaveDelayedTasks Z \ No newline at end of file