Repository navigation
Accessories and Armor
Accessories and armor are items the player wears. Armor goes in the three armor
slots and can form a set, which gives an extra bonus when all three pieces are
worn together. Accessories go in the accessory slots and change the player
while they are equipped, and wings are accessories that let the player fly. All
of them are ModItems with a few extra hooks, and the [AutoloadEquip]
attribute you will see below is what gives them a look on the player's body.
[AutoloadEquip(EquipType.Head)]
public class ExampleHelmet : ModItem
{
public override bool IsArmorSet(Item head, Item body, Item legs) =>
body.type == ModContent.ItemType<ExampleBreastplate>() && legs.type == ModContent.ItemType<ExampleLeggings>();
public override void UpdateArmorSet(Player player) => player.meleeDamage += 0.2f;
}[AutoloadEquip(EquipType.Head, ...)] takes the worn textures next to the
item's: ExampleHelmet_Head.png, _Body, _Legs, _Wings, _Shield,
_Back... Each gets a slot after the game's (Item.headSlot,
Item.wingSlot... are set before your SetDefaults). In SetStaticDefaults, Item is the template item, as in
tModLoader, so wings can write
ArmorIDs.Wing.Sets.Stats[Item.wingSlot] = new WingStats(180, 9f, 2.5f);.
EquipLoader.AddEquipTexture(mod, texture, type, name: "...") in Load
adds one by hand; its slot exists from SetStaticDefaults on
(EquipLoader.GetEquipSlot(mod, name, type)).
The hooks are tModLoader's: UpdateEquip, UpdateAccessory(player, hideVisual), UpdateVanity, CanAccessoryBeEquippedWith, IsArmorSet and
UpdateArmorSet (on each worn piece), IsVanitySet (by the drawn slots; by
default the IsArmorSet of those slots' items), PreUpdateVanitySet,
UpdateVanitySet, ArmorSetShadows, SetMatch, EquipFrameEffects,
VerticalWingSpeeds, HorizontalWingSpeeds, WingUpdate. A GlobalItem
has them with the Item first and the set as a string, and an
EquipTexture subclass can replace them for one texture.
The set bonus text is tModLoader's player.setBonus, set in
UpdateArmorSet (or anywhere in the player's update):
public static LocalizedText SetBonusText { get; private set; }
public override void SetStaticDefaults() =>
SetBonusText = this.GetLocalization("SetBonus").WithFormatArgs(AdditiveGenericDamageBonus);
public override void UpdateArmorSet(Player player)
{
player.setBonus = SetBonusText.Value;
player.GetDamage(DamageClass.Generic) += AdditiveGenericDamageBonus / 100f;
}The game has no Player.setBonus since 1.4.5.8 (its sets are in
ArmorSetBonuses); the Bunny Loader keeps the text per player, clears it at
the start of each UpdateArmorSets and adds a SetBonus line, in the game's
"Set Bonus: ..." format and green, to the worn pieces' tooltip (an item the
game already gives a set line keeps the game's). ModifyTooltips sees it as
Terraria/SetBonus. WithFormatArgs makes a new text with the arguments
filled in; it does not follow a language change made after it.
DrawArmorColor(drawPlayer, shadow, ref color, ref glowMask, ref glowMaskColor) (head, body and legs) and ArmorArmGlowMask(drawPlayer, shadow, ref glowMask, ref color) (the body's arms) run through the worn
slot's EquipTexture (by default the item's) and then the GlobalItems,
after the game's PlayerDrawSet.BoringSetup. Since that is after the game's
own effects (buff tints, stealth), a part the game made fully transparent
keeps its color; a changed glow color gets the game's immunity blink
(GetImmuneAlphaPure). glowMask is one of the game's glow masks
(GlowMaskID).
CanEquipAccessory(player, slot, modded) (false refuses) is asked when
the item is dropped on an accessory slot (ItemSlot.PickItemMovementAction),
on the quick swap (ItemSlot.ArmorSwap: the swap is undone and the item
stays where it was) and by the phone's ItemSlot.CanEquipAccessoryInSlot /
CanEquipAccessoryInVanitySlot. slot is the index in player.armor;
modded is true for the slots a ModAccessorySlot adds.
tModLoader's drawing flags are on the game's sets, sized to the slots
(the mod ones included), with tModLoader's defaults for the game's:
ArmorIDs.Head.Sets.DrawFullHair, DrawHatHair,
DrawsBackHairWithoutHeadgear (read after Player.GetHairSettings),
ArmorIDs.Body.Sets.HidesTopSkin, HidesBottomSkin, HidesHands (default
true), HidesArms and ArmorIDs.Legs.Sets.HidesTopSkin,
HidesBottomSkin (applied after BoringSetup). Set them in
SetStaticDefaults, as ExampleRobe does:
public override void SetStaticDefaults() => ArmorIDs.Body.Sets.HidesHands[Item.bodySlot] = false;They only add to what the game decides: a true hides, a HidesHands of
false shows the hand, a HidesArms of true hides the arm. The hooks are
installed the first time a mod reads one of these sets.
Not on the phone yet: ArmorIDs.Head.Sets.IsTallHat.
ModItem.ModifyEquipTextureDraw(ref drawInfo, ref drawData, equipTexture, methodName)
(through EquipTexture.ModifyDraw) changes the draw of the item's equip texture
or adds others to drawInfo.DrawDataCache; false drops the original.
ExampleCustomDrawWings draws the wing with a glow this way. On the phone it
runs for wings, back, balloons, shoes, waist, neck and shields; the other equip
types (head, body, legs, face, front) do not call it yet.
ExampleCostume shows the rest of a full costume: EquipLoader.AddEquipTexture
with a name for each set, ArmorIDs.Head.Sets.DrawHead[slot] = false (the
game's HidesHead, inverted), ArmorIDs.Body.Sets.HidesTopSkin, and
ModPlayer.FrameEffects swapping Player.head, body and legs.
ExampleDashPlayer (in ExampleShield.cs) is a dash made in
ModPlayer.PreUpdateMovement with DashID.None as the check that no other dash
is on. On the phone Item.backSlot and the other slots are sbyte, and the
WaspNest swaps the bee type with On_Player.beeType where tModLoader uses IL.
A ModAccessorySlot gives the player one more accessory slot, with its own
vanity and dye slots, as in tModLoader. The simplest one is an empty class,
and the Example Mod has exactly that:
public class ExampleModAccessorySlot1 : ModAccessorySlot
{
}On the phone the mod slots do not crowd the game's column. In the equipment screen a button appears just left of the star, and it opens a panel next to the game's accessories: each row is a dye, a vanity and an accessory slot, with the eye that hides the accessory's look, two rows at a time, and the ▲ and ▼ buttons turn the pages when there are more. A selected mod slot works with the game's own buttons, the eye and the unequip button included.
A slot can be choosy. The Example Mod's wing slot only takes wings, receives them first when the player equips wings from the inventory, and only exists while the player wears something on the head:
public override bool CanAcceptItem(Item checkItem, AccessorySlotType context)
{
if (checkItem.wingSlot > 0)
return true;
return false;
}
public override bool ModifyDefaultSwapSlot(Item item, int accSlotToSwapTo)
{
if (item.wingSlot > 0)
return true;
return false;
}
public override bool IsEnabled()
{
if (Player.GetEffectiveArmor(0).headSlot >= 0)
return true;
return false;
}CanAcceptItem is asked for each of the three slots, with context saying
which one. ModifyDefaultSwapSlot returning true sends the item to this
slot instead of the game's when it is equipped straight from the inventory.
IsEnabled turns the slot off while it returns false, and
IsVisibleWhenNotEnabled decides whether a turned off slot still shows; by
default it shows while it holds something, so nothing gets lost. The slot's
items are FunctionalItem, VanityItem and DyeItem, and the slot also
answers IsEmpty, HideVisuals, OnMouseHover (the text when a finger is
on it) and the textures of each slot's background and icon
(FunctionalTexture, DyeBackgroundTexture and so on).
The items in mod slots are saved with the character, apart from the game's
own slots, and follow the equipment loadouts unless
HasEquipmentLoadoutSupport returns false. Unlike tModLoader, the class
that holds every player's mod slots is not a ModPlayer, so
GetModPlayer<ModAccessorySlotPlayer>() does not work: go through the slot
itself.
Bunny Loader wiki ·
Discord ·
Repository ·
BL Editor
Written for Bunny Loader 0.5.5-beta and Terraria Mobile 1.4.5.8.6.
Bunny Loader is not affiliated with Re-Logic or 505 Games.
