Click plans
These types let an inventory tool rearrange a menu as a player would, through the server’s own click handling, whether or not the server runs the mod.
At a glance
Section titled “At a glance”| Type | Summary | Status | Since | Side | Thread |
|---|---|---|---|---|---|
Click |
One click on a menu slot. | Experimental | 2.10.0 | both | any |
ClickAction |
What a Click does, as vanilla’s click types do. |
Experimental | 2.10.0 | both | any |
ClickPlan |
Clicks to run, in order, on one open menu. | Experimental | 2.10.0 | both | any |
ClickPlanner |
Plans the clicks that rearrange a menu, as a player sorting by hand would click. | Experimental | 2.10.0 | both | any |
ClickPlanRoute |
A route that carries ClickPlans to the server as one packet each, for InventoryTransport. |
Experimental | 2.10.0 | both | setup |
InventoryTransport |
Gets a ClickPlan to the server. |
Experimental | 2.10.0 | client | render |
MenuSnapshot |
A menu’s layout for ClickPlanner: each slot’s stack, numbered by kind, and what each slot allows. |
Experimental | 2.10.0 | both | any |
PlanStack |
A stack as ClickPlanner sees it. |
Experimental | 2.10.0 | both | any |
ReplayLimits |
Limits on what a ClickPlanRoute replays for each player. |
Experimental | 2.10.0 | both | any |
SlotRules |
What each slot of a menu allows, by slot index and PlanStack kind. |
Experimental | 2.10.0 | both | any |
TransportResult |
How a plan run by InventoryTransport ended. |
Experimental | 2.10.0 | client | render |
Quick start
Section titled “Quick start”In a container screen’s key handler on the client, with ROUTE the mod’s declared route and
Sorter.target the mod’s own sorting, which returns a target layout for a snapshot:
LocalPlayer player = Minecraft.getInstance().player;if (player == null || InventoryTransport.isBusy()) return;MenuSnapshot snapshot = MenuSnapshot.of(player.containerMenu);ClickPlan plan = ClickPlanner.plan(snapshot.containerId(), snapshot.stateId(), snapshot.stacks(), Sorter.target(snapshot), snapshot.rules());InventoryTransport.execute(plan, ROUTE, 4, result -> { if (result == TransportResult.REJECTED) Stope.LOG.debug("The server refused the sort");});ClickPlanner
Section titled “ClickPlanner”Experimental · Since 2.10.0 · Side: both · Thread: any
Build the target from the snapshot’s own stacks: move them between slots, and leave every slot
the tool must not touch as PlanStack.UNTOUCHED. A target that splits one kind across several
partial stacks plans one right click per item for all but the last, so a sort that fills slots
to capacity first plans far fewer clicks. Check a plan made by hand with ClickPlanner#simulate
before sending it.
MenuSnapshot
Section titled “MenuSnapshot”Experimental · Since 2.10.0 · Side: both · Thread: any
Kinds are numbered afresh in each snapshot, so compare stacks from two snapshots with
MenuSnapshot#stackOf, never by kind number. With menu the open menu, a target that reverses
the player’s main rows and leaves every other slot alone:
MenuSnapshot snapshot = MenuSnapshot.of(menu);List<Integer> rows = new ArrayList<>();for (Slot slot : menu.slots) { int index = SlotRegions.inventorySlot(slot); if (index >= 9 && index < 36) rows.add(slot.index);}List<PlanStack> target = new ArrayList<>(Collections.nCopies(menu.slots.size(), PlanStack.UNTOUCHED));for (int i = 0; i < rows.size(); i++) { target.set(rows.get(i), snapshot.stacks().get(rows.get(rows.size() - 1 - i)));}ClickPlanRoute
Section titled “ClickPlanRoute”Experimental · Since 2.10.0 · Side: both · Thread: setup
Declare the route once, in common initialization, after the other packets on the mod’s
channel. With CHANNEL the mod’s NetworkChannel:
public static final ClickPlanRoute ROUTE = ClickPlanRoute.declare( CHANNEL, "sort", new ReplayLimits(512, 4, 20));Size ReplayLimits to the largest menu the tool sorts: a double chest and the player’s
inventory hold 90 slots, and a sort that fills slots to capacity takes up to three clicks per
slot. A perTicks of 20 ticks (1 second) with a few plans is room for a player pressing a key
repeatedly.
InventoryTransport
Section titled “InventoryTransport”Experimental · Since 2.10.0 · Side: client · Thread: render
Call InventoryTransport#usesPackets when a plan is about to run, to show which way it goes;
InventoryTransport#execute picks the same way on its own. On a server without the route,
keep clicksPerTick low enough that anti-cheat plugins do not flag the clicks as a burst. After
REJECTED, take a fresh snapshot and plan again once at most: the menu was resent, so the old
plan’s state ID is stale.
A listener on
ItemDepletedCallback
or ItemReplacedCallback that brings the next stack into the hand starts its plan with
InventoryTransport#executeRefill. On a server without the route a second refill has to wait
for the first, so keep what is wanted and start it from onDone. In the listener, with plan
one swap click that brings a main-row stack into the held slot, and next, the mod’s method
that starts a refill it kept waiting:
if (InventoryTransport.isBusy()) return;InventoryTransport.executeRefill(plan, ROUTE, 1, result -> next());See also
Section titled “See also”- Slot regions: which slots belong to the player and which to the container, to choose the slots a plan touches.
- Networking: the channel a route’s packets go on.
- Testing: replaying a plan through a route in a GameTest.