-
Notifications
You must be signed in to change notification settings - Fork 0
API
Applies to all versions. The package and the entry points are the same everywhere; the base class of
CAStacksBaseand the death-drop hook depend on the loader (both are shown below).
Armor Cosmetic has a small Java API in the package com.skd.armorcosmetic.api. Add the Armor Cosmetic JAR for your Minecraft version and loader as a compile dependency; the source of every build is on its branch of codex-skd/armor-cosmetic.
import com.skd.armorcosmetic.api.CosArmorAPI;
import com.skd.armorcosmetic.api.inventory.CAStacksBase;
CAStacksBase stacks = CosArmorAPI.getCAStacks(player.getUUID()); // server side
CAStacksBase view = CosArmorAPI.getCAStacksClient(player.getUUID()); // client side, read only| Method | Side | Notes |
|---|---|---|
CosArmorAPI.getCAStacks(UUID) |
Server | The real inventory. Changes are saved and sent to every client. Loads the player's data if needed. |
CosArmorAPI.getCAStacksClient(UUID) |
Client | The copy received from the server. Read it only: changes made here are not sent to the server. |
The inventory has 4 slots:
| Index | Slot |
|---|---|
| 0 | Feet |
| 1 | Legs |
| 2 | Chest |
| 3 | Head |
Methods available on every build:
| Method | Description |
|---|---|
int getSlots() |
Number of slots (4). |
ItemStack getStackInSlot(int slot) |
The cosmetic item in a slot. |
void setStackInSlot(int slot, ItemStack stack) |
Replaces the cosmetic item in a slot. |
boolean isSkinArmor(int slot) / void setSkinArmor(int slot, boolean value)
|
The per-slot skin toggle (see Cosmetic inventory). |
boolean isHidden(String modid, String identifier) |
See Hiding other mods' items. |
boolean setHidden(String modid, String identifier, boolean hide) |
Returns true if the value changed. |
void forEachHidden(BiConsumer<String, String> consumer) |
Iterates over every hidden (modid, identifier) pair. |
CompoundTag serializeNBT(HolderLookup.Provider) / void deserializeNBT(HolderLookup.Provider, CompoundTag)
|
Save format used for the .cosarmor file. |
| Build | CAStacksBase |
|---|---|
| NeoForge 1.21.1, 26.1.2, 26.2 (all 26.2 builds) | Extends NeoForge's net.neoforged.neoforge.items.ItemStackHandler, so the methods of that class are also available. |
| NeoForge 26.3 and every Fabric build | Standalone class with only the methods listed above. |
Use only the methods in the first table if your code must work on every build.
Each player also has a set of hidden flags: (modid, identifier) pairs that are saved with the cosmetic inventory and sent to every client. Armor Cosmetic does not use them itself; they let another mod store "hide this item of mine" choices per player (for example for an accessory slot).
// server side: hide the "backpack" item of the mod "mymod" for this player
CosArmorAPI.getCAStacks(player.getUUID()).setHidden("mymod", "backpack", true);
// client side, while rendering:
boolean hidden = CosArmorAPI.getCAStacksClient(player.getUUID()).isHidden("mymod", "backpack");Armor Cosmetic fires a hook just before it drops a dead player's cosmetic items (only when they would be dropped, see Death and storage). Cancel it to keep the items in the cosmetic slots.
NeoForge (all versions): com.skd.armorcosmetic.api.event.CosArmorDeathDrops is a cancellable event on NeoForge.EVENT_BUS.
NeoForge.EVENT_BUS.addListener((CosArmorDeathDrops event) -> {
Player player = event.getEntityPlayer();
CAStacksBase stacks = event.getCAStacks();
if (shouldKeep(player)) {
event.setCanceled(true);
}
});Fabric (all versions): CosArmorDeathDrops.EVENT is a Fabric API event. Return false to cancel; the first listener that returns false wins.
CosArmorDeathDrops.EVENT.register((player, stacks) -> !shouldKeep(player));Armor Cosmetic is a fork of CosmeticArmorReworked by zlainsama and dmillerw, distributed under the Minecraft Mod Public License (MMPL) 1.0.1. Not affiliated with or endorsed by the original authors.