Skip to content

Commit

Permalink
fix: fix simulateLookAt #146
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox committed Aug 8, 2024
1 parent 24fea65 commit 0edc422
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
9 changes: 6 additions & 3 deletions docs/apis/GameAPI/Player.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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`
Expand Down
9 changes: 6 additions & 3 deletions docs/apis/GameAPI/Player.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])`

- 参数:

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

- 返回值:是否成功模拟操作
- 返回值类型:`Boolean`
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/api/RemoteCallAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Local<Value> _extractValue(RemoteCall::ItemType&& v) {
};
Local<Value> _extractValue(RemoteCall::NbtType&& v) {
if (v.own) return NbtCompoundClass::pack(v.tryGetUniquePtr());
else return NbtCompoundClass::pack(const_cast<CompoundTag*>(v.ptr), false);
else return NbtCompoundClass::pack(const_cast<CompoundTag*>(v.ptr));
};

Local<Value> extract(RemoteCall::ValueType&& val);
Expand Down
17 changes: 12 additions & 5 deletions src/legacy/api/SimulatedPlayerAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,19 @@ Local<Value> PlayerClass::simulateLookAt(const Arguments& args) {
auto sp = asSimulatedPlayer();
if (!sp) return Local<Value>();
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<IntPos>(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!");
Expand All @@ -401,7 +408,7 @@ Local<Value> 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!");
Expand All @@ -411,14 +418,14 @@ Local<Value> 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<Value>();
sp->simulateLookAt(**actor, (sim::LookDuration)0);
sp->simulateLookAt(**actor, (sim::LookDuration)lookDuration);
return Boolean::newBoolean(true);
}
LOG_WRONG_ARG_TYPE();
Expand Down

0 comments on commit 0edc422

Please sign in to comment.