aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasLoaderMixin.java43
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasPreparationMixin.java10
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java2
3 files changed, 52 insertions, 3 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasLoaderMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasLoaderMixin.java
new file mode 100644
index 0000000..786251b
--- /dev/null
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasLoaderMixin.java
@@ -0,0 +1,43 @@
+package shcm.shsupercm.fabric.citresewn.mixin;
+
+import net.minecraft.client.texture.atlas.AtlasLoader;
+import net.minecraft.client.texture.atlas.AtlasSource;
+import net.minecraft.client.texture.atlas.AtlasSourceType;
+import net.minecraft.resource.Resource;
+import net.minecraft.resource.ResourceFinder;
+import net.minecraft.resource.ResourceManager;
+import net.minecraft.util.Identifier;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
+import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
+import shcm.shsupercm.fabric.citresewn.CITResewn;
+import shcm.shsupercm.fabric.citresewn.pack.PackParser;
+
+import java.util.List;
+import java.util.Map;
+
+@Mixin(AtlasLoader.class)
+public class AtlasLoaderMixin {
+ @Inject(method = "of", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILSOFT)
+ private static void citresewn$atlasSource(ResourceManager resourceManager, Identifier id, CallbackInfoReturnable<AtlasLoader> cir, Identifier identifier, List<AtlasSource> list) {
+ if (id.getPath().equals("blocks") && id.getNamespace().equals("minecraft")) {
+ list.add(new AtlasSource() {
+ @Override
+ public void load(ResourceManager resourceManager, SpriteRegions regions) {
+ for (String root : PackParser.ROOTS) {
+ ResourceFinder resourceFinder = new ResourceFinder(root + "/cit", ".png");
+ for (Map.Entry<Identifier, Resource> entry : resourceFinder.findResources(resourceManager).entrySet())
+ regions.add(resourceFinder.toResourceId(entry.getKey()).withPrefixedPath(root + "/cit/"), entry.getValue());
+ }
+ }
+
+ @Override
+ public AtlasSourceType getType() {
+ return null;
+ }
+ });
+ }
+ }
+}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasPreparationMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasPreparationMixin.java
index 035a95e..1cc8b54 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasPreparationMixin.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasPreparationMixin.java
@@ -16,7 +16,13 @@ public abstract class AtlasPreparationMixin {
@Inject(method = "getSprite", cancellable = true, at = @At("HEAD"))
private void citresewn$unwrapTexturePaths(Identifier id, CallbackInfoReturnable<Sprite> cir) {
- if (id.getPath().startsWith("textures/") && id.getPath().endsWith(".png"))
- cir.setReturnValue(getSprite(new Identifier(id.getNamespace(), id.getPath().substring(9, id.getPath().length() - 4))));
+ if (id.getPath().endsWith(".png")) {
+ id = id.withPath(path -> path.substring(0, path.length() - 4));
+
+ if (id.getPath().startsWith("textures/"))
+ id = id.withPath(path -> path.substring(9));
+
+ cir.setReturnValue(getSprite(id));
+ }
}
}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java
index 590f5a0..aa367b7 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java
@@ -26,7 +26,7 @@ public final class PackParser { private PackParser() {}
/**
* Possible CIT roots in resourcepacks ordered in increasing order of priority.
*/
- private static final String[] ROOTS = new String[] { "mcpatcher", "optifine", "citresewn" };
+ public static final List<String> ROOTS = List.of("mcpatcher", "optifine", "citresewn");
/**
* Loads a merged global property group from loaded packs making sure to respect order.