Skip to content

Commit 3f4efbd

Browse files
committed
feat: add Player.toEntity api
1 parent 8664be9 commit 3f4efbd

File tree

4 files changed

+62
-32
lines changed

4 files changed

+62
-32
lines changed

docs/apis/GameAPI/Player.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,17 @@ such as `Base` `Current` `DefaultMax` `DefaultMin` `Max` `Min` `Name` by default
13341334
| village_hero | 29 |
13351335
| darkness | 30 |
13361336

1337+
#### Convert Player Object to Entity Object
1338+
1339+
`en.toEntity()`
1340+
1341+
- Return value: The converted `Entity` object.
1342+
- Return value type: `Entity`
1343+
- Returns `Null` if the transition fails.
1344+
1345+
If the current entity object points to a player, you can use this function to convert the entity object to a player
1346+
object to use more player-related APIs.
1347+
13371348
### Determine whether it is a simulated player
13381349

13391350
`pl.isSimulatedPlayer()`

docs/apis/GameAPI/Player.zh.md

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,38 +1693,46 @@
16931693
- 返回值:操作是否成功
16941694
- 返回值类型:`Boolean`
16951695

1696-
| 效果 | 名称 | 数字id |
1697-
|--------|-----------------|------|
1698-
| 迅捷 | speed | 1 |
1699-
| 缓慢 | slowness | 2 |
1700-
| 急迫 | haste | 3 |
1701-
| 挖掘疲劳 | mining_fatigue | 4 |
1702-
| 力量 | strength | 5 |
1703-
| 瞬间治疗 | instant_health | 6 |
1704-
| 瞬间伤害 | instant_damage | 7 |
1705-
| 跳跃提升 | jump_boost | 8 |
1706-
| 反胃 | nausea | 9 |
1707-
| 生命恢复 | regeneration | 10 |
1708-
| 抗性提升 | resistance | 11 |
1709-
| 抗火 | fire_resistance | 12 |
1710-
| 水下呼吸 | water_breathing | 13 |
1711-
| 隐身 | invisibility | 14 |
1712-
| 失明 | blindness | 15 |
1713-
| 夜视 | night_vision | 16 |
1714-
| 饥饿 | hunger | 17 |
1715-
| 虚弱 | weakness | 18 |
1716-
| 中毒 | poison | 19 |
1717-
| 凋零 | wither | 20 |
1718-
| 生命提升 | health_boost | 21 |
1719-
| 伤害吸收 | absorption | 22 |
1720-
| 饱和 | saturation | 23 |
1721-
| 飘浮 | levitation | 24 |
1722-
| 中毒(致命) | fatal_poison | 25 |
1723-
| 潮涌能量 | conduit_power | 26 |
1724-
| 缓降 | slow_falling | 27 |
1725-
| 不祥之兆 | bad_omen | 28 |
1726-
| 村庄英雄 | village_hero | 29 |
1727-
| 黑暗 | darkness | 30 |
1696+
| 效果 | 名称 | 数字 id |
1697+
| ------------ | --------------- | ------- |
1698+
| 迅捷 | speed | 1 |
1699+
| 缓慢 | slowness | 2 |
1700+
| 急迫 | haste | 3 |
1701+
| 挖掘疲劳 | mining_fatigue | 4 |
1702+
| 力量 | strength | 5 |
1703+
| 瞬间治疗 | instant_health | 6 |
1704+
| 瞬间伤害 | instant_damage | 7 |
1705+
| 跳跃提升 | jump_boost | 8 |
1706+
| 反胃 | nausea | 9 |
1707+
| 生命恢复 | regeneration | 10 |
1708+
| 抗性提升 | resistance | 11 |
1709+
| 抗火 | fire_resistance | 12 |
1710+
| 水下呼吸 | water_breathing | 13 |
1711+
| 隐身 | invisibility | 14 |
1712+
| 失明 | blindness | 15 |
1713+
| 夜视 | night_vision | 16 |
1714+
| 饥饿 | hunger | 17 |
1715+
| 虚弱 | weakness | 18 |
1716+
| 中毒 | poison | 19 |
1717+
| 凋零 | wither | 20 |
1718+
| 生命提升 | health_boost | 21 |
1719+
| 伤害吸收 | absorption | 22 |
1720+
| 饱和 | saturation | 23 |
1721+
| 飘浮 | levitation | 24 |
1722+
| 中毒(致命) | fatal_poison | 25 |
1723+
| 潮涌能量 | conduit_power | 26 |
1724+
| 缓降 | slow_falling | 27 |
1725+
| 不祥之兆 | bad_omen | 28 |
1726+
| 村庄英雄 | village_hero | 29 |
1727+
| 黑暗 | darkness | 30 |
1728+
1729+
#### 将玩家对象转换实体对象
1730+
1731+
`en.toEntity()`
1732+
1733+
- 返回值:转换成的实体对象
1734+
- 返回值类型:`Entity`
1735+
- 如果转换失败,则返回 `Null`
17281736

17291737
#### 判断是否为模拟玩家
17301738

src/legacy/api/PlayerAPI.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ ClassDefine<PlayerClass> PlayerClassBuilder =
313313
.instanceFunction("getAllItems", &PlayerClass::getAllItems)
314314
.instanceFunction("removeScore", &PlayerClass::deleteScore)
315315
.instanceFunction("distanceToPos", &PlayerClass::distanceTo)
316+
317+
.instanceFunction("toEntity", &PlayerClass::toEntity)
316318
.build();
317319

318320
//////////////////// Classes ////////////////////
@@ -3604,3 +3606,10 @@ Local<Value> PlayerClass::removeEffect(const Arguments& args) {
36043606
}
36053607
CATCH("Fail in removeEffect!");
36063608
}
3609+
3610+
Local<Value> PlayerClass::toEntity(const Arguments&) {
3611+
try {
3612+
return EntityClass::newEntity(get());
3613+
}
3614+
CATCH("Fail in toEntity!");
3615+
}

src/legacy/api/PlayerAPI.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,5 +224,7 @@ class PlayerClass : public ScriptClass {
224224
Local<Value> removeItem(const Arguments& args);
225225

226226
Local<Value> setAbility(const Arguments& args);
227+
228+
Local<Value> toEntity(const Arguments& args);
227229
};
228230
extern ClassDefine<PlayerClass> PlayerClassBuilder;

0 commit comments

Comments
 (0)