-
Notifications
You must be signed in to change notification settings - Fork 0
Items
Butterfly API includes item helpers for three common Minecraft 1.21.11 tasks:
- displayed attack speed modifiers
- separate GUI and held item models
- custom progress bars beneath item stacks
Vanilla attack speed attributes use a modifier based on displayed speed - 4.0.
ItemUtils lets you work with the attack speed value you actually want players to see.
import moth.butterflyapi.item.ItemUtils;
import net.minecraft.item.Item;
public static final Item QUICK_BLADE = MOD.item(
"quick_blade",
settings -> new Item(ItemUtils.combatAttributes(
settings,
MOD.id("quick_blade"),
5.0D,
1.8D))
);In this example:
-
5.0Dis the attack damage -
1.8Dis the displayed attack speed
ItemUtils.displayedAttackSpeed(
settings,
MOD.id("fast_tool"),
2.4D
);double vanillaModifier =
ItemUtils.attackSpeedModifier(1.6D);Minecraft 1.21.11 uses item model definitions under:
assets/<modid>/items/<id>.json
Butterfly API can generate the JSON needed for an item that uses one model in the GUI and another while held.
import moth.butterflyapi.item.ItemModelDefinitions;
var models = ItemModelDefinitions.separateGuiAndHeld(
MOD.id("twisted_spade")
);
String itemDefinitionPath = models.itemDefinitionPath();
String itemDefinitionJson = models.itemDefinitionJson();
String guiModelJson = models.guiModelJson(
MOD.id("item/twisted_spade_gui")
);
String heldModelJson = models.heldModelJson(
MOD.id("item/twisted_spade")
);The default output paths are:
assets/<modid>/items/<id>.json
assets/<modid>/models/item/<id>.json
assets/<modid>/models/item/<id>_held.json
The held model is used for:
firstperson_lefthandfirstperson_righthandthirdperson_lefthandthirdperson_righthand
The GUI model is used as the fallback for inventory, ground, fixed, and other contexts.
Butterfly API can render custom progress bars beneath item stacks.
import moth.butterflyapi.item.bar.ItemProgressBars;
ItemProgressBars.register(
TWISTED_SPADE,
0xE63F51,
stack -> charge(stack)
);The progress function should normally return a value from:
0.0
to:
1.0
where 0.0 is empty and 1.0 is full.
import moth.butterflyapi.item.bar.ItemProgressBar;
ItemProgressBars.register(
TWISTED_CORE,
stack -> List.of(
ItemProgressBar.of(
primaryProgress(stack),
0x66CCFF
),
ItemProgressBar.of(
secondaryProgress(stack),
0xFFD166,
false
)
)
);This allows an item to display multiple separate rows.
Use registerLayered(...) when one value can progress through multiple full layers.
ItemProgressBars.registerLayered(
TWISTED_SPADE,
true,
stack -> storedCycles(stack),
0xE63F51,
0x8A4DFF,
0xFFD166
);Layered progress can be greater than 1.0.
For example:
2.35
means:
- two completed layers
- 35% progress through the next layer
Butterfly renders layered bars in constant time, so large progress values do not require every completed layer to be drawn individually.
pixelSnap controls how the visible bar width is rounded.
Rounds to pixel steps for a crisp vanilla-style bar.
Uses ceiling behavior so very small non-zero progress becomes visible sooner.