-
Notifications
You must be signed in to change notification settings - Fork 79
Quick Start Guide
Trinkets is a large library with a lot of information to digest, and that can be overwhelming. There is, however, a large group of people that just want to use it in a very simple way, and don't want to dive into all the specifics. This guide is, therefore, an abridged easy getting started guide for adding your own trinkets.
An important first step is adding the slots you want to use. Trinkets data is managed with data packs, so an extremely basic understanding on how that works is fundamental. For a simple mod, you'll want to pick one of the default slots for your item, though further Trinkets documentation can explain how to add your own custom slots and slot groups. For this guide, feet/aglet
will be used. To enable a slot for players, you need to create a file in data/trinkets/entities/
, it can be named whatever you want, but it is suggested to be [modid].json
. A simple file to add the aglet slot will look like this:
data/trinkets/entities/guidemod.json
{
"entities": [
"player"
],
"slots": [
"feet/aglet"
]
}
When you boot up the game, you should notice that hovering over the feet slot in the inventory will pop up that slot group, and the aglet slot will now be accessible. On to adding an item. The simplest way to register a trinket item is to simple register an item that extends TrinketItem
, like the example below:
public class MyAglet extends TrinketItem {
public MyAglet(Settings settings) {
super(settings);
}
public Multimap<EntityAttribute, EntityAttributeModifier> getModifiers(ItemStack stack, SlotReference slot, LivingEntity entity, UUID uuid) {
var modifiers = super.getModifiers(stack, slot, entity, uuid);
// +10% movement speed
modifiers.put(EntityAttributes.GENERIC_MOVEMENT_SPEED, new EntityAttributeModifier(uuid, "guidemod:movement_speed", 0.1, EntityAttributeModifier.Operation.MULTIPLY_TOTAL));
// If the player has access to ring slots, this will give them an extra one
SlotAttributes.addSlotModifier(modifiers, "hand/ring", uuid, 1, EntityAttributeModifier.Operation.ADDITION);
return modifiers;
}
}
If you register this like any other item, it should work as a trinket when equipped in the aglet slot. But currently, it cannot be equipped anywhere, because this has not been specified. Trinket slots, by default, validate items using item tags, located at data/trinkets/tags/items/[group]/[slot].json
. So for this example, adding this file work:
data/trinkets/tags/items/feet/aglet.json
:
{
"replace": false,
"values": [
"guidemod:my_aglet"
]
}
In game, you should be able to equip an aglet that makes you run a bit faster and gives an extra ring slot, if paired with a mod that enables rings for players.