This commit is contained in:
paulevsGitch 2020-09-24 18:49:23 +03:00
parent 34e7c442e4
commit 36ea4b8726
8 changed files with 32 additions and 57 deletions

View file

@ -27,23 +27,22 @@ import net.minecraft.world.World;
import ru.betterend.recipe.EndRecipeManager;
@Mixin(RecipeManager.class)
public class RecipeManagerMixin
{
public class RecipeManagerMixin {
@Shadow
private Map<RecipeType<?>, Map<Identifier, Recipe<?>>> recipes;
@Inject(method = "apply", at = @At(value = "RETURN"))
private void setRecipes(Map<Identifier, JsonElement> map, ResourceManager resourceManager, Profiler profiler, CallbackInfo info)
{
private void setRecipes(Map<Identifier, JsonElement> map, ResourceManager resourceManager, Profiler profiler, CallbackInfo info) {
recipes = EndRecipeManager.getMap(recipes);
}
@Shadow
private <C extends Inventory, T extends Recipe<C>> Map<Identifier, Recipe<C>> getAllOfType(RecipeType<T> type) { return null; }
private <C extends Inventory, T extends Recipe<C>> Map<Identifier, Recipe<C>> getAllOfType(RecipeType<T> type) {
return null;
}
@Overwrite
public <C extends Inventory, T extends Recipe<C>> Optional<T> getFirstMatch(RecipeType<T> type, C inventory, World world)
{
public <C extends Inventory, T extends Recipe<C>> Optional<T> getFirstMatch(RecipeType<T> type, C inventory, World world) {
Collection<Recipe<C>> values = getAllOfType(type).values();
List<Recipe<C>> list = new ArrayList<Recipe<C>>(values);
list.sort((v1, v2) -> {
@ -51,9 +50,9 @@ public class RecipeManagerMixin
boolean b2 = v2.getId().getNamespace().equals("minecraft");
return b1 ^ b2 ? (b1 ? 1 : -1) : 0;
});
return list.stream().flatMap((recipe) -> {
return Util.stream(type.get(recipe, world, inventory));
}).findFirst();
}
return Util.stream(type.get(recipe, world, inventory));
}).findFirst();
}
}