Merge pull request #32 from glisco03/main

Always use the KubeJS workaround for recipe loading to improve mod compatibility
This commit is contained in:
paulevsGitch 2021-08-20 13:02:38 +03:00 committed by GitHub
commit 5ed75012cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 40 deletions

View file

@ -3,7 +3,6 @@ package ru.bclib.mixin.common;
import com.mojang.authlib.GameProfileRepository;
import com.mojang.authlib.minecraft.MinecraftSessionService;
import com.mojang.datafixers.DataFixer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.core.RegistryAccess.RegistryHolder;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
@ -34,45 +33,44 @@ import java.util.concurrent.CompletableFuture;
@Mixin(MinecraftServer.class)
public class MinecraftServerMixin {
@Shadow
private ServerResources resources;
@Shadow
private ServerResources resources;
@Final
@Shadow
private Map<ResourceKey<Level>, ServerLevel> levels;
@Final
@Shadow
private Map<ResourceKey<Level>, ServerLevel> levels;
@Final
@Shadow
protected WorldData worldData;
@Inject(method = "<init>*", at = @At("TAIL"))
private void bclib_onServerInit(Thread thread, RegistryHolder registryHolder, LevelStorageAccess levelStorageAccess, WorldData worldData, PackRepository packRepository, Proxy proxy, DataFixer dataFixer, ServerResources serverResources, MinecraftSessionService minecraftSessionService, GameProfileRepository gameProfileRepository, GameProfileCache gameProfileCache, ChunkProgressListenerFactory chunkProgressListenerFactory, CallbackInfo ci){
DataExchangeAPI.prepareServerside();
}
@Final
@Shadow
protected WorldData worldData;
@Inject(method="convertFromRegionFormatIfNeeded", at = @At("HEAD"))
private static void bclib_applyPatches(LevelStorageSource.LevelStorageAccess session, CallbackInfo ci){
@Inject(method = "<init>*", at = @At("TAIL"))
private void bclib_onServerInit(Thread thread, RegistryHolder registryHolder, LevelStorageAccess levelStorageAccess, WorldData worldData, PackRepository packRepository, Proxy proxy, DataFixer dataFixer, ServerResources serverResources, MinecraftSessionService minecraftSessionService, GameProfileRepository gameProfileRepository, GameProfileCache gameProfileCache, ChunkProgressListenerFactory chunkProgressListenerFactory, CallbackInfo ci) {
DataExchangeAPI.prepareServerside();
}
@Inject(method = "convertFromRegionFormatIfNeeded", at = @At("HEAD"))
private static void bclib_applyPatches(LevelStorageSource.LevelStorageAccess session, CallbackInfo ci) {
/*File levelPath = session.getLevelPath(LevelResource.ROOT).toFile();
WorldDataAPI.load(new File(levelPath, "data"));
DataFixerAPI.fixData(levelPath, session.getLevelId());*/
}
}
@Inject(method = "reloadResources", at = @At(value = "RETURN"), cancellable = true)
private void bclib_reloadResources(Collection<String> collection, CallbackInfoReturnable<CompletableFuture<Void>> info) {
bclib_injectRecipes();
}
@Inject(method = "reloadResources", at = @At(value = "RETURN"), cancellable = true)
private void bclib_reloadResources(Collection<String> collection, CallbackInfoReturnable<CompletableFuture<Void>> info) {
bclib_injectRecipes();
}
@Inject(method = "loadLevel", at = @At(value = "RETURN"), cancellable = true)
private void bclib_loadLevel(CallbackInfo info) {
bclib_injectRecipes();
BiomeAPI.initRegistry(MinecraftServer.class.cast(this));
}
@Inject(method = "loadLevel", at = @At(value = "RETURN"), cancellable = true)
private void bclib_loadLevel(CallbackInfo info) {
bclib_injectRecipes();
BiomeAPI.initRegistry(MinecraftServer.class.cast(this));
}
private void bclib_injectRecipes() {
if (FabricLoader.getInstance().isModLoaded("kubejs")) {
RecipeManagerAccessor accessor = (RecipeManagerAccessor) resources.getRecipeManager();
accessor.bclib_setRecipes(BCLRecipeManager.getMap(accessor.bclib_getRecipes()));
}
}
private void bclib_injectRecipes() {
RecipeManagerAccessor accessor = (RecipeManagerAccessor) resources.getRecipeManager();
accessor.bclib_setRecipes(BCLRecipeManager.getMap(accessor.bclib_getRecipes()));
}
}

View file

@ -29,11 +29,6 @@ public abstract class RecipeManagerMixin {
@Shadow
private Map<RecipeType<?>, Map<ResourceLocation, Recipe<?>>> recipes;
@Inject(method = "apply", at = @At(value = "RETURN"))
private void be_apply(Map<ResourceLocation, JsonElement> map, ResourceManager resourceManager, ProfilerFiller profiler, CallbackInfo info) {
recipes = BCLRecipeManager.getMap(recipes);
}
@Shadow
private <C extends Container, T extends Recipe<C>> Map<ResourceLocation, Recipe<C>> byType(RecipeType<T> type) {
return null;