Skip to content

Commit 0edc422

Browse files
committed
fix: fix simulateLookAt #146
1 parent 24fea65 commit 0edc422

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

docs/apis/GameAPI/Player.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,9 +1507,9 @@ Reference: [mojang-gametest docs](https://docs.microsoft.com/en-us/minecraft/cre
15071507

15081508
#### Simulate Look At a Block or Entity
15091509

1510-
`sp.simulateLookAt(pos)`
1511-
`sp.simulateLookAt(entity)`
1512-
`sp.simulateLookAt(block)`
1510+
`sp.simulateLookAt(pos, [lookDuration])`
1511+
`sp.simulateLookAt(entity, [lookDuration])`
1512+
`sp.simulateLookAt(block, [lookDuration])`
15131513

15141514
- Parameters:
15151515

@@ -1519,6 +1519,9 @@ Reference: [mojang-gametest docs](https://docs.microsoft.com/en-us/minecraft/cre
15191519
The coordinates to look at
15201520
- block :`Block`
15211521
The block to look at
1522+
- lookDuration: `Int`
1523+
The duration SimulatedPlayer look
1524+
0 = Instant, 1 = Continuous, 2 = UntilMove
15221525

15231526
- Return value: Whether the simulation operation was successful
15241527
- Return type: `Boolean`

docs/apis/GameAPI/Player.zh.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,9 +1888,9 @@
18881888

18891889
#### 模拟看向某方块或实体
18901890

1891-
`sp.simulateLookAt(pos)`
1892-
`sp.simulateLookAt(entity)`
1893-
`sp.simulateLookAt(block)`
1891+
`sp.simulateLookAt(pos, [lookDuration])`
1892+
`sp.simulateLookAt(entity, [lookDuration])`
1893+
`sp.simulateLookAt(block, [lookDurration])`
18941894

18951895
- 参数:
18961896

@@ -1900,6 +1900,9 @@
19001900
要看向的坐标
19011901
- block :`Block`
19021902
要看向的方块
1903+
- lookDuration: `Int`
1904+
模拟玩家看向目标的持续时间
1905+
0 = 立刻, 1 = 持续, 2 = 不变直到移动
19031906

19041907
- 返回值:是否成功模拟操作
19051908
- 返回值类型:`Boolean`

src/legacy/api/RemoteCallAPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Local<Value> _extractValue(RemoteCall::ItemType&& v) {
118118
};
119119
Local<Value> _extractValue(RemoteCall::NbtType&& v) {
120120
if (v.own) return NbtCompoundClass::pack(v.tryGetUniquePtr());
121-
else return NbtCompoundClass::pack(const_cast<CompoundTag*>(v.ptr), false);
121+
else return NbtCompoundClass::pack(const_cast<CompoundTag*>(v.ptr));
122122
};
123123

124124
Local<Value> extract(RemoteCall::ValueType&& val);

src/legacy/api/SimulatedPlayerAPI.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,19 @@ Local<Value> PlayerClass::simulateLookAt(const Arguments& args) {
387387
auto sp = asSimulatedPlayer();
388388
if (!sp) return Local<Value>();
389389
Vec3 target;
390-
int dimid = sp->getDimensionId();
390+
int dimid = sp->getDimensionId();
391+
int lookDuration = 2; // 0 = Instant, 1 = Continuous, 2 = UntilMove
392+
if (args.size() > 1) {
393+
if (!args[1].isNumber()) {
394+
LOG_WRONG_ARG_TYPE();
395+
}
396+
lookDuration = args[1].asNumber().toInt32();
397+
}
391398
if (IsInstanceOf<IntPos>(args[0])) {
392399
auto pos = IntPos::extractPos(args[0]);
393400
auto did = pos->getDimensionId();
394401
if (dimid == did || did < 0 || did > 2) {
395-
sp->simulateLookAt(pos->getBlockPos(), (sim::LookDuration)0);
402+
sp->simulateLookAt(pos->getBlockPos(), (sim::LookDuration)lookDuration);
396403
return Boolean::newBoolean(true);
397404
}
398405
lse::getSelfPluginInstance().getLogger().debug("Can't simulate look at other dimension!");
@@ -401,7 +408,7 @@ Local<Value> PlayerClass::simulateLookAt(const Arguments& args) {
401408
auto pos = FloatPos::extractPos(args[0]);
402409
auto did = pos->getDimensionId();
403410
if (dimid == did || did < 0 || did > 2) {
404-
sp->simulateLookAt(pos->getVec3(), (sim::LookDuration)0);
411+
sp->simulateLookAt(pos->getVec3(), (sim::LookDuration)lookDuration);
405412
return Boolean::newBoolean(true);
406413
}
407414
lse::getSelfPluginInstance().getLogger().debug("Can't simulate look at other dimension!");
@@ -411,14 +418,14 @@ Local<Value> PlayerClass::simulateLookAt(const Arguments& args) {
411418
auto pos = IntPos::extractPos(block->getPos());
412419
auto did = pos->getDimensionId();
413420
if (dimid == did || did < 0 || did > 2) {
414-
sp->simulateLookAt(pos->getBlockPos(), (sim::LookDuration)0);
421+
sp->simulateLookAt(pos->getBlockPos(), (sim::LookDuration)lookDuration);
415422
return Boolean::newBoolean(true);
416423
}
417424
lse::getSelfPluginInstance().getLogger().debug("Can't simulate look at other dimension!");
418425
return Boolean::newBoolean(false);
419426
} else if (auto actor = EntityClass::tryExtractActor(args[0])) {
420427
if (!*actor) return Local<Value>();
421-
sp->simulateLookAt(**actor, (sim::LookDuration)0);
428+
sp->simulateLookAt(**actor, (sim::LookDuration)lookDuration);
422429
return Boolean::newBoolean(true);
423430
}
424431
LOG_WRONG_ARG_TYPE();

0 commit comments

Comments
 (0)