Fixed build issues in RecipeManagerMixin

This commit is contained in:
Frank 2023-12-18 13:07:27 +01:00
parent 3d4245331a
commit ec94517c91

View file

@ -7,6 +7,7 @@ import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.profiling.ProfilerFiller; import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.Container; import net.minecraft.world.Container;
import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.RecipeManager; import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
@ -24,8 +25,11 @@ import java.util.Optional;
@Mixin(RecipeManager.class) @Mixin(RecipeManager.class)
public abstract class RecipeManagerMixin { public abstract class RecipeManagerMixin {
@Shadow @Shadow
protected abstract <C extends Container, T extends Recipe<C>> Map<ResourceLocation, T> byType(RecipeType<T> recipeType); protected abstract <C extends Container, T extends Recipe<C>> Map<ResourceLocation, RecipeHolder<T>> byType(
RecipeType<T> recipeType
);
@Inject(method = "apply(Ljava/util/Map;Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/util/profiling/ProfilerFiller;)V", at = @At("HEAD")) @Inject(method = "apply(Ljava/util/Map;Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/util/profiling/ProfilerFiller;)V", at = @At("HEAD"))
public void bcl_interceptApply( public void bcl_interceptApply(
@ -42,21 +46,26 @@ public abstract class RecipeManagerMixin {
RecipeType<T> recipeType, RecipeType<T> recipeType,
C container, C container,
Level level, Level level,
CallbackInfoReturnable<Optional<T>> cir CallbackInfoReturnable<Optional<RecipeHolder<T>>> cir
) { ) {
var inter = this.byType(recipeType); var inter = this.byType(recipeType);
var all = inter.values().stream().filter((recipe) -> recipe.matches(container, level)).sorted((a, b) -> { var all = inter
if (a.getId().getNamespace().equals(b.getId().getNamespace())) { .values()
return a.getId().getPath().compareTo(b.getId().getPath()); .stream()
} .filter((recipe) -> recipe.value().matches(container, level)).sorted((a, b) -> {
if (a.getId().getNamespace().equals("minecraft") && !b.getId().getNamespace().equals("minecraft")) { if (a.id().getNamespace().equals(b.id().getNamespace())) {
return 1; return a.id().getPath().compareTo(b.id().getPath());
} else if (!a.getId().getNamespace().equals("minecraft") && b.getId().getNamespace().equals("minecraft")) { }
return -1; if (a.id().getNamespace().equals("minecraft") && !b.id().getNamespace().equals("minecraft")) {
} else { return 1;
return a.getId().getNamespace().compareTo(b.getId().getNamespace()); } else if (!a.id().getNamespace().equals("minecraft") && b.id()
} .getNamespace()
}).toList(); .equals("minecraft")) {
return -1;
} else {
return a.id().getNamespace().compareTo(b.id().getNamespace());
}
}).toList();
if (all.size() > 1) { if (all.size() > 1) {
cir.setReturnValue(Optional.of(all.get(0))); cir.setReturnValue(Optional.of(all.get(0)));