Immersive Wool: Java API
MC 1.20.1Forge~3 min read
On this page (7)
Package com.otectus.immersivewool.api (ImmersiveWoolAPI.API_VERSION = 1). Register integrations from your mod constructor or FMLCommonSetupEvent. Unless noted otherwise, all methods and events run on the logical server.
Reading yarn grades
Optional<YarnGrade> grade = ImmersiveWoolAPI.readYarnGrade(stack);
- Returns
Optional.empty()for anything that is not an Immersive WoolYarnItem, or for yarn whoseimmersive_woolNBT compound uses an unsupported newer schema (schema != 1) or unknown grade string (never silently downgraded). - Yarn without an
immersive_woolNBT compound reads asYarnGrade.STANDARD. YarnGradevalues andrepresentativeScore():CRUDE(20, min0),STANDARD(50, min35),FINE(80, min70),MASTERWORK(100, min90).
Completion events (Forge event bus, not cancelable)
Both events are posted on MinecraftForge.EVENT_BUS on the server thread after output items are committed, tool wear is applied, and the job ledger is closed.
| Event | Posted when | Fields exposed |
|---|---|---|
WoolSpunEvent |
Productive carding-and-spinning session finishes |
jobId() (UUID), recipeId(), fleeceUnits(), output() (copy with grade NBT), score() (0–100), grade() (@Nullable YarnGrade), starter(), finisher(), practice() (false) |
TextileWovenEvent |
Weaving job finishes (both artisan and fixed string weaving) |
jobId() (UUID), recipeId(), output() (copy, count = base + bonus), baseOutput(), bonusOutput(), scored(), yarnScore() (-1 if unscored), weavingScore() (-1 if unscored), craftsmanship() (-1 if unscored), starter(), finisher(), practice() (false) |
Event guarantees
- Once per job ID: Seal/resume cycles,
Unfinished Textile Batchrecovery,READYdelivery retries, world reloads, and duplicate finish packets never post a second event. - Never fired for side routes: Never posted for Practice mode, washing, drying, dyeing, unravelling, or import sorting.
- Safe copies:
output()returns a freshItemStackcopy on each call; listeners never gain mutable references to station inventories. No synthetic vanillaPlayerEvent.ItemCraftedEventis fired. - Exception safety: Exceptions thrown by a listener are caught and logged without reverting or repeating completion.
Recipe gates
ImmersiveWoolAPI.registerRecipeGate((player, operation, recipeId) ->
allowed ? null : Component.translatable("mymod.not_yet"));
- Consulted on the server before a player starts a job (e.g., progression/skill level locks). Returning a non-null
Componentcancels reservation before any items, water, or tool durability are touched and displays the message to the player. - Never consulted for unattended automation-started passive jobs (
Auto: On). - Exceptions thrown by a gate are caught, logged, and treated as allow so a broken integration never locks a world.
Assistance providers
ImmersiveWoolAPI.registerAssistProvider((player, operation) -> 1.25);
- Returns a timing/control assistance multiplier (
>= 1.0). - At Start, the server takes
max(playerRequest, maxProviderAssist), clamps it to[1.0, accessibility.maxTimingAssist], and snapshots it into the job. - Only widens timing windows and slows tension drift/rate — never acts as a yield multiplier, and the maximum attainable score remains
100.
Harvest adapters
List<ItemStack> converted = ImmersiveWoolAPI.convertHarvest(entity, HarvestPath.FORGE_SHEAR, player, drops);
ImmersiveWoolAPI.registerSourceAdapter(new SourceAdapterDeclaration(
"mymod",
"[1.2,1.3)",
Set.of(HarvestPath.FORGE_SHEAR),
false,
"MySheep custom shearing"
));
convertHarvestapplies Immersive Wool’s exact rules (HarvestOwnership,fiber_sources, exclusions, NBT preservation) to a harvest drop list and returns a newList<ItemStack>without mutating the input list. Call once per harvest on the logical server.- Note that
registerSourceAdapteradds no hooks on its own — it informs/immersivewool sourcesabout which modded harvest paths your integration handles, and still requires a matchingfiber_sourcesdatapack entry for the entity.
Stability boundary
Everything outside com.otectus.immersivewool.api — including SessionManager, TextileJob, block entities, menus, packets, and internal test seams — is internal and may change without notice.