diff options
Diffstat (limited to 'src')
4 files changed, 58 insertions, 1 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java index d96de20..bb99d49 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java @@ -3,6 +3,7 @@ package shcm.shsupercm.fabric.citresewn; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.fabricmc.loader.api.FabricLoader; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -17,6 +18,8 @@ public class CITResewn implements ClientModInitializer { public CITResewnConfig config = null; + public OptionalCompat compat = null; + public boolean processingBrokenPaths = false; @@ -25,6 +28,8 @@ public class CITResewn implements ClientModInitializer { INSTANCE = this; config = CITResewnConfig.read(); + + compat = new OptionalCompat(s -> FabricLoader.getInstance().isModLoaded(s)); } public static void info(String message) { diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/OptionalCompat.java b/src/main/java/shcm/shsupercm/fabric/citresewn/OptionalCompat.java new file mode 100644 index 0000000..7558d03 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/OptionalCompat.java @@ -0,0 +1,41 @@ +package shcm.shsupercm.fabric.citresewn; + +import io.github.apace100.cosmetic_armor.CosmeticArmor; +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; + +import java.util.function.Predicate; + +public final class OptionalCompat { + public static OptionalCompat INSTANCE() { + return CITResewn.INSTANCE.compat; + } + + public final CompatCosmeticArmor compatCosmeticArmor; + + public OptionalCompat(Predicate<String> isLoaded) { + compatCosmeticArmor = isLoaded.test("cosmetic-armor") ? CompatCosmeticArmor.impl() : null; + } + + public static ItemStack getCosmeticArmor(ItemStack original, LivingEntity entity, EquipmentSlot slot) { + if (INSTANCE().compatCosmeticArmor != null) { + ItemStack stackInCosmeticSlot = INSTANCE().compatCosmeticArmor.getStackInCosmeticSlot(entity, slot); + if (!stackInCosmeticSlot.isEmpty()) + return stackInCosmeticSlot; + } + + return original; + } + + /** + * Compatibility with 'cosmetic-armor': Display cits for cosmetic armors instead of equipped armors + */ + public interface CompatCosmeticArmor { + private static CompatCosmeticArmor impl() { + return CosmeticArmor::getCosmeticArmor; + } + + ItemStack getStackInCosmeticSlot(LivingEntity entity, EquipmentSlot slot); + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citarmor/ArmorFeatureRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citarmor/ArmorFeatureRendererMixin.java index 5fe1965..d8b78a4 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citarmor/ArmorFeatureRendererMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citarmor/ArmorFeatureRendererMixin.java @@ -15,6 +15,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import shcm.shsupercm.fabric.citresewn.CITResewn; +import shcm.shsupercm.fabric.citresewn.OptionalCompat; import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; import java.lang.ref.WeakReference; @@ -30,6 +31,10 @@ public class ArmorFeatureRendererMixin<T extends LivingEntity, M extends BipedEn return; ItemStack itemStack = entity.getEquippedStack(armorSlot); + + //compat Cosmetic Armor + itemStack = OptionalCompat.getCosmeticArmor(itemStack, entity, armorSlot); + Map<String, Identifier> armorTextures = CITResewn.INSTANCE.activeCITs.getArmorTextures(itemStack, entity.world, entity); if (armorTextures != null) { armorTexturesCached = new WeakReference<>(armorTextures); 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 f44871b..b5ef126 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 @@ -14,6 +14,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import shcm.shsupercm.fabric.citresewn.CITResewn; +import shcm.shsupercm.fabric.citresewn.OptionalCompat; import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; import java.lang.ref.WeakReference; @@ -28,7 +29,12 @@ public class ElytraFeatureRendererMixin { if (!CITResewnConfig.INSTANCE().enabled || CITResewn.INSTANCE.activeCITs == null) return; - this.elytraItemCached = new WeakReference<>(livingEntity.getEquippedStack(EquipmentSlot.CHEST)); + ItemStack itemStack = livingEntity.getEquippedStack(EquipmentSlot.CHEST); + + //compat Cosmetic Armor + itemStack = OptionalCompat.getCosmeticArmor(itemStack, livingEntity, EquipmentSlot.CHEST); + + this.elytraItemCached = new WeakReference<>(itemStack); this.livingEntityCached = new WeakReference<>(livingEntity); } |