From 0edc422ec799ea201405cb89d3f7565d9b560add Mon Sep 17 00:00:00 2001 From: ShrBox Date: Thu, 8 Aug 2024 10:36:52 +0800 Subject: [PATCH] fix: fix simulateLookAt #146 --- docs/apis/GameAPI/Player.md | 9 ++++++--- docs/apis/GameAPI/Player.zh.md | 9 ++++++--- src/legacy/api/RemoteCallAPI.cpp | 2 +- src/legacy/api/SimulatedPlayerAPI.cpp | 17 ++++++++++++----- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/docs/apis/GameAPI/Player.md b/docs/apis/GameAPI/Player.md index 0d1fa92..89cd92d 100644 --- a/docs/apis/GameAPI/Player.md +++ b/docs/apis/GameAPI/Player.md @@ -1507,9 +1507,9 @@ Reference: [mojang-gametest docs](https://docs.microsoft.com/en-us/minecraft/cre #### Simulate Look At a Block or Entity -`sp.simulateLookAt(pos)` -`sp.simulateLookAt(entity)` -`sp.simulateLookAt(block)` +`sp.simulateLookAt(pos, [lookDuration])` +`sp.simulateLookAt(entity, [lookDuration])` +`sp.simulateLookAt(block, [lookDuration])` - Parameters: @@ -1519,6 +1519,9 @@ Reference: [mojang-gametest docs](https://docs.microsoft.com/en-us/minecraft/cre The coordinates to look at - block :`Block` The block to look at + - lookDuration: `Int` + The duration SimulatedPlayer look + 0 = Instant, 1 = Continuous, 2 = UntilMove - Return value: Whether the simulation operation was successful - Return type: `Boolean` diff --git a/docs/apis/GameAPI/Player.zh.md b/docs/apis/GameAPI/Player.zh.md index 7a3d0e7..7fc48d0 100644 --- a/docs/apis/GameAPI/Player.zh.md +++ b/docs/apis/GameAPI/Player.zh.md @@ -1888,9 +1888,9 @@ #### 模拟看向某方块或实体 -`sp.simulateLookAt(pos)` -`sp.simulateLookAt(entity)` -`sp.simulateLookAt(block)` +`sp.simulateLookAt(pos, [lookDuration])` +`sp.simulateLookAt(entity, [lookDuration])` +`sp.simulateLookAt(block, [lookDurration])` - 参数: @@ -1900,6 +1900,9 @@ 要看向的坐标 - block :`Block` 要看向的方块 + - lookDuration: `Int` + 模拟玩家看向目标的持续时间 + 0 = 立刻, 1 = 持续, 2 = 不变直到移动 - 返回值:是否成功模拟操作 - 返回值类型:`Boolean` diff --git a/src/legacy/api/RemoteCallAPI.cpp b/src/legacy/api/RemoteCallAPI.cpp index 63d4269..cf45c03 100644 --- a/src/legacy/api/RemoteCallAPI.cpp +++ b/src/legacy/api/RemoteCallAPI.cpp @@ -118,7 +118,7 @@ Local _extractValue(RemoteCall::ItemType&& v) { }; Local _extractValue(RemoteCall::NbtType&& v) { if (v.own) return NbtCompoundClass::pack(v.tryGetUniquePtr()); - else return NbtCompoundClass::pack(const_cast(v.ptr), false); + else return NbtCompoundClass::pack(const_cast(v.ptr)); }; Local extract(RemoteCall::ValueType&& val); diff --git a/src/legacy/api/SimulatedPlayerAPI.cpp b/src/legacy/api/SimulatedPlayerAPI.cpp index 5b4dbb1..61bb81b 100644 --- a/src/legacy/api/SimulatedPlayerAPI.cpp +++ b/src/legacy/api/SimulatedPlayerAPI.cpp @@ -387,12 +387,19 @@ Local PlayerClass::simulateLookAt(const Arguments& args) { auto sp = asSimulatedPlayer(); if (!sp) return Local(); Vec3 target; - int dimid = sp->getDimensionId(); + int dimid = sp->getDimensionId(); + int lookDuration = 2; // 0 = Instant, 1 = Continuous, 2 = UntilMove + if (args.size() > 1) { + if (!args[1].isNumber()) { + LOG_WRONG_ARG_TYPE(); + } + lookDuration = args[1].asNumber().toInt32(); + } if (IsInstanceOf(args[0])) { auto pos = IntPos::extractPos(args[0]); auto did = pos->getDimensionId(); if (dimid == did || did < 0 || did > 2) { - sp->simulateLookAt(pos->getBlockPos(), (sim::LookDuration)0); + sp->simulateLookAt(pos->getBlockPos(), (sim::LookDuration)lookDuration); return Boolean::newBoolean(true); } lse::getSelfPluginInstance().getLogger().debug("Can't simulate look at other dimension!"); @@ -401,7 +408,7 @@ Local PlayerClass::simulateLookAt(const Arguments& args) { auto pos = FloatPos::extractPos(args[0]); auto did = pos->getDimensionId(); if (dimid == did || did < 0 || did > 2) { - sp->simulateLookAt(pos->getVec3(), (sim::LookDuration)0); + sp->simulateLookAt(pos->getVec3(), (sim::LookDuration)lookDuration); return Boolean::newBoolean(true); } lse::getSelfPluginInstance().getLogger().debug("Can't simulate look at other dimension!"); @@ -411,14 +418,14 @@ Local PlayerClass::simulateLookAt(const Arguments& args) { auto pos = IntPos::extractPos(block->getPos()); auto did = pos->getDimensionId(); if (dimid == did || did < 0 || did > 2) { - sp->simulateLookAt(pos->getBlockPos(), (sim::LookDuration)0); + sp->simulateLookAt(pos->getBlockPos(), (sim::LookDuration)lookDuration); return Boolean::newBoolean(true); } lse::getSelfPluginInstance().getLogger().debug("Can't simulate look at other dimension!"); return Boolean::newBoolean(false); } else if (auto actor = EntityClass::tryExtractActor(args[0])) { if (!*actor) return Local(); - sp->simulateLookAt(**actor, (sim::LookDuration)0); + sp->simulateLookAt(**actor, (sim::LookDuration)lookDuration); return Boolean::newBoolean(true); } LOG_WRONG_ARG_TYPE();