Add basic server support
This commit is contained in:
parent
21e4ac1366
commit
58ffdcaeb0
|
@ -6,7 +6,7 @@ minecraft_version=1.16.4
|
||||||
yarn_mappings=1.16.4+build.7
|
yarn_mappings=1.16.4+build.7
|
||||||
loader_version=0.10.8
|
loader_version=0.10.8
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=1.1.1
|
mod_version=1.2.0
|
||||||
maven_group=io.gitlab.jfronny
|
maven_group=io.gitlab.jfronny
|
||||||
archives_base_name=resclone
|
archives_base_name=resclone
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
|
@ -10,11 +10,8 @@ import io.gitlab.jfronny.resclone.fetchers.PackFetcher;
|
||||||
import io.gitlab.jfronny.resclone.processors.PackProcessor;
|
import io.gitlab.jfronny.resclone.processors.PackProcessor;
|
||||||
import io.gitlab.jfronny.resclone.processors.RemoveEmptyProcessor;
|
import io.gitlab.jfronny.resclone.processors.RemoveEmptyProcessor;
|
||||||
import io.gitlab.jfronny.resclone.processors.RootPathProcessor;
|
import io.gitlab.jfronny.resclone.processors.RootPathProcessor;
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.fabricmc.api.EnvType;
|
|
||||||
import net.fabricmc.api.Environment;
|
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -24,8 +21,7 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
public class Resclone implements ModInitializer, RescloneApi {
|
||||||
public class Resclone implements ClientModInitializer, RescloneApi {
|
|
||||||
public static final Set<PackMetaUnloaded> conf = new LinkedHashSet<>();
|
public static final Set<PackMetaUnloaded> conf = new LinkedHashSet<>();
|
||||||
public static final Map<String, PackFetcher> fetcherInstances = new LinkedHashMap<>();
|
public static final Map<String, PackFetcher> fetcherInstances = new LinkedHashMap<>();
|
||||||
public static final Set<PackProcessor> processors = new LinkedHashSet<>();
|
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";
|
public static final String MOD_ID = "resclone";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitialize() {
|
||||||
conf.clear();
|
conf.clear();
|
||||||
fetcherInstances.clear();
|
fetcherInstances.clear();
|
||||||
processors.clear();
|
processors.clear();
|
||||||
|
@ -48,7 +44,7 @@ public class Resclone implements ClientModInitializer, RescloneApi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addProcessor(new RemoveEmptyProcessor());
|
addProcessor(new RemoveEmptyProcessor());
|
||||||
reload(false);
|
reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -67,7 +63,7 @@ public class Resclone implements ClientModInitializer, RescloneApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload(boolean forceResourceReload) {
|
public void reload() {
|
||||||
//Get paths from patchers. Downloading is implemented in PackFetcher to allow for unconsidered sources
|
//Get paths from patchers. Downloading is implemented in PackFetcher to allow for unconsidered sources
|
||||||
//TODO implement downloading again after a set time if downloadable
|
//TODO implement downloading again after a set time if downloadable
|
||||||
Set<PackMetaLoaded> metas = new LinkedHashSet<>();
|
Set<PackMetaLoaded> metas = new LinkedHashSet<>();
|
||||||
|
@ -105,23 +101,24 @@ public class Resclone implements ClientModInitializer, RescloneApi {
|
||||||
}
|
}
|
||||||
catch (Throwable e) {
|
catch (Throwable e) {
|
||||||
if (!p1.equals(p.zipPath)) {
|
if (!p1.equals(p.zipPath)) {
|
||||||
|
e.printStackTrace();
|
||||||
System.err.println("Failed to download, using cache");
|
System.err.println("Failed to download, using cache");
|
||||||
Files.deleteIfExists(p.zipPath);
|
Files.deleteIfExists(p.zipPath);
|
||||||
Files.move(p1, p.zipPath);
|
Files.move(p1, p.zipPath);
|
||||||
} else
|
} else
|
||||||
throw new RescloneException("Failed to download initial");
|
throw new RescloneException("Failed to download initial", e);
|
||||||
}
|
}
|
||||||
if (!p1.equals(p.zipPath))
|
if (!p1.equals(p.zipPath))
|
||||||
Files.deleteIfExists(p1);
|
Files.deleteIfExists(p1);
|
||||||
metas.add(p);
|
metas.add(p);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
System.err.println("Encountered issue while preparing " + s.name);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Set variable
|
//Set variable
|
||||||
downloadedPacks.clear();
|
downloadedPacks.clear();
|
||||||
downloadedPacks.addAll(metas);
|
downloadedPacks.addAll(metas);
|
||||||
if (forceResourceReload) MinecraftClient.getInstance().reloadResources();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -8,6 +8,8 @@ import io.gitlab.jfronny.resclone.fetchers.CurseforgeFetcher;
|
||||||
import io.gitlab.jfronny.resclone.fetchers.GithubMasterFetcher;
|
import io.gitlab.jfronny.resclone.fetchers.GithubMasterFetcher;
|
||||||
import io.gitlab.jfronny.resclone.fetchers.GithubReleaseFetcher;
|
import io.gitlab.jfronny.resclone.fetchers.GithubReleaseFetcher;
|
||||||
import io.gitlab.jfronny.resclone.processors.PruneVanillaProcessor;
|
import io.gitlab.jfronny.resclone.processors.PruneVanillaProcessor;
|
||||||
|
import net.fabricmc.api.EnvType;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
|
||||||
public class RescloneEntryDefault implements RescloneEntry {
|
public class RescloneEntryDefault implements RescloneEntry {
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,7 +18,8 @@ public class RescloneEntryDefault implements RescloneEntry {
|
||||||
api.addFetcher(new GithubMasterFetcher());
|
api.addFetcher(new GithubMasterFetcher());
|
||||||
api.addFetcher(new GithubReleaseFetcher());
|
api.addFetcher(new GithubReleaseFetcher());
|
||||||
api.addFetcher(new CurseforgeFetcher());
|
api.addFetcher(new CurseforgeFetcher());
|
||||||
api.addProcessor(new PruneVanillaProcessor());
|
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT)
|
||||||
|
api.addProcessor(new PruneVanillaProcessor());
|
||||||
ConfigLoader.load(api);
|
ConfigLoader.load(api);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,6 @@ public interface RescloneApi {
|
||||||
void addFetcher(PackFetcher fetcher);
|
void addFetcher(PackFetcher fetcher);
|
||||||
void addProcessor(PackProcessor processor);
|
void addProcessor(PackProcessor processor);
|
||||||
void addPack(String fetcher, String pack, String name);
|
void addPack(String fetcher, String pack, String name);
|
||||||
void reload(boolean forceResourceReload);
|
void reload();
|
||||||
Path getConfigPath();
|
Path getConfigPath();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
JsonObject latest = (JsonObject)readJsonFromURL("https://addons-ecs.forgesvc.net/api/v2/addon/" + baseUrl + "/files", JsonArray.class).get(0);
|
||||||
return latest.get("downloadUrl").getAsString();
|
return latest.get("downloadUrl").getAsString();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw new RescloneException("Could not get CF download", e);
|
throw new RescloneException("Could not get CF download for " + baseUrl, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,19 +10,21 @@ import java.nio.file.Files;
|
||||||
public class RemoveEmptyProcessor extends PackProcessor {
|
public class RemoveEmptyProcessor extends PackProcessor {
|
||||||
@Override
|
@Override
|
||||||
public void process(FileSystem p) throws RescloneException {
|
public void process(FileSystem p) throws RescloneException {
|
||||||
try {
|
if (Files.exists(p.getPath("/assets"))) {
|
||||||
Files.walkFileTree(p.getPath("/assets"), new PathPruneVisitor(s -> {
|
try {
|
||||||
if (Files.isDirectory(s)) {
|
Files.walkFileTree(p.getPath("/assets"), new PathPruneVisitor(s -> {
|
||||||
try {
|
if (Files.isDirectory(s)) {
|
||||||
return !Files.newDirectoryStream(s).iterator().hasNext();
|
try {
|
||||||
} catch (IOException e) {
|
return !Files.newDirectoryStream(s).iterator().hasNext();
|
||||||
e.printStackTrace();
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return false;
|
||||||
return false;
|
}));
|
||||||
}));
|
} catch (Throwable e) {
|
||||||
} catch (Throwable e) {
|
throw new RescloneException("Failed to prune empty directories", e);
|
||||||
throw new RescloneException("Failed to prune empty directories", e);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
"icon": "assets/resclone/icon.png",
|
"icon": "assets/resclone/icon.png",
|
||||||
"environment": "*",
|
"environment": "*",
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
"client": [
|
"main": [
|
||||||
"io.gitlab.jfronny.resclone.Resclone"
|
"io.gitlab.jfronny.resclone.Resclone"
|
||||||
],
|
],
|
||||||
"resclone": [
|
"resclone": [
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"minVersion": "0.8",
|
"minVersion": "0.8",
|
||||||
"package": "io.gitlab.jfronny.resclone.mixin",
|
"package": "io.gitlab.jfronny.resclone.mixin",
|
||||||
"compatibilityLevel": "JAVA_8",
|
"compatibilityLevel": "JAVA_8",
|
||||||
"client": [
|
"mixins": [
|
||||||
"FileResourcePackProviderMixin"
|
"FileResourcePackProviderMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
|
|
Loading…
Reference in New Issue