Add armor retexturing for skyblock items

This commit is contained in:
Linnea Gräf
2024-04-17 16:17:52 +02:00
parent 749f257161
commit fbe94315a4
3 changed files with 100 additions and 0 deletions

View File

@@ -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.

View File

@@ -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;
}
}
}

View File

@@ -14,6 +14,7 @@ import net.minecraft.block.SkullBlock
import net.minecraft.client.MinecraftClient import net.minecraft.client.MinecraftClient
import net.minecraft.client.render.RenderLayer import net.minecraft.client.render.RenderLayer
import net.minecraft.client.util.ModelIdentifier import net.minecraft.client.util.ModelIdentifier
import net.minecraft.item.ItemStack
import net.minecraft.util.Identifier import net.minecraft.util.Identifier
import moe.nea.firmament.events.CustomItemModelEvent import moe.nea.firmament.events.CustomItemModelEvent
import moe.nea.firmament.events.TickEvent import moe.nea.firmament.events.TickEvent
@@ -70,6 +71,23 @@ object CustomSkyBlockTextures : FirmamentFeature {
return Identifier("firmskyblock", "textures/placedskull/$id.png") 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( fun modifySkullTexture(
type: SkullBlock.SkullType?, type: SkullBlock.SkullType?,
profile: GameProfile?, profile: GameProfile?,