Interface ReplaceableResultSupplier
-
- All Implemented Interfaces:
-
io.github.sakaki_aruka.customcrafter.result.ResultSupplier
public interface ReplaceableResultSupplier implements ResultSupplier
A subinterface of ResultSupplier that writes items back into the crafting UI slots after a craft completes, instead of (or in addition to) giving them to the player.
Typical use cases include ingredient transformation (e.g. returning a modified tool to the grid) and byproduct placement (e.g. returning an empty bucket after consuming a filled one).
supply is called on an executor thread (async).
replaceQueries is invoked on the calling thread, before the async dispatch, to build the slot-to-item mapping.
All UI access (
getItem/setItem) is dispatched to the entity's regional scheduler via a singlerunAtEntitycall, ensuring thread safety for both Paper and Folia.After all slots are processed (or the timeout elapses), replaceResultHandler is called with the result of each slot operation.
supply itself always returns an empty list; item delivery to the player's inventory is the responsibility of replaceResultHandler if needed.
If the entity scheduler does not execute within timeoutMilli milliseconds, all slots that have not been processed yet are marked ReplaceState.TIMEOUT and replaceResultHandler is still called.
- Since:
5.0.21
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enumReplaceableResultSupplier.ReplaceStateRepresents the outcome of a single slot write-back attempt.
public final classReplaceableResultSupplier.ContextA subset of ResultSupplier.Context passed to replaceQueries and replaceResultHandler.
This class exposes the same fields as ResultSupplier.Context but omits ResultSupplier.Context.asyncContext, which is not relevant to slot write-back logic.
-
Method Summary
Modifier and Type Method Description List<ItemStack>supply(ResultSupplier.Context ctx)Executes the slot write-back logic and always returns an empty list. LongtimeoutMilli()Returns the maximum number of milliseconds to wait for the entity scheduler to execute the slot write-back. abstract Map<CoordinateComponent, ItemStack>replaceQueries(ReplaceableResultSupplier.Context ctx)Builds the mapping of crafting-grid slots to items that should be written back. abstract UnitreplaceResultHandler(Map<CoordinateComponent, ReplaceableResultSupplier.ReplaceState> results, Map<CoordinateComponent, ItemStack> usedQueries, ReplaceableResultSupplier.Context usedContext)Called after all slot write-back attempts have completed (or timed out). -
-
Method Detail
-
supply
List<ItemStack> supply(ResultSupplier.Context ctx)
Executes the slot write-back logic and always returns an empty list.
The actual placement is performed asynchronously on the entity's regional scheduler. Item delivery to the player, if required, should be handled inside replaceResultHandler.
- Parameters:
ctx- Context provided by the recipe system- Returns:
An empty list — slot placement and any player-facing delivery are handled by replaceResultHandler
- Since:
5.0.21
-
timeoutMilli
Long timeoutMilli()
Returns the maximum number of milliseconds to wait for the entity scheduler to execute the slot write-back.
If this duration elapses before execution completes, unprocessed slots are marked ReplaceState.TIMEOUT and replaceResultHandler is still invoked. Defaults to
1000ms.- Returns:
Timeout duration in milliseconds
- Since:
5.0.21
-
replaceQueries
abstract Map<CoordinateComponent, ItemStack> replaceQueries(ReplaceableResultSupplier.Context ctx)
Builds the mapping of crafting-grid slots to items that should be written back.
This function is called on the same thread that invoked supply, before the async dispatch. Avoid accessing Bukkit API or game state directly; use the provided ctx instead.
Entries whose coordinates are not present in io.github.sakaki_aruka.customcrafter.ui.CraftUIDesigner.Baked.craftSlots are recorded as ReplaceState.OUT_OF_SLOTS_AREA and skipped.
- Parameters:
ctx- Context derived from the original ResultSupplier.Context- Returns:
A map of CoordinateComponent to the ItemStack to place in that slot
- Since:
5.0.21
-
replaceResultHandler
abstract Unit replaceResultHandler(Map<CoordinateComponent, ReplaceableResultSupplier.ReplaceState> results, Map<CoordinateComponent, ItemStack> usedQueries, ReplaceableResultSupplier.Context usedContext)
Called after all slot write-back attempts have completed (or timed out).
Use this callback to inspect per-slot outcomes, deliver items to the player if needed, or perform any post-craft side effects.
- Parameters:
results- Per-slot outcome of the write-back operation.usedQueries- The map returned by replaceQueries.usedContext- The Context that was passed to replaceQueries- Since:
5.0.21
-
-
-
-