Player api

This commit is contained in:
2026-10-13 22:59:48 -03:00
parent b34e97e487
commit a10b15a3fd
22 changed files with 581 additions and 89 deletions
+24 -1
View File
@@ -68,7 +68,21 @@ export interface BlockComponent<P = any> {
export interface ItemComponent<P = any> {
on_create?(item: ItemStack, params: P): void;
get_lore?(item: ItemStack, params: P): string;
on_use?(item: ItemStack, params: P, player: Player): void;
// right clicked while holding it, at nothing or at the block in target, like minecraft's use and useOn
on_use?(item: ItemStack, params: P, player: Player, target: UseTarget | undefined): void;
// using it over time, see Player.start_using. every tick while they do, ticks counting from 1, like onUseTick
on_use_tick?(item: ItemStack, params: P, player: Player, ticks: number): void;
// they let go of use before it finished, like a bow being shot, after using it for ticks. like releaseUsing
on_release_using?(item: ItemStack, params: P, player: Player, ticks: number): void;
// they used it for as long as start_using said, like food being eaten. like finishUsingItem
on_finish_using?(item: ItemStack, params: P, player: Player): void;
}
// the block an item was used on, the face that was clicked, and where on the block (0 to 1 on each axis)
export interface UseTarget {
readonly block: BlockRef;
readonly face: Face;
readonly hit: readonly [number, number, number];
}
// P is the component's params from the effect json. see docs/modding/entities/effects.md
@@ -328,6 +342,15 @@ export interface Player {
remove_effect(id: Id): boolean;
// lying flat in water in the 0.8 tall box, like minecraft's isSwimming. their client says when
is_swimming(): boolean;
// holding the sneak key, flying or not, like minecraft's isShiftKeyDown. their client says when
is_sneaking(): boolean;
// keeps using the held item while they hold use, like minecraft's startUsingItem: its components' on_use_tick runs
// every tick, then on_finish_using after ticks, or on_release_using if they let go first. -1 uses it until they let
// go, like a bow. it slows them down like sneaking. for an on_use to call. switching away from it stops it
start_using(ticks: number): void;
// stops using it without on_release_using or on_finish_using, like stopUsingItem
stop_using(): void;
is_using(): boolean;
}
export interface EffectOptions {