This guide describes the public API in the current source version 0.1.11. Check that the mod is loaded when integrating conditionally.
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 if the item is ineligible, already processed, has no matching source data, or fails its chance roll.
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.1 uses the singular tags/item directory.
The defaults include NeoForge's #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.