From b994cb2059e5ff8d6e532d83aa14779ffd7c6339 Mon Sep 17 00:00:00 2001 From: SHsuperCM Date: Mon, 2 Jan 2023 10:40:47 +0200 Subject: Moved new resource/atlas mixins out of Defaults This is to prepare for future cit modeling api --- .../citresewn/mixin/AtlasPreparationMixin.java | 22 +++++++++++++++++++++ .../citresewn/mixin/ResourceFinderMixin.java | 23 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasPreparationMixin.java create mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ResourceFinderMixin.java (limited to 'src') diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasPreparationMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasPreparationMixin.java new file mode 100644 index 0000000..035a95e --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasPreparationMixin.java @@ -0,0 +1,22 @@ +package shcm.shsupercm.fabric.citresewn.mixin; + +import net.minecraft.client.render.model.SpriteAtlasManager; +import net.minecraft.client.texture.Sprite; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +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; + +@Mixin(SpriteAtlasManager.AtlasPreparation.class) +public abstract class AtlasPreparationMixin { + @Shadow public @Nullable abstract Sprite getSprite(Identifier id); + + @Inject(method = "getSprite", cancellable = true, at = @At("HEAD")) + private void citresewn$unwrapTexturePaths(Identifier id, CallbackInfoReturnable 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)))); + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ResourceFinderMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ResourceFinderMixin.java new file mode 100644 index 0000000..0abdf76 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ResourceFinderMixin.java @@ -0,0 +1,23 @@ +package shcm.shsupercm.fabric.citresewn.mixin; + +import net.minecraft.resource.ResourceFinder; +import net.minecraft.util.Identifier; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +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; + +@Mixin(ResourceFinder.class) +public class ResourceFinderMixin { + + @Shadow @Final private String fileExtension; + + @Inject(method = "toResourcePath", cancellable = true, at = + @At("HEAD")) + private void citresewn$forceAbsoluteTextureIdentifier(Identifier id, CallbackInfoReturnable cir) { + if (id.getPath().endsWith(".png") && this.fileExtension.equals(".png")) + cir.setReturnValue(id); + } +} -- cgit