跳转至

Zig:客户端

声明

client.KeyHandler

Zig
pub const KeyHandler = fn (user: ?*anyopaque, action: KeyAction, impact: i32) void;

已注册按键每次按下和松开时在客户端线程上调用:注册时给出的 user 指针、动作,以及引擎报告的焦点影响。

函数

client.property

Zig
pub fn property(prop: i32) core.Error!f64

按 PIER_CPROP_* 键读取一个数值型的客户端属性。宿主不认识这个键、或者客户端不在世界里时读取关于本地玩家的键,得到 NoAnswer。

  • 参数:
    • prop : i32
  • 返回值类型:core.Error!f64
  • 对应槽位:client_get_num

client.localPosition

Zig
pub fn localPosition() core.Error![3]f64

本地玩家脚下的位置:x、y、z。

client.localRotation

Zig
pub fn localRotation() core.Error![2]f64

本地玩家的 pitch 和 yaw,单位为度;pitch 为负表示向上看。

client.localDimension

Zig
pub fn localDimension() core.Error!i32

本地玩家所在维度的 id。

client.guiScale

Zig
pub fn guiScale() core.Error!f64

这个客户端绘制界面所用的 GUI 缩放。

client.serverPingMs

Zig
pub fn serverPingMs() core.Error!f64

到服务器的往返延迟,单位毫秒,由这个客户端测得。

client.isShowingMenu

Zig
pub fn isShowingMenu() core.Error!bool

是否正在显示菜单界面。

client.isShowingPauseScreen

Zig
pub fn isShowingPauseScreen() core.Error!bool

是否正在显示暂停界面。

client.isPlaying

Zig
pub fn isPlaying() core.Error!bool

客户端是否正在游玩一个世界。

client.isInRealm

Zig
pub fn isInRealm() core.Error!bool

当前世界是否是 Realm。

client.isGameInputEnabled

Zig
pub fn isGameInputEnabled() core.Error!bool

游戏输入是否能到达世界;上层有界面时就不能。

client.topScreenName

Zig
pub fn topScreenName(allocator: std.mem.Allocator) (core.Error || std.mem.Allocator.Error)![]u8

客户端界面栈最顶层的界面,由调用方持有。

  • 参数:
    • allocator : std.mem.Allocator
  • 返回值类型:(core.Error || std.mem.Allocator.Error)![]u8
  • 对应槽位:client_get_str

client.registeredKeys

Zig
pub fn registeredKeys(allocator: std.mem.Allocator) (core.Error || std.mem.Allocator.Error)![][]u8

按键注册表里所有按键绑定的名字,不论是哪个 mod 注册的。每个名字和切片都由调用方释放。

  • 参数:
    • allocator : std.mem.Allocator
  • 返回值类型:(core.Error || std.mem.Allocator.Error)![][]u8
  • 对应槽位:client_list_keys

client.showMessage

Zig
pub fn showMessage(text: []const u8) core.Error!void

在这个客户端的聊天栏里显示文字。不会向服务器发送任何东西。

  • 参数:
    • text : []const u8
  • 返回值类型:core.Error!void
  • 对应槽位:client_action

client.setTitle

Zig
pub fn setTitle(text: []const u8) core.Error!void

在这个客户端上把文字显示为标题。

  • 参数:
    • text : []const u8
  • 返回值类型:core.Error!void
  • 对应槽位:client_action

client.setSubtitle

Zig
pub fn setSubtitle(text: []const u8) core.Error!void

在这个客户端上把文字显示为副标题。

  • 参数:
    • text : []const u8
  • 返回值类型:core.Error!void
  • 对应槽位:client_action

client.setActionBar

Zig
pub fn setActionBar(text: []const u8) core.Error!void

在这个客户端的快捷栏上方显示文字。

  • 参数:
    • text : []const u8
  • 返回值类型:core.Error!void
  • 对应槽位:client_action

client.showTip

Zig
pub fn showTip(text: []const u8) core.Error!void

在这个客户端上把文字显示为提示。

  • 参数:
    • text : []const u8
  • 返回值类型:core.Error!void
  • 对应槽位:client_action

client.playUiSound

Zig
pub fn playUiSound(name: []const u8, volume: f64, pitch: f64) core.Error!void

在这个客户端上按名字播放一个界面音效,例如 "random.click"。

  • 参数:
    • name : []const u8
    • volume : f64
    • pitch : f64
  • 返回值类型:core.Error!void
  • 对应槽位:client_action

client.grabMouse

Zig
pub fn grabMouse() core.Error!void

让游戏捕获鼠标,效果和点击进入世界一样。

client.releaseMouse

Zig
pub fn releaseMouse() core.Error!void

把鼠标释放给界面。

client.setInputDisabled

Zig
pub fn setInputDisabled(disabled: bool) core.Error!void

禁用或启用游戏输入。

  • 参数:
    • disabled : bool
  • 返回值类型:core.Error!void
  • 对应槽位:client_action

client.leaveLevel

Zig
pub fn leaveLevel() core.Error!void

离开当前世界回到菜单。引擎以异步方式完成。

client.health

Zig
pub fn health() core.Error!f64

本地玩家的 Actor::getHealth

client.maxHealth

Zig
pub fn maxHealth() core.Error!f64

本地玩家的 Actor::getMaxHealth

client.isOnGround

Zig
pub fn isOnGround() core.Error!bool

本地玩家的 Actor::isOnGround

client.isInWater

Zig
pub fn isInWater() core.Error!bool

本地玩家的 Actor::isInWater

client.isSneaking

Zig
pub fn isSneaking() core.Error!bool

本地玩家的 Actor::isSneaking

client.isSprinting

Zig
pub fn isSprinting() core.Error!bool

本地玩家的 Actor::isSprinting

client.isSwimming

Zig
pub fn isSwimming() core.Error!bool

本地玩家的 Actor::isSwimming

client.isOnFire

Zig
pub fn isOnFire() core.Error!bool

本地玩家的 Actor::isOnFire

client.isFlying

Zig
pub fn isFlying() core.Error!bool

本地玩家的 Player::isFlying

client.gameType

Zig
pub fn gameType() core.Error!f64

本地玩家的 Player::getPlayerGameType

client.selectedSlot

Zig
pub fn selectedSlot() core.Error!f64

本地玩家的 Player::getSelectedItemSlot

client.velX

Zig
pub fn velX() core.Error!f64

本地玩家的 Actor::getPosDelta,单位为方块每刻

client.velY

Zig
pub fn velY() core.Error!f64

Actor::getPosDelta 的竖直分量

client.velZ

Zig
pub fn velZ() core.Error!f64

Actor::getPosDelta 的 z 分量

client.xpNeededNextLevel

Zig
pub fn xpNeededNextLevel() core.Error!f64

本地玩家的 Player::getXpNeededForNextLevel

client.isLeavingGame

Zig
pub fn isLeavingGame() core.Error!bool

IClientInstance::isLeavingGame

client.isExitingLevel

Zig
pub fn isExitingLevel() core.Error!bool

IClientInstance::isExitingLevel

client.isInBedScreen

Zig
pub fn isInBedScreen() core.Error!bool

IClientInstance::isInBedScreen

client.isInDeathScreen

Zig
pub fn isInDeathScreen() core.Error!bool

IClientInstance::isInDeathScreen

client.isShowingLoadingScreen

Zig
pub fn isShowingLoadingScreen() core.Error!bool

IClientInstance::isShowingLoadingScreen

client.isShowingProgressScreen

Zig
pub fn isShowingProgressScreen() core.Error!bool

IClientInstance::isShowingProgressScreen

client.isShowingWorldProgressScreen

Zig
pub fn isShowingWorldProgressScreen() core.Error!bool

IClientInstance::isShowingWorldProgressScreen

client.isShowingDeathScreen

Zig
pub fn isShowingDeathScreen() core.Error!bool

IClientInstance::isShowingDeathScreen

client.isShowingServerForm

Zig
pub fn isShowingServerForm() core.Error!bool

IClientInstance::isShowingServerForm

client.isInWorldWithoutMenu

Zig
pub fn isInWorldWithoutMenu() core.Error!bool

IClientInstance::isInWorldAndNotShowingAnyMenuScreens

client.isWorldActive

Zig
pub fn isWorldActive() core.Error!bool

IClientInstance::isWorldActive

client.hasLevel

Zig
pub fn hasLevel() core.Error!bool

IClientInstance::hasLevel

client.isPreGame

Zig
pub fn isPreGame() core.Error!bool

IClientInstance::isPreGame

client.isInMultiplayerGame

Zig
pub fn isInMultiplayerGame() core.Error!bool

IClientInstance::isInMultiplayerGame

client.isMultiplayerClient

Zig
pub fn isMultiplayerClient() core.Error!bool

IClientInstance::isMultiPlayerClient

client.isPrimaryLevelMultiplayer

Zig
pub fn isPrimaryLevelMultiplayer() core.Error!bool

IClientInstance::isPrimaryLevelMultiplayer

client.isPrimaryLevelCrossPlatform

Zig
pub fn isPrimaryLevelCrossPlatform() core.Error!bool

IClientInstance::isPrimaryLevelCrossPlatformMultiplayer

client.isKeyboardEnabled

Zig
pub fn isKeyboardEnabled() core.Error!bool

IClientInstance::isKeyboardEnabled

client.isUsingController

Zig
pub fn isUsingController() core.Error!bool

IClientInstance::useController

client.isUsingTouchscreen

Zig
pub fn isUsingTouchscreen() core.Error!bool

IClientInstance::useTouchscreen

client.isMouseGrabbed

Zig
pub fn isMouseGrabbed() core.Error!bool

IClientInstance::getMouseGrabbed

client.isMouseAndKeyboard

Zig
pub fn isMouseAndKeyboard() core.Error!bool

IClientInstance::currentInputModeIsMouseAndKeyboard

client.hasConnectedController

Zig
pub fn hasConnectedController() core.Error!bool

IClientInstance::hasConnectedController

client.controllerId

Zig
pub fn controllerId() core.Error!f64

IClientInstance::getControllerId

client.isTouchGameplayAllowed

Zig
pub fn isTouchGameplayAllowed() core.Error!bool

IClientInstance::isTouchGameplayAllowed

client.isSplitScreenActive

Zig
pub fn isSplitScreenActive() core.Error!bool

IClientInstance::isSplitScreenActive

client.splitScreenCount

Zig
pub fn splitScreenCount() core.Error!f64

IClientInstance::getSplitScreenCount

client.guiScaleOffset

Zig
pub fn guiScaleOffset() core.Error!f64

IClientInstance::getGuiScaleOffset

client.isEduMode

Zig
pub fn isEduMode() core.Error!bool

IClientInstance::isEduMode

client.isInEditor

Zig
pub fn isInEditor() core.Error!bool

IClientInstance::isPlayerInEditor

client.isReadyToRender

Zig
pub fn isReadyToRender() core.Error!bool

IClientInstance::isReadyToRender

client.isFullVanillaPackOnStack

Zig
pub fn isFullVanillaPackOnStack() core.Error!bool

IClientInstance::isFullVanillaPackOnStack

client.serverConnectionTime

Zig
pub fn serverConnectionTime() core.Error!f64

IClientInstance::getServerConnectionTime

client.remoteServerTimeMs

Zig
pub fn remoteServerTimeMs() core.Error!f64

IClientInstance::getRemoteServerTimeMs

client.remoteServerNetworkTimeMs

Zig
pub fn remoteServerNetworkTimeMs() core.Error!f64

IClientInstance::getRemoteServerNetworkTimeMs

client.frameAlpha

Zig
pub fn frameAlpha() core.Error!f64

IClientInstance::getFrameAlpha,当前帧处在两刻之间的位置

client.gameUpdateSeconds

Zig
pub fn gameUpdateSeconds() core.Error!f64

IClientInstance::getGameUpdateDurationInSeconds

client.isPrimaryClient

Zig
pub fn isPrimaryClient() core.Error!bool

IClientInstance::isPrimaryClient

client.userId

Zig
pub fn userId() core.Error!f64

IClientInstance::getUserId

client.isGameplayTipsEnabled

Zig
pub fn isGameplayTipsEnabled() core.Error!bool

IClientInstance::isGamePlayTipsEnabled

client.hasCommands

Zig
pub fn hasCommands() core.Error!bool

IClientInstance::hasCommands

client.platformId

Zig
pub fn platformId(allocator: std.mem.Allocator) (core.Error || std.mem.Allocator.Error)![]u8

IClientInstance::getPlatformId

  • 参数:
    • allocator : std.mem.Allocator
  • 返回值类型:(core.Error || std.mem.Allocator.Error)![]u8
  • 对应槽位:client_get_str

client.platformOnlineId

Zig
pub fn platformOnlineId(allocator: std.mem.Allocator) (core.Error || std.mem.Allocator.Error)![]u8

IClientInstance::getPlatformOnlineId

  • 参数:
    • allocator : std.mem.Allocator
  • 返回值类型:(core.Error || std.mem.Allocator.Error)![]u8
  • 对应槽位:client_get_str

client.localXuid

Zig
pub fn localXuid(allocator: std.mem.Allocator) (core.Error || std.mem.Allocator.Error)![]u8

本地玩家的 Player::getXuid;不在世界里时失败

  • 参数:
    • allocator : std.mem.Allocator
  • 返回值类型:(core.Error || std.mem.Allocator.Error)![]u8
  • 对应槽位:client_get_str

client.localUuid

Zig
pub fn localUuid(allocator: std.mem.Allocator) (core.Error || std.mem.Allocator.Error)![]u8

本地玩家的 Player::getUuid,规范字符串形式

  • 参数:
    • allocator : std.mem.Allocator
  • 返回值类型:(core.Error || std.mem.Allocator.Error)![]u8
  • 对应槽位:client_get_str

client.localNameTag

Zig
pub fn localNameTag(allocator: std.mem.Allocator) (core.Error || std.mem.Allocator.Error)![]u8

本地玩家的 Actor::getNameTag

  • 参数:
    • allocator : std.mem.Allocator
  • 返回值类型:(core.Error || std.mem.Allocator.Error)![]u8
  • 对应槽位:client_get_str

client.clipboard

Zig
pub fn clipboard(allocator: std.mem.Allocator) (core.Error || std.mem.Allocator.Error)![]u8

AppPlatform::getClipboardText,系统剪贴板

  • 参数:
    • allocator : std.mem.Allocator
  • 返回值类型:(core.Error || std.mem.Allocator.Error)![]u8
  • 对应槽位:client_get_str

client.showPopup

Zig
pub fn showPopup(text: []const u8) core.Error!void

显示一个弹出提示;文字里的换行把消息和副标题分开。

  • 参数:
    • text : []const u8
  • 返回值类型:core.Error!void
  • 对应槽位:client_action

client.showDevConsoleMessage

Zig
pub fn showDevConsoleMessage(text: []const u8) core.Error!void

把文字写入开发者控制台。

  • 参数:
    • text : []const u8
  • 返回值类型:core.Error!void
  • 对应槽位:client_action

client.setSuspendInput

Zig
pub fn setSuspendInput(suspended: bool) core.Error!void

暂停或恢复全部输入。

  • 参数:
    • suspended : bool
  • 返回值类型:core.Error!void
  • 对应槽位:client_action

client.setSuspendDirectionalInput

Zig
pub fn setSuspendDirectionalInput(suspended: bool) core.Error!void

暂停或恢复移动输入。

  • 参数:
    • suspended : bool
  • 返回值类型:core.Error!void
  • 对应槽位:client_action

client.setGameInputEnabled

Zig
pub fn setGameInputEnabled(enabled: bool) core.Error!void

启用或禁用游戏输入。

  • 参数:
    • enabled : bool
  • 返回值类型:core.Error!void
  • 对应槽位:client_action

client.refocusMouse

Zig
pub fn refocusMouse(lost: bool) core.Error!void

把鼠标交还给游戏。

  • 参数:
    • lost : bool
  • 返回值类型:core.Error!void
  • 对应槽位:client_action

client.muteAudio

Zig
pub fn muteAudio() core.Error!void

把客户端静音。

client.unmuteAudio

Zig
pub fn unmuteAudio() core.Error!void

取消客户端静音。

client.fadeOutMusic

Zig
pub fn fadeOutMusic() core.Error!void

让正在播放的音乐淡出。

client.setGuiScaleOffset

Zig
pub fn setGuiScaleOffset(offset: i32) core.Error!void

设置 GUI 缩放偏移。

  • 参数:
    • offset : i32
  • 返回值类型:core.Error!void
  • 对应槽位:client_action

client.resetPlayerMovement

Zig
pub fn resetPlayerMovement() core.Error!void

重置本地玩家的移动输入。

client.pushLeaveGameScreen

Zig
pub fn pushLeaveGameScreen() core.Error!void

打开询问是否离开世界的界面。

client.openContentLogHistory

Zig
pub fn openContentLogHistory() core.Error!void

打开内容日志历史。

client.setClipboard

Zig
pub fn setClipboard(value: []const u8) core.Error!void

把 value 写入系统剪贴板。

  • 参数:
    • value : []const u8
  • 返回值类型:core.Error!void
  • 对应槽位:client_action

client.navigateHowToPlay

Zig
pub fn navigateHowToPlay(topic: []const u8) core.Error!void

打开“游戏指南”并定位到 topic,主题为空时打开首页。

  • 参数:
    • topic : []const u8
  • 返回值类型:core.Error!void
  • 对应槽位:client_action

client.options

Zig
pub fn options(allocator: std.mem.Allocator) (core.Error || std.mem.Allocator.Error)![]OptionPair

全部客户端选项。每个键、每个值和切片都由调用方释放。

  • 参数:
    • allocator : std.mem.Allocator
  • 返回值类型:(core.Error || std.mem.Allocator.Error)![]OptionPair
  • 对应槽位:client_option_list

client.option

Zig
pub fn option(key: []const u8, allocator: std.mem.Allocator) (core.Error || std.mem.Allocator.Error)![]u8

按 options.txt 里的键读取一个客户端选项,由调用方持有。

  • 参数:
    • key : []const u8
    • allocator : std.mem.Allocator
  • 返回值类型:(core.Error || std.mem.Allocator.Error)![]u8
  • 对应槽位:client_option_get

client.setOption

Zig
pub fn setOption(key: []const u8, value: []const u8) core.Error!void

用 options.txt 的文本形式写入一个客户端选项;读回来才能看到引擎保留了什么。

  • 参数:
    • key : []const u8
    • value : []const u8
  • 返回值类型:core.Error!void
  • 对应槽位:client_option_set

client.registerKey

Zig
pub fn registerKey(name: []const u8, key_codes: []const i32, allow_remap: bool, user: ?*anyopaque, comptime handler: KeyHandler) core.Error!KeyBinding

以 name 注册一个按键绑定,默认按键码为 key_codes。allow_remap 允许玩家重新绑定。名字已被占用、或按键码列表为空时得到 Refused。

  • 参数:
    • name : []const u8
    • key_codes : []const i32
    • allow_remap : bool
    • user : ?*anyopaque
    • handler : comptime KeyHandler
  • 返回值类型:core.Error!KeyBinding
  • 对应槽位:client_register_key

client.isInLevel

Zig
pub fn isInLevel() core.Error!bool

客户端是否在一个 level 里,也就是是否已经加载了世界。

client.localPlayerName

Zig
pub fn localPlayerName(allocator: std.mem.Allocator) (core.Error || std.mem.Allocator.Error)![]u8

本地玩家的名字,由调用方持有。不在 level 里时为 NoAnswer。

  • 参数:
    • allocator : std.mem.Allocator
  • 返回值类型:(core.Error || std.mem.Allocator.Error)![]u8
  • 对应槽位:client_get_local_player

client.KeyBinding

Zig
1
2
3
4
pub const KeyBinding = struct {
    handle: c.PierKeyHandle,
    // ...
};

一个已注册的按键绑定,留着它是为了之后注销。

client.KeyBinding.keyCodes

Zig
pub fn keyCodes(self: KeyBinding, allocator: std.mem.Allocator) (core.Error || std.mem.Allocator.Error)![]i32

当前分配的按键码;玩家重新映射过按键时,它和默认值不同。由调用方持有。

  • 参数:
    • allocator : std.mem.Allocator
  • 返回值类型:(core.Error || std.mem.Allocator.Error)![]i32
  • 对应槽位:client_get_key_codes

client.KeyBinding.unregister

Zig
pub fn unregister(self: *KeyBinding) core.Error!void

注销这个绑定:这个 mod 的处理函数不再触发。引擎对每个名字只保留一个按键,也没有移除的接口,所以再次注册同一个名字会复用它。调用两次也没有害处。

client.KeyAction

Zig
1
2
3
4
5
pub const KeyAction = enum(i32) {
    up = 0,
    down = 1,
    _,
};

一个按键绑定上报的动作。

client.KeyAction.isDown

Zig
pub fn isDown(self: KeyAction) bool
  • 返回值类型:bool

client.OptionPair

Zig
1
2
3
4
5
pub const OptionPair = struct {
    key: []u8,
    value: []u8,
    // ...
};

一个客户端选项:它在 options.txt 里的键,以及那种文本形式的值。