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
+3 -2
View File
@@ -16,14 +16,15 @@ export interface ClientContext {
// the way jei's recipes screen checks options.keyInventory
options: KeyMappings;
net: ClientNet;
// is_swimming: lying flat in water in the 0.8 tall box, like minecraft's isSwimming. biome and season are where
// their feet are, undefined until that chunk loads
// is_swimming: lying flat in water in the 0.8 tall box, like minecraft's isSwimming. is_sneaking: holding the sneak
// key, like isShiftKeyDown. biome and season are where their feet are, undefined until that chunk loads
player: {
readonly name: string;
readonly position: Readonly<Position>;
readonly biome: Id | undefined;
readonly season: Season | undefined;
is_swimming(): boolean;
is_sneaking(): boolean;
};
// read only, what this client sees
world: {
+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 {
+6 -2
View File
@@ -93,19 +93,23 @@ export interface SharedBlock extends Position {
}
// a player placing a block at x y z by clicking face of the block next to it, at hit (0 to 1 on each axis of that
// block), like minecraft's BlockPlaceContext. facing is the way the player looks, along the ground
// block), like minecraft's BlockPlaceContext. facing is the way the player looks, along the ground, and sneaking
// whether they hold the sneak key, for blocks placed another way round when they do
export interface BlockPlacement extends Position {
readonly face: Face;
readonly hit: readonly [number, number, number];
readonly facing: "north" | "east" | "south" | "west";
readonly sneaking: boolean;
}
// a player right clicking face of a block, at hit (0 to 1 on each axis of the block), like minecraft's BlockHitResult.
// facing is the way the player looks, along the ground
// facing is the way the player looks, along the ground, and sneaking whether they hold the sneak key. sneaking with
// an item in hand doesn't interact at all, the item is used or placed instead
export interface BlockInteraction {
readonly face: Face;
readonly hit: readonly [number, number, number];
readonly facing: "north" | "east" | "south" | "west";
readonly sneaking: boolean;
}
// P is the component's params from the block json