From fbe94315a45082bdf50d0a95583725352e3f20ec Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Wed, 17 Apr 2024 16:17:52 +0200 Subject: Add armor retexturing for skyblock items --- docs/Texture Pack Format.md | 14 +++++ .../nea/firmament/mixins/ArmorTexturePatch.java | 68 ++++++++++++++++++++++ .../features/texturepack/CustomSkyBlockTextures.kt | 18 ++++++ 3 files changed, 100 insertions(+) create mode 100644 src/main/java/moe/nea/firmament/mixins/ArmorTexturePatch.java diff --git a/docs/Texture Pack Format.md b/docs/Texture Pack Format.md index 9b5a66e..5e466bf 100644 --- a/docs/Texture Pack Format.md +++ b/docs/Texture Pack Format.md @@ -143,3 +143,17 @@ specify one of these other matchers and one color preserving property. } ``` +## Armor textures + +You can re-*texture* armors, but not re-*model* them with firmament. + +To do so, simply place the layer 1 and layer 2 armor +texture files at `assets/firmskyblock/textures/models/armor/{skyblock_id}_layer_1.png` and +`assets/firmskyblock/textures/models/armor/{skyblock_id}_layer_2.png` respectively. + +If you want to re-texture a leather +armor you can use `assets/firmskyblock/textures/models/armor/{skyblock_id}_layer_1_overlay.png` and +`assets/firmskyblock/textures/models/armor/{skyblock_id}_layer_2_overlay.png` instead. Doing this will cancel out the +regular leather colors. If you want the leather colors to be applied, supply the normal non-`_overlay` variant, and +also supply a blank `_overlay` variant. You can also put non-color-affected parts into the `_overlay` variant. + 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 + * + * 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, A extends BipedEntityModel> { + @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 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; + } + } +} diff --git a/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt b/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt index 66c0036..3fb5e9c 100644 --- a/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt +++ b/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt @@ -14,6 +14,7 @@ import net.minecraft.block.SkullBlock import net.minecraft.client.MinecraftClient import net.minecraft.client.render.RenderLayer import net.minecraft.client.util.ModelIdentifier +import net.minecraft.item.ItemStack import net.minecraft.util.Identifier import moe.nea.firmament.events.CustomItemModelEvent import moe.nea.firmament.events.TickEvent @@ -70,6 +71,23 @@ object CustomSkyBlockTextures : FirmamentFeature { return Identifier("firmskyblock", "textures/placedskull/$id.png") } + fun getArmorTexture( + itemStack: ItemStack, secondLayer: Boolean, + overlay: String? + ): Identifier? { + val modelIdentifier = CustomItemModelEvent.getModelIdentifier(itemStack) ?: return null + // Vanilla scheme: "textures/models/armor/" + var10000 + "_layer_" + (secondLayer ? 2 : 1) + (overlay == null ? "" : "_" + overlay) + ".png"; + val overlayPart = if (overlay != null) "_$overlay" else "" + val identifier = Identifier( + modelIdentifier.namespace, + "textures/models/armor/${modelIdentifier.path}_layer_${if (secondLayer) 2 else 1}$overlayPart.png" + ) + if (MC.resourceManager.getResource(identifier).isPresent) { + return identifier + } + return null + } + fun modifySkullTexture( type: SkullBlock.SkullType?, profile: GameProfile?, -- cgit