DynRes/src/main/java/io/gitlab/jfronny/dynres/mixin/ServerPropertiesHandlerMixi...

45 lines
1.8 KiB
Java

package io.gitlab.jfronny.dynres.mixin;
import io.gitlab.jfronny.dynres.DynRes;
import net.minecraft.server.dedicated.ServerPropertiesHandler;
import net.minecraft.util.registry.DynamicRegistryManager;
import org.apache.commons.codec.digest.DigestUtils;
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 java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
@Mixin(ServerPropertiesHandler.class)
public class ServerPropertiesHandlerMixin {
@Shadow public String resourcePack;
@Shadow public String resourcePackHash;
@Shadow public String resourcePackSha1;
@Inject(at = @At("RETURN"), method = "<init>(Ljava/util/Properties;Lnet/minecraft/util/registry/DynamicRegistryManager;)V")
public void init(Properties properties, DynamicRegistryManager dynamicRegistryManager, CallbackInfo info) {
resourcePack = DynRes.removePort(DynRes.simplifyElement(DynRes.baseLink)) + ":" + DynRes.getPort() + "/resources.zip";
System.out.println("Pack link: " + resourcePack);
//TODO hash the pack
resourcePackSha1 = "";
if (DynRes.cfg.hashResources) {
try {
FileInputStream fs = new FileInputStream(DynRes.resFile);
resourcePackSha1 = DigestUtils.sha1Hex(fs);
System.out.println("Set hash to " + resourcePackSha1);
fs.close();
} catch (IOException e) {
System.err.println("Failed to get hash, continuing with empty");
e.printStackTrace();
}
}
resourcePackHash = resourcePackSha1;
}
}