Repository navigation
fix: drive eating indication from a real use session #607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { describe, expect, test } from 'vitest' | ||
| import type { UseItemAction, UseItemSession } from 'minecraft-renderer/src/playerState/types' | ||
|
Check failure on line 2 in src/mineflayer/movementWhileUsing.test.ts
|
||
| import { shouldBlockSprint, shouldSlowWhileUsing } from './movementWhileUsing' | ||
|
|
||
| const makeSession = (action: UseItemAction = 'EAT', status: UseItemSession['status'] = 'active'): UseItemSession => ({ | ||
| id: 1, | ||
| itemSnapshot: { | ||
| name: action === 'BOW' ? 'bow' : 'bread', | ||
| durationTicks: 32, | ||
| action, | ||
| particleEffect: action === 'EAT' ? 'food' : 'none', | ||
| }, | ||
| hand: 0, | ||
| action, | ||
| durationTicks: 32, | ||
| elapsedTicks: 0, | ||
| status, | ||
| }) | ||
|
|
||
| describe('movement restrictions while using an item', () => { | ||
| test('requires an active or awaiting-completion session', () => { | ||
| expect(shouldSlowWhileUsing(undefined, false)).toBe(false) | ||
| expect(shouldBlockSprint(undefined)).toBe(false) | ||
| expect(shouldSlowWhileUsing(makeSession('EAT', 'completed'), false)).toBe(false) | ||
| expect(shouldBlockSprint(makeSession('EAT', 'cancelled'))).toBe(false) | ||
| expect(shouldSlowWhileUsing(makeSession('DRINK', 'awaitingCompletion'), false)).toBe(true) | ||
| expect(shouldBlockSprint(makeSession('EAT', 'active'))).toBe(true) | ||
| }) | ||
|
|
||
| test('matches represented vanilla use actions, including bow draw', () => { | ||
| for (const action of ['EAT', 'DRINK', 'BOW', 'CROSSBOW', 'SHIELD'] as const) { | ||
| expect(shouldSlowWhileUsing(makeSession(action), false)).toBe(true) | ||
| expect(shouldBlockSprint(makeSession(action))).toBe(true) | ||
| } | ||
| expect(shouldSlowWhileUsing(makeSession('NONE'), false)).toBe(false) | ||
| expect(shouldBlockSprint(makeSession('NONE'))).toBe(false) | ||
| }) | ||
|
|
||
| test('mounted players keep normal movement but still cannot sprint while using', () => { | ||
| const session = makeSession('BOW') | ||
| expect(shouldSlowWhileUsing(session, true)).toBe(false) | ||
| expect(shouldBlockSprint(session)).toBe(true) | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import type { UseItemAction, UseItemSession } from 'minecraft-renderer/src/playerState/types' | ||
|
Check failure on line 1 in src/mineflayer/movementWhileUsing.ts
|
||
|
|
||
| /** | ||
| * These are the use actions represented by the local item-use session. `NONE` | ||
| * is used for activatable inventory items that do not have a vanilla use | ||
| * animation; it is not a LocalPlayer.isUsingItem() state and must not apply | ||
| * the movement restriction. | ||
| */ | ||
| const MOVEMENT_RESTRICTED_USE_ACTIONS: Record<UseItemAction, true | undefined> = { | ||
| EAT: true, | ||
| DRINK: true, | ||
| BOW: true, | ||
| CROSSBOW: true, | ||
| SHIELD: true, | ||
| NONE: undefined, | ||
| } | ||
|
|
||
| const isActiveUseSession = (session: UseItemSession | null | undefined): boolean => { | ||
| if (!session || (session.status !== 'active' && session.status !== 'awaitingCompletion')) { | ||
| return false | ||
| } | ||
| return MOVEMENT_RESTRICTED_USE_ACTIONS[session.action] === true | ||
| } | ||
|
|
||
| /** Vanilla's input slow applies to unmounted players while an item is used. */ | ||
| export const shouldSlowWhileUsing = ( | ||
| session: UseItemSession | null | undefined, | ||
| hasVehicle: boolean | ||
| ): boolean => !hasVehicle && isActiveUseSession(session) | ||
|
|
||
| /** Vanilla sprint eligibility is blocked for every active represented use. */ | ||
| export const shouldBlockSprint = (session: UseItemSession | null | undefined): boolean => { | ||
| return isActiveUseSession(session) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🔴 Critical | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: zardoy/minecraft-web-client
Length of output: 221
🏁 Script executed:
Repository: zardoy/minecraft-web-client
Length of output: 50384
🏁 Script executed:
Repository: zardoy/minecraft-web-client
Length of output: 11934
🌐 Web query:
minecraft-renderer 0.1.99 src/playerState/types UseItemSession PlayerStateReactive💡 Result:
<source_evidence>
Citations:
🏁 Script executed:
Repository: zardoy/minecraft-web-client
Length of output: 1967
Update the renderer dependency before consuming item-use sessions.
The lockfile resolves
minecraft-rendererto0.1.99, but that version does not exportUseItemActionorUseItemSession. ItsPlayerStateReactivetype also has noitemUseSessionproperty. TypeScript therefore fails on this import and on theplayerState.reactive.itemUseSessionaccesses insrc/controls.ts.Publish or select a renderer version that contains this contract. Then update the dependency and lockfile before merging this PR.
🧰 Tools
🪛 GitHub Check: build-and-deploy
[failure] 1-1:
Module '"minecraft-renderer/src/playerState/types"' has no exported member 'UseItemAction'.
🤖 Prompt for AI Agents