Add basic server support

This commit is contained in:
JFronny 2020-12-29 22:22:23 +01:00
parent 21e4ac1366
commit 58ffdcaeb0
8 changed files with 31 additions and 29 deletions

View File

@ -6,7 +6,7 @@ minecraft_version=1.16.4
yarn_mappings=1.16.4+build.7
loader_version=0.10.8
# Mod Properties
mod_version=1.1.1
mod_version=1.2.0
maven_group=io.gitlab.jfronny
archives_base_name=resclone
# Dependencies

View File

@ -10,11 +10,8 @@ import io.gitlab.jfronny.resclone.fetchers.PackFetcher;
import io.gitlab.jfronny.resclone.processors.PackProcessor;
import io.gitlab.jfronny.resclone.processors.RemoveEmptyProcessor;
import io.gitlab.jfronny.resclone.processors.RootPathProcessor;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import java.io.IOException;
import java.net.URI;
@ -24,8 +21,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
@Environment(EnvType.CLIENT)
public class Resclone implements ClientModInitializer, RescloneApi {
public class Resclone implements ModInitializer, RescloneApi {
public static final Set<PackMetaUnloaded> conf = new LinkedHashSet<>();
public static final Map<String, PackFetcher> fetcherInstances = new LinkedHashMap<>();
public static final Set<PackProcessor> processors = new LinkedHashSet<>();
@ -34,7 +30,7 @@ public class Resclone implements ClientModInitializer, RescloneApi {
public static final String MOD_ID = "resclone";
@Override
public void onInitializeClient() {
public void onInitialize() {
conf.clear();
fetcherInstances.clear();
processors.clear();
@ -48,7 +44,7 @@ public class Resclone implements ClientModInitializer, RescloneApi {
}
}
addProcessor(new RemoveEmptyProcessor());
reload(false);
reload();
}
@Override
@ -67,7 +63,7 @@ public class Resclone implements ClientModInitializer, RescloneApi {
}
@Override
public void reload(boolean forceResourceReload) {
public void reload() {
//Get paths from patchers. Downloading is implemented in PackFetcher to allow for unconsidered sources
//TODO implement downloading again after a set time if downloadable
Set<PackMetaLoaded> metas = new LinkedHashSet<>();
@ -105,23 +101,24 @@ public class Resclone implements ClientModInitializer, RescloneApi {
}
catch (Throwable e) {
if (!p1.equals(p.zipPath)) {
e.printStackTrace();
System.err.println("Failed to download, using cache");
Files.deleteIfExists(p.zipPath);
Files.move(p1, p.zipPath);
} else
throw new RescloneException("Failed to download initial");
throw new RescloneException("Failed to download initial", e);
}
if (!p1.equals(p.zipPath))
Files.deleteIfExists(p1);
metas.add(p);
} catch (Throwable e) {
System.err.println("Encountered issue while preparing " + s.name);
e.printStackTrace();
}
}
//Set variable
downloadedPacks.clear();
downloadedPacks.addAll(metas);
if (forceResourceReload) MinecraftClient.getInstance().reloadResources();
}
@Override

View File

@ -8,6 +8,8 @@ import io.gitlab.jfronny.resclone.fetchers.CurseforgeFetcher;
import io.gitlab.jfronny.resclone.fetchers.GithubMasterFetcher;
import io.gitlab.jfronny.resclone.fetchers.GithubReleaseFetcher;
import io.gitlab.jfronny.resclone.processors.PruneVanillaProcessor;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
public class RescloneEntryDefault implements RescloneEntry {
@Override
@ -16,7 +18,8 @@ public class RescloneEntryDefault implements RescloneEntry {
api.addFetcher(new GithubMasterFetcher());
api.addFetcher(new GithubReleaseFetcher());
api.addFetcher(new CurseforgeFetcher());
api.addProcessor(new PruneVanillaProcessor());
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT)
api.addProcessor(new PruneVanillaProcessor());
ConfigLoader.load(api);
}
}

View File

@ -9,6 +9,6 @@ public interface RescloneApi {
void addFetcher(PackFetcher fetcher);
void addProcessor(PackProcessor processor);
void addPack(String fetcher, String pack, String name);
void reload(boolean forceResourceReload);
void reload();
Path getConfigPath();
}

View File

@ -16,7 +16,7 @@ public class CurseforgeFetcher extends PackFetcher {
JsonObject latest = (JsonObject)readJsonFromURL("https://addons-ecs.forgesvc.net/api/v2/addon/" + baseUrl + "/files", JsonArray.class).get(0);
return latest.get("downloadUrl").getAsString();
} catch (Throwable e) {
throw new RescloneException("Could not get CF download", e);
throw new RescloneException("Could not get CF download for " + baseUrl, e);
}
}
}

View File

@ -10,19 +10,21 @@ import java.nio.file.Files;
public class RemoveEmptyProcessor extends PackProcessor {
@Override
public void process(FileSystem p) throws RescloneException {
try {
Files.walkFileTree(p.getPath("/assets"), new PathPruneVisitor(s -> {
if (Files.isDirectory(s)) {
try {
return !Files.newDirectoryStream(s).iterator().hasNext();
} catch (IOException e) {
e.printStackTrace();
if (Files.exists(p.getPath("/assets"))) {
try {
Files.walkFileTree(p.getPath("/assets"), new PathPruneVisitor(s -> {
if (Files.isDirectory(s)) {
try {
return !Files.newDirectoryStream(s).iterator().hasNext();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return false;
}));
} catch (Throwable e) {
throw new RescloneException("Failed to prune empty directories", e);
return false;
}));
} catch (Throwable e) {
throw new RescloneException("Failed to prune empty directories", e);
}
}
}
}

View File

@ -12,7 +12,7 @@
"icon": "assets/resclone/icon.png",
"environment": "*",
"entrypoints": {
"client": [
"main": [
"io.gitlab.jfronny.resclone.Resclone"
],
"resclone": [

View File

@ -3,7 +3,7 @@
"minVersion": "0.8",
"package": "io.gitlab.jfronny.resclone.mixin",
"compatibilityLevel": "JAVA_8",
"client": [
"mixins": [
"FileResourcePackProviderMixin"
],
"injectors": {