This guide describes the public API in the current source version 0.4.0. Check that the mod is loaded when integrating conditionally. The API uses no loader classes, so the same calls work on Fabric and NeoForge (Minecraft 1.20.6, 1.21.1, 1.21.11 and 26.1 to 26.3). Each target is published as com.fyxe.ffitemraritymodifiers:ffitemraritymodifiers-<minecraft>-<loader>:0.3.1, for example ffitemraritymodifiers-1.21.1-fabric or ffitemraritymodifiers-1.21.11-neoforge, on the Fyxe Gitea Maven registry.
Item Rarity Modifiers — Modding API
Entry point: com.fyxe.ffitemraritymodifiers.api.RarityModifierApi. Use it when your mod creates an item outside the built-in crafting, loot, or trade paths.
Roll a custom source
ResourceLocation source = ResourceLocation.fromNamespaceAndPath("mymod", "quest_reward");
boolean changed = RarityModifierApi.tryApplyRaritySource(
reward, source, level.getRandom(), level.registryAccess());
The method takes an ItemStack, source ResourceLocation, RandomSource, and HolderLookup.Provider. It returns true when the stack changes. It is a safe no-op only if the item is ineligible or already processed. Otherwise the item always gets a rarity: a failed chance roll or an unknown source gives Common.
Pair code with data
Create data/mymod/ffitemraritymodifiers/rarity_source/quest_reward.json so pack authors can configure the source's chance and rarity weights. The source ID in code must match the namespace and file path. See the mod's README and shipped datapack files for the current schema.
Call from the logical server path that hands out the reward. Do not call repeatedly on the same stack in a tick; the API guards already processed items, but the best integration point is item creation.
Choose eligible items with tags
The API and built-in sources accept only single-stack items in ffitemraritymodifiers:weapons, :armor, :tools, or :accessories. Add items or another tag to one of these tags using data/ffitemraritymodifiers/tags/item/<category>.json. Minecraft 1.21 and newer use the singular tags/item directory; 1.20.6 uses tags/items.
The defaults include the shared #c:tools/melee_weapon and #c:tools/ranged_weapon for weapons, #c:armors plus elytra and wolf armor for armor, and #c:tools plus the two vanilla riding sticks for tools. The separate mining_tools tag contains vanilla pickaxes, axes, shovels, hoes, and shears plus #c:tools/mining_tool. Mining tools take priority over weapons, so axes stay in the tool category. The accessories tag is empty until a datapack or another mod fills it. An item class alone does not make an item eligible.
{"values":["mymod:quest_blade", "#mymod:relic_weapons"]}
Limit a modifier to an item tag
A modifier_type definition can set optional required_item_tag alongside applies_to. The category and tag must both match before that modifier enters a roll. Use the tag ID without a leading #. Existing definitions without this field continue to apply to their whole category.
{"category":"good","kind":"attribute","family":"fishing_luck","applies_to":["tool"],"required_item_tag":"c:tools/fishing_rod","attribute":"minecraft:generic.luck","operation":"add_value","slot":"mainhand","base_value":0.25,"short_name":"mymod.modifier.lucky_rod.short","detailed_name":"mymod.modifier.lucky_rod.detailed"}
This example follows the current ModifierType codec. Add translations for both name keys. The built-in definitions use tag restrictions to keep melee attack bonuses off bows and fishing luck on rods.