-
Notifications
You must be signed in to change notification settings - Fork 75
Slot Modifiers
This is a feature only in Curios 4.0.6.0+.
Slot modifiers are a way to dynamically add/remove slots from entities the same way modders could add/remove health or attack damage. In fact, it uses the exact same AttributeModifier
system to accomplish this.
The main method modders should use is ICuriosHelper#addSlotModifier(Multimap, String, UUID, double, AttributeModifier.Operation)
.
Parameters:
-
Multimap
- This is a multimap that normally contains theMultimap<Attribute, AttributeModifier
attribute map used for entities. Curios will add the slot modifiers to this map, wrapping the modifier in the appropriate logic to translate it into slots. -
String
- The identifier of the slot to add the modifier onto. -
UUID
- The UUID to use for the modifier. -
double
- The amount of the modifier. -
AttributeModifier.Operation
- The type of operation of the modifier. All operations are supported.
A very typical example of how a modder could override their ICurio#getAttributeModifiers(SlotContext, UUID)
implementation to incorporate a slot modifier that adds 6 ring slots when equipped in addition to its normal attribute modifier for movement speed.
@Override
public Multimap<Attribute, AttributeModifier> getAttributeModifiers(SlotContext slotContext, UUID uuid) {
Multimap<Attribute, AttributeModifier> atts = LinkedHashMultimap.create();
atts.put(Attributes.MOVEMENT_SPEED, new AttributeModifier(uuid, "speed_bonus", 0.1, AttributeModifier.Operation.MULTIPLY_TOTAL));
CuriosApi.getCuriosHelper().addSlotModifier(atts, "ring", uuid, 6.0, AttributeModifier.Operation.ADDITION);
return atts;
}
Sometimes, modders might want to add ways to permanently change the amount of slots a player has. This could be due to advancements, or getting past certain stages, or obtaining a certain item, or anything really. The way to do this is to obtain the ICurioStacksHandler
instance of the slot you're looking for and add an attribute modifier using ICurioStacksHandler#addPermanentModifier(AttributeModifier)
.
An example how a modder could permanently add 2 more ring slots to a player.
CuriosApi.getCuriosHelper().getCuriosHandler(player).ifPresent(handler -> {
handler.getStacksHandler("ring").ifPresent(stacks -> {
stacks.addPermanentModifier(new AttributeModifier(uuid, "name", 2, AttributeModifier.Operation.ADDITION));
});
});