76 lines
3.4 KiB
Java
76 lines
3.4 KiB
Java
package ru.bclib.mixin.common;
|
|
|
|
import com.mojang.authlib.GameProfileRepository;
|
|
import com.mojang.authlib.minecraft.MinecraftSessionService;
|
|
import com.mojang.datafixers.DataFixer;
|
|
import net.minecraft.core.RegistryAccess.RegistryHolder;
|
|
import net.minecraft.resources.ResourceKey;
|
|
import net.minecraft.server.MinecraftServer;
|
|
import net.minecraft.server.ServerResources;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.server.level.progress.ChunkProgressListenerFactory;
|
|
import net.minecraft.server.packs.repository.PackRepository;
|
|
import net.minecraft.server.players.GameProfileCache;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.storage.LevelStorageSource;
|
|
import net.minecraft.world.level.storage.LevelStorageSource.LevelStorageAccess;
|
|
import net.minecraft.world.level.storage.WorldData;
|
|
import org.spongepowered.asm.mixin.Final;
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
import org.spongepowered.asm.mixin.Shadow;
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
import ru.bclib.api.BiomeAPI;
|
|
import ru.bclib.api.dataexchange.DataExchangeAPI;
|
|
import ru.bclib.recipes.BCLRecipeManager;
|
|
|
|
import java.net.Proxy;
|
|
import java.util.Collection;
|
|
import java.util.Map;
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
@Mixin(MinecraftServer.class)
|
|
public class MinecraftServerMixin {
|
|
@Shadow
|
|
private ServerResources resources;
|
|
|
|
@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();
|
|
}
|
|
|
|
@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 = "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() {
|
|
RecipeManagerAccessor accessor = (RecipeManagerAccessor) resources.getRecipeManager();
|
|
accessor.bclib_setRecipes(BCLRecipeManager.getMap(accessor.bclib_getRecipes()));
|
|
}
|
|
}
|