Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package net.ltxprogrammer.changed.mixin.compatibility.CosmeticArmorReworked;

import net.ltxprogrammer.changed.client.renderer.layers.LatexHumanoidArmorLayer;
import net.ltxprogrammer.changed.entity.ChangedEntity;
import net.ltxprogrammer.changed.extension.RequiredMods;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.lang.reflect.Method;

/** Uses Cosmetic Armor Reworked's client-side cosmetic inventory when rendering Changed entities. */
@Mixin(LatexHumanoidArmorLayer.class)
@RequiredMods("cosmeticarmorreworked")
public abstract class LatexHumanoidArmorLayerMixin {
private static final Method GET_COSMETIC_STACKS = findMethod();

private static Method findMethod() {
try {
Class<?> api = Class.forName("lain.mods.cos.api.CosArmorAPI");
return api.getMethod("getCAStacksClient", java.util.UUID.class);
} catch (ReflectiveOperationException ignored) {
return null;
}
}

@Redirect(method = "renderArmorPiece", at = @At(value = "INVOKE", target = "Lnet/ltxprogrammer/changed/entity/ChangedEntity;getItemBySlot(Lnet/minecraft/world/entity/EquipmentSlot;)Lnet/minecraft/world/item/ItemStack;"))
private ItemStack changed$getCosmeticArmor(ChangedEntity entity, EquipmentSlot slot) {
if (GET_COSMETIC_STACKS == null || entity.getUnderlyingPlayer() == null)
return entity.getItemBySlot(slot);

int cosmeticSlot = switch (slot) {
case FEET -> 0;
case LEGS -> 1;
case CHEST -> 2;
case HEAD -> 3;
default -> -1;
};
if (cosmeticSlot < 0)
return entity.getItemBySlot(slot);

try {
Object stacks = GET_COSMETIC_STACKS.invoke(null, entity.getUnderlyingPlayer().getUUID());
boolean hideEquippedArmor = (boolean) stacks.getClass().getMethod("isSkinArmor", int.class).invoke(stacks, cosmeticSlot);
if (hideEquippedArmor)
return ItemStack.EMPTY;

ItemStack cosmetic = (ItemStack) stacks.getClass().getMethod("getStackInSlot", int.class).invoke(stacks, cosmeticSlot);
return cosmetic == null || cosmetic.isEmpty() ? entity.getItemBySlot(slot) : cosmetic;
} catch (ReflectiveOperationException | RuntimeException ignored) {
return entity.getItemBySlot(slot);
}
}
}
3 changes: 2 additions & 1 deletion src/main/resources/changed.compatibility.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"BeyondEarth.OxygenSystemMixin",
"CarryOn.HoldEntityAnimatorMixin",
"CarryOn.PickupHandlerMixin",
"CosmeticArmorReworked.LatexHumanoidArmorLayerMixin",
"Create.AdvancedHumanoidRendererMixin",
"Create.HumanoidAnimatorMixin",
"Curios.AdvancedHumanoidRendererMixin",
Expand Down Expand Up @@ -73,4 +74,4 @@
"injectors": {
"defaultRequire": 1
}
}
}
Loading