Skip to content

Emit an event when a crafting job is completed - #222

Merged
rubensworks merged 2 commits into
master-1.21-ltsfrom
feature/crafting-job-finished-event
Sep 2, 2026
Merged

Emit an event when a crafting job is completed#222
rubensworks merged 2 commits into
master-1.21-ltsfrom
feature/crafting-job-finished-event

Conversation

@rubensworks

@rubensworks rubensworks commented Sep 2, 2026

Copy link
Copy Markdown
Member

Groundwork for #175 (toast notifications for completed crafting jobs). This PR only adds the hook; the toast itself lives in CyclopsMC/IntegratedTerminals#214.

What

CraftingJobFinishedEvent

A new event on the NeoForge event bus, emitted from CraftingNetwork#onCraftingJobFinished for jobs that ran to completion.

Two details worth calling out:

  • Cancelled jobs are excluded. CraftingNetwork#cancelCraftingJob cannot simply skip emitting, because it delegates to the crafting interface, which finalizes the job through the regular finishing logic a tick later. So cancelling marks the job via a new transient CraftingJob#isCancelled, which the emit checks. Jobs that disappear together with their crafting interface never reach onCraftingJobFinished at all, so they emit nothing either.
  • isRootJob() is captured when the event is constructed. The event is emitted for every completed job, including dependencies, and consumers generally only care about the job that was requested. CraftingJobDependencyGraph#onCraftingJobFinished clears the job's dependent links right after the emit, so reading getDependentCraftingJobs() later would report every job as a root job.

CraftingJob#notifyInitiator

A persisted flag next to the existing initiatorUuid, with which an initiator indicates that it wants to be notified once the job is completed. Set through a new CraftingHelpers#scheduleCraftingJobs overload; the existing signature delegates to it with false, so nothing changes for current callers.

CraftingJob#initialAmount

A persisted copy of the amount as it was when the job was scheduled. The regular amount is decremented while the job runs and is zero by the time the job finishes, so it cannot be used to describe what the job produced. Set for every scheduled job, not just for initiator-driven ones.

Tests

Three game tests in GameTestsCraftingJobFinishedEvent, each on the basic crafting network:

  • a completed job emits exactly one event for the requested job, carrying the initiator, the notify flag, and its initial amount
  • the notify flag stays unset when the initiator did not ask for it
  • a cancelled job emits no event

Each test filters events by a random initiator UUID, so concurrently running tests do not interfere.

Compatibility

Both new NBT fields default to false/0 when absent, so crafting jobs saved by older versions load unchanged. Jobs that were already running when a world is updated report an initialAmount of 0, which consumers should treat as unknown.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QNDY2pZtkXqJrhztYCvNbh

Adds CraftingJobFinishedEvent, which is emitted on the NeoForge event bus
for jobs that ran to completion. Cancelled jobs are excluded: cancelling
marks the job, because the crafting interface finalizes cancelled jobs
through the regular finishing logic a tick later.

Crafting jobs now also carry a notifyInitiator flag, so that initiators can
indicate that they want to be notified once the job is completed, and an
initialAmount, because the regular amount is decremented to zero while the
job runs.

Related to #175

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QNDY2pZtkXqJrhztYCvNbh
@rubensworks
rubensworks force-pushed the feature/crafting-job-finished-event branch from 5dbf41c to e7662c1 Compare September 2, 2026 18:50
@rubensworks
rubensworks merged commit 4a097a6 into master-1.21-lts Sep 2, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants