aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/shcm/shsupercm
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/shcm/shsupercm')
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java17
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java (renamed from src/main/java/shcm/shsupercm/fabric/citresewn/CITResewnClient.java)20
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/mixin/IdentifierMixin.java2
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ReloadableResourceManagerImplMixin.java23
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java48
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java69
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CIT.java4
7 files changed, 156 insertions, 27 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java
new file mode 100644
index 0000000..3b87619
--- /dev/null
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java
@@ -0,0 +1,17 @@
+package shcm.shsupercm.fabric.citresewn;
+
+import shcm.shsupercm.fabric.citresewn.pack.cits.CIT;
+
+import java.util.Collection;
+
+public class ActiveCITs {
+
+
+ public ActiveCITs(Collection<CIT> cits) {
+
+ }
+
+ public void dispose() {
+
+ }
+}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewnClient.java b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java
index 57f628e..fa084ef 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewnClient.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java
@@ -3,21 +3,15 @@ package shcm.shsupercm.fabric.citresewn;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
-import net.minecraft.client.MinecraftClient;
-import net.minecraft.client.network.AbstractClientPlayerEntity;
-import net.minecraft.entity.EquipmentSlot;
-import net.minecraft.item.ArmorItem;
-import net.minecraft.resource.ReloadableResourceManager;
-import net.minecraft.resource.ResourceManager;
-import net.minecraft.resource.ResourceReloader;
-import net.minecraft.util.profiler.Profiler;
-
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.Executor;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
@Environment(EnvType.CLIENT)
-public class CITResewnClient implements ClientModInitializer {
- public static CITResewnClient INSTANCE;
+public class CITResewn implements ClientModInitializer {
+ public static final Logger LOG = LogManager.getLogger("citresewn");
+ public static CITResewn INSTANCE;
+
+ public ActiveCITs activeCITs = null;
@Override
public void onInitializeClient() {
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/IdentifierMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/IdentifierMixin.java
index 2effef9..10b67f0 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/IdentifierMixin.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/IdentifierMixin.java
@@ -11,7 +11,7 @@ public class IdentifierMixin {
@Inject(method = "isPathValid(Ljava/lang/String;)Z", cancellable = true, at = @At("HEAD"))
private static void isPathValid(String path, CallbackInfoReturnable<Boolean> ci) {
- if(path.startsWith("optifine"))
+ if(path.startsWith("citresewn") || path.startsWith("optifine") || path.startsWith("mcpatcher"))
ci.setReturnValue(true); return;
}
}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ReloadableResourceManagerImplMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ReloadableResourceManagerImplMixin.java
index 01b092b..fb5a267 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ReloadableResourceManagerImplMixin.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ReloadableResourceManagerImplMixin.java
@@ -1,6 +1,5 @@
package shcm.shsupercm.fabric.citresewn.mixin;
-import net.minecraft.client.MinecraftClient;
import net.minecraft.resource.*;
import net.minecraft.util.Identifier;
import net.minecraft.util.Unit;
@@ -10,6 +9,10 @@ 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.CallbackInfoReturnable;
+import shcm.shsupercm.fabric.citresewn.ActiveCITs;
+import shcm.shsupercm.fabric.citresewn.CITResewn;
+import shcm.shsupercm.fabric.citresewn.pack.CITParser;
+import shcm.shsupercm.fabric.citresewn.pack.cits.CIT;
import java.util.*;
import java.util.concurrent.CompletableFuture;
@@ -29,20 +32,14 @@ public abstract class ReloadableResourceManagerImplMixin implements ReloadableRe
if (this.type != ResourceType.CLIENT_RESOURCES)
return;
- Map<String, ResourcePack> citFiles = new HashMap<>();
- for (ResourcePack pack : packs) {
- for (Identifier identifier : pack.findResources(ResourceType.CLIENT_RESOURCES, "minecraft", "citresewn/cit", 5, s -> true))
- citFiles.put(identifier.getPath(), pack);
- for (Identifier identifier : pack.findResources(ResourceType.CLIENT_RESOURCES, "minecraft", "mcpatcher/cit", 5, s -> true))
- citFiles.put(identifier.getPath(), pack);
- for (Identifier identifier : pack.findResources(ResourceType.CLIENT_RESOURCES, "minecraft", "optifine/cit", 5, s -> true))
- citFiles.put(identifier.getPath(), pack);
+ if (CITResewn.INSTANCE.activeCITs != null) {
+ CITResewn.INSTANCE.activeCITs.dispose();
+ CITResewn.INSTANCE.activeCITs = null;
}
- for (Map.Entry<String, ResourcePack> citFile : citFiles.entrySet()) {
+ Collection<CIT> cits = CITParser.parse(packs);
- }
-
- new String();
+ if (cits.size() > 0)
+ CITResewn.INSTANCE.activeCITs = new ActiveCITs(cits);
}
} \ No newline at end of file
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java
new file mode 100644
index 0000000..27b693a
--- /dev/null
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java
@@ -0,0 +1,48 @@
+package shcm.shsupercm.fabric.citresewn.pack;
+
+import net.minecraft.resource.ResourcePack;
+import shcm.shsupercm.fabric.citresewn.CITResewn;
+import shcm.shsupercm.fabric.citresewn.pack.cits.CIT;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Properties;
+
+public class CITPack {
+ public final ResourcePack resourcePack;
+ public final Collection<CIT> cits = new ArrayList<>();
+
+ private EnchantmentMergeMethod method = EnchantmentMergeMethod.AVERAGE;
+ private int cap = 8;
+ private float fade = 0.5f;
+ private boolean useGlint = true;
+
+ public CITPack(ResourcePack resourcePack) {
+ this.resourcePack = resourcePack;
+ }
+
+ public void loadProperties(Properties properties) {
+ method = CITPack.EnchantmentMergeMethod.valueOf(properties.getProperty("method", "average"));
+ try {
+ cap = Integer.parseInt(properties.getProperty("cap", "8"));
+ } catch (NumberFormatException e) {
+ CITResewn.LOG.error("Skipped property: cap is not a whole number in cit.properties inside " + resourcePack.getName());
+ }
+ try {
+ fade = Float.parseFloat(properties.getProperty("fade", "0.5"));
+ } catch (NumberFormatException e) {
+ CITResewn.LOG.error("Skipped property: fade is not a number in cit.properties inside " + resourcePack.getName());
+ }
+ switch (properties.getProperty("useGlint", "true")) {
+ case "true" -> useGlint = true;
+ case "false" -> useGlint = false;
+ default -> CITResewn.LOG.error("Skipped property: useGlint is not a boolean in cit.properties inside " + resourcePack.getName());
+ }
+ }
+
+ public enum EnchantmentMergeMethod {
+ AVERAGE,
+ LAYERED,
+ CYCLE
+ }
+}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java
new file mode 100644
index 0000000..c3db062
--- /dev/null
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java
@@ -0,0 +1,69 @@
+package shcm.shsupercm.fabric.citresewn.pack;
+
+import net.minecraft.resource.ResourcePack;
+import net.minecraft.resource.ResourceType;
+import net.minecraft.util.Identifier;
+import shcm.shsupercm.fabric.citresewn.pack.cits.CIT;
+
+import java.io.InputStream;
+import java.util.*;
+import java.util.function.Predicate;
+
+public class CITParser { private CITParser() {}
+
+ /**
+ * Parses cit entries from an ordered collection of resourcepacks.
+ * @param packs packs to parse
+ * @return a collection of parsed CITs
+ */
+ public static Collection<CIT> parse(Collection<ResourcePack> packs) {
+ Collection<CIT> cits = new ArrayList<>();
+
+ // load cit resourcepack entries
+ Map<ResourcePack, Set<Identifier>> citPacks = new HashMap<>();
+ final Predicate<String> isProperties = s -> s.endsWith(".properties");
+ Identifier citresewnCITSettingsIdentifier = new Identifier("minecraft", "citresewn/cit.properties"), mcpatcherCITSettingsIdentifier = new Identifier("minecraft", "mcpatcher/cit.properties"), optifineCITSettingsIdentifier = new Identifier("minecraft", "optifine/cit.properties");
+ for (ResourcePack pack : packs) {
+ Set<Identifier> packIdentifiers = new HashSet<>();
+ packIdentifiers.addAll(pack.findResources(ResourceType.CLIENT_RESOURCES, "minecraft", "citresewn/cit", 5, isProperties));
+ if (pack.contains(ResourceType.CLIENT_RESOURCES, citresewnCITSettingsIdentifier))
+ packIdentifiers.add(citresewnCITSettingsIdentifier);
+ packIdentifiers.addAll(pack.findResources(ResourceType.CLIENT_RESOURCES, "minecraft", "mcpatcher/cit", 5, isProperties));
+ if (pack.contains(ResourceType.CLIENT_RESOURCES, mcpatcherCITSettingsIdentifier))
+ packIdentifiers.add(mcpatcherCITSettingsIdentifier);
+ packIdentifiers.addAll(pack.findResources(ResourceType.CLIENT_RESOURCES, "minecraft", "optifine/cit", 5, isProperties));
+ if (pack.contains(ResourceType.CLIENT_RESOURCES, optifineCITSettingsIdentifier))
+ packIdentifiers.add(optifineCITSettingsIdentifier);
+
+ if (packIdentifiers.size() > 0)
+ citPacks.put(pack, packIdentifiers);
+ }
+
+ for (Map.Entry<ResourcePack, Set<Identifier>> citPackEntry : citPacks.entrySet()) {
+ CITPack citPack = new CITPack(citPackEntry.getKey());
+ for (Identifier citIdentifier : citPackEntry.getValue()) {
+ try {
+ InputStream is = citPackEntry.getKey().open(ResourceType.CLIENT_RESOURCES, citIdentifier);
+ Properties citProperties = new Properties();
+ citProperties.load(is);
+ is.close();
+
+ if (citIdentifier == citresewnCITSettingsIdentifier || citIdentifier == mcpatcherCITSettingsIdentifier || citIdentifier == optifineCITSettingsIdentifier)
+ citPack.loadProperties(citProperties);
+ else
+ citPack.cits.add(parseCIT(citPack, citIdentifier, citProperties));
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ cits.addAll(citPack.cits);
+ }
+
+ return cits;
+ }
+
+ public static CIT parseCIT(CITPack pack, Identifier identifier, Properties properties) {
+ return null;
+ }
+}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CIT.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CIT.java
new file mode 100644
index 0000000..8d4dc65
--- /dev/null
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CIT.java
@@ -0,0 +1,4 @@
+package shcm.shsupercm.fabric.citresewn.pack.cits;
+
+public abstract class CIT {
+}