From b15717a8cf4c80963750fba4fcac173cecdf8ab3 Mon Sep 17 00:00:00 2001 From: SHsuperCM Date: Mon, 2 Jan 2023 13:03:30 +0200 Subject: Added /cit/ folders to the blocks atlas by default --- .../fabric/citresewn/mixin/AtlasLoaderMixin.java | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasLoaderMixin.java (limited to 'src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasLoaderMixin.java') 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 cir, Identifier identifier, List 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 entry : resourceFinder.findResources(resourceManager).entrySet()) + regions.add(resourceFinder.toResourceId(entry.getKey()).withPrefixedPath(root + "/cit/"), entry.getValue()); + } + } + + @Override + public AtlasSourceType getType() { + return null; + } + }); + } + } +} -- cgit