diff options
author | Linnea Gräf <nea@nea.moe> | 2024-04-17 16:17:52 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-04-17 16:17:52 +0200 |
commit | fbe94315a45082bdf50d0a95583725352e3f20ec (patch) | |
tree | 7ff4018c9edab6a36dba78b79b8b3c19e86b7ec1 /src/main/java/moe/nea/firmament | |
parent | 749f2571614a8e8cf57080518518b686ee983b8c (diff) | |
download | firmament-fbe94315a45082bdf50d0a95583725352e3f20ec.tar.gz firmament-fbe94315a45082bdf50d0a95583725352e3f20ec.tar.bz2 firmament-fbe94315a45082bdf50d0a95583725352e3f20ec.zip |
Add armor retexturing for skyblock items
Diffstat (limited to 'src/main/java/moe/nea/firmament')
-rw-r--r-- | src/main/java/moe/nea/firmament/mixins/ArmorTexturePatch.java | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/main/java/moe/nea/firmament/mixins/ArmorTexturePatch.java b/src/main/java/moe/nea/firmament/mixins/ArmorTexturePatch.java new file mode 100644 index 0000000..4e6c1cd --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/ArmorTexturePatch.java @@ -0,0 +1,68 @@ +/* + * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe> + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package moe.nea.firmament.mixins; + + +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; +import com.llamalad7.mixinextras.sugar.Local; +import moe.nea.firmament.features.texturepack.CustomSkyBlockTextures; +import net.minecraft.client.render.VertexConsumer; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.entity.feature.ArmorFeatureRenderer; +import net.minecraft.client.render.entity.model.BipedEntityModel; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ArmorItem; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(ArmorFeatureRenderer.class) +public abstract class ArmorTexturePatch<T extends LivingEntity, M extends BipedEntityModel<T>, A extends BipedEntityModel<T>> { + @Unique + private ItemStack lastRenderedArmorItem; + + @Unique + private boolean foundCustomTexture; + + @WrapWithCondition(method = "renderArmorParts", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;IIFFFF)V")) + private boolean preventRenderingLeatherArmorColor(BipedEntityModel instance, MatrixStack matrixStack, + VertexConsumer vertexConsumer, int light, int uv, + float r, float g, float b, float a, + @Local(argsOnly = true) @Nullable String overlay) { + if (overlay != null) return true; + if (foundCustomTexture) return true; + var customOverlayTexture = CustomSkyBlockTextures.INSTANCE.getArmorTexture(this.lastRenderedArmorItem, false, "overlay"); + return customOverlayTexture == null; + } + + @Inject(method = "renderArmor", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getItem()Lnet/minecraft/item/Item;")) + private void onBeforeRenderArmor(MatrixStack matrices, VertexConsumerProvider vertexConsumers, + T entity, EquipmentSlot armorSlot, int light, A model, CallbackInfo ci, + @Local ItemStack itemStack) { + this.lastRenderedArmorItem = itemStack; + } + + @Inject(method = "getArmorTexture", at = @At("HEAD"), cancellable = true) + private void onGetTexture(ArmorItem item, boolean secondLayer, String overlay, CallbackInfoReturnable<Identifier> cir) { + if (this.lastRenderedArmorItem == null) return; + var armorTexture = CustomSkyBlockTextures.INSTANCE.getArmorTexture(this.lastRenderedArmorItem, secondLayer, overlay); + if (armorTexture != null) { + cir.setReturnValue(armorTexture); + this.foundCustomTexture = true; + } else { + this.foundCustomTexture = false; + } + } +} |