diff options
author | SHsuperCM <shsupercm@gmail.com> | 2021-12-11 07:38:33 +0200 |
---|---|---|
committer | SHsuperCM <shsupercm@gmail.com> | 2021-12-11 07:38:33 +0200 |
commit | 083b872fb15b0075ab541a40ff3f3c1a3776a163 (patch) | |
tree | fed1f0598dcba334e5b66231262d20c2773f6c39 /src/main/java | |
parent | de03174eaeaed79c98b26c0abdf4674cdbb79589 (diff) | |
download | CITResewn-083b872fb15b0075ab541a40ff3f3c1a3776a163.tar.gz CITResewn-083b872fb15b0075ab541a40ff3f3c1a3776a163.tar.bz2 CITResewn-083b872fb15b0075ab541a40ff3f3c1a3776a163.zip |
Replaced Redirect usage with ModifyArg
Fixes #73
Fixes #72
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citelytra/ElytraFeatureRendererMixin.java | 33 | ||||
-rw-r--r-- | src/main/java/shcm/shsupercm/fabric/citresewn/mixin/cititem/ModelLoaderMixin.java | 15 |
2 files changed, 25 insertions, 23 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citelytra/ElytraFeatureRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citelytra/ElytraFeatureRendererMixin.java index db2241e..b4151f8 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citelytra/ElytraFeatureRendererMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citelytra/ElytraFeatureRendererMixin.java @@ -12,7 +12,7 @@ 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.Redirect; +import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import shcm.shsupercm.fabric.citresewn.CITResewn; import shcm.shsupercm.fabric.citresewn.OptionalCompat; @@ -25,7 +25,8 @@ public class ElytraFeatureRendererMixin { private WeakReference<ItemStack> elytraItemCached = new WeakReference<>(null); private WeakReference<LivingEntity> livingEntityCached = new WeakReference<>(null); - @Inject(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/entity/LivingEntity;FFFFFF)V", at = @At("HEAD")) + @Inject(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/entity/LivingEntity;FFFFFF)V", at = + @At("HEAD")) private void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, LivingEntity livingEntity, float f, float g, float h, float j, float k, float l, CallbackInfo ci) { if (!CITResewnConfig.INSTANCE().enabled || CITResewn.INSTANCE.activeCITs == null) return; @@ -39,21 +40,21 @@ public class ElytraFeatureRendererMixin { this.livingEntityCached = new WeakReference<>(livingEntity); } - @Redirect(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/entity/LivingEntity;FFFFFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/RenderLayer;getArmorCutoutNoCull(Lnet/minecraft/util/Identifier;)Lnet/minecraft/client/render/RenderLayer;")) - private RenderLayer getArmorCutoutNoCull(Identifier originalIdentifier) { - if (!CITResewnConfig.INSTANCE().enabled || CITResewn.INSTANCE.activeCITs == null) - return RenderLayer.getArmorCutoutNoCull(originalIdentifier); - - ItemStack itemStack = this.elytraItemCached.get(); - LivingEntity livingEntity = this.livingEntityCached.get(); - if (itemStack != null && itemStack.isOf(Items.ELYTRA) && livingEntity != null) { - Identifier elytraTexture = CITResewn.INSTANCE.activeCITs.getElytraTextureCached(itemStack, livingEntity.world, livingEntity); - this.elytraItemCached = new WeakReference<>(null); - this.livingEntityCached = new WeakReference<>(null); - if (elytraTexture != null) - return RenderLayer.getArmorCutoutNoCull(elytraTexture); + @ModifyArg(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/entity/LivingEntity;FFFFFF)V", at = + @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/ItemRenderer;getArmorGlintConsumer(Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/client/render/RenderLayer;ZZ)Lnet/minecraft/client/render/VertexConsumer;"), index = 1) + private RenderLayer getArmorCutoutNoCull(RenderLayer original) { + if (CITResewnConfig.INSTANCE().enabled && CITResewn.INSTANCE.activeCITs != null) { + ItemStack itemStack = this.elytraItemCached.get(); + LivingEntity livingEntity = this.livingEntityCached.get(); + if (itemStack != null && itemStack.isOf(Items.ELYTRA) && livingEntity != null) { + Identifier elytraTexture = CITResewn.INSTANCE.activeCITs.getElytraTextureCached(itemStack, livingEntity.world, livingEntity); + this.elytraItemCached = new WeakReference<>(null); + this.livingEntityCached = new WeakReference<>(null); + if (elytraTexture != null) + return RenderLayer.getArmorCutoutNoCull(elytraTexture); + } } - return RenderLayer.getArmorCutoutNoCull(originalIdentifier); + return original; } } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/cititem/ModelLoaderMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/cititem/ModelLoaderMixin.java index c8489fe..ec04910 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/cititem/ModelLoaderMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/cititem/ModelLoaderMixin.java @@ -20,7 +20,7 @@ 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.Redirect; +import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import shcm.shsupercm.fabric.citresewn.CITResewn; @@ -29,7 +29,6 @@ import shcm.shsupercm.fabric.citresewn.pack.ResewnTextureIdentifier; import shcm.shsupercm.fabric.citresewn.pack.cits.CIT; import shcm.shsupercm.fabric.citresewn.pack.cits.CITItem; -import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.*; @@ -155,10 +154,12 @@ public class ModelLoaderMixin { } } - @Redirect(method = "loadModelFromJson", at = @At(value = "INVOKE", target = "Lnet/minecraft/resource/ResourceManager;getResource(Lnet/minecraft/util/Identifier;)Lnet/minecraft/resource/Resource;")) - public Resource getResource(ResourceManager resourceManager, Identifier id) throws IOException { - if (id.getPath().endsWith(".json.json") && id.getPath().contains("cit")) - return resourceManager.getResource(new Identifier(id.getNamespace(), id.getPath().substring(7, id.getPath().length() - 5))); - return resourceManager.getResource(id); + @ModifyArg(method = "loadModelFromJson", at = + @At(value = "INVOKE", target = "Lnet/minecraft/resource/ResourceManager;getResource(Lnet/minecraft/util/Identifier;)Lnet/minecraft/resource/Resource;")) + public Identifier fixDuplicatePrefixSuffix(Identifier original) { + if (original.getPath().startsWith("models/models/") && original.getPath().endsWith(".json.json") && original.getPath().contains("cit")) + return new Identifier(original.getNamespace(), original.getPath().substring(7, original.getPath().length() - 5)); + + return original; } } |