57 lines
1.9 KiB
Markdown
57 lines
1.9 KiB
Markdown
---
|
||
sidebarDepth: 1
|
||
---
|
||
# 行为
|
||
|
||
## UseItemAttackEntity
|
||
|
||
<span style="display:inline;color:#ff5555">服务端</span>
|
||
|
||
method in mod.server.component.gameCompServer.GameComponentServer
|
||
|
||
- 描述
|
||
|
||
使用指定物品攻击某个实体。
|
||
|
||
- 参数
|
||
|
||
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
|
||
| :--- | :--- | :--- |
|
||
| itemDict | dict | 物品字典数据 |
|
||
| entityId | str | 攻击实体id |
|
||
| cause | str | 伤害类型,默认值是EntityAttack,详见Minecraft枚举值文档的[ActorDamageCause](../../枚举值/ActorDamageCause.md) |
|
||
| attackerPos | tuple(float,float,float) | 伤害来源坐标,默认值为None,该参数会影响击退效果的计算 |
|
||
| knocked | bool | 是否击退,默认值为False,如果设置为True,需同时设置attackerPos |
|
||
| customTag | str | 标识自定义伤害来源,只在cause为Custom生效,可在ActorHurtServerEvent、ActuallyHurtServerEvent、DamageEvent、PlayerHurtEvent、PlayerDieEvent、MobDieEvent监听到标识 |
|
||
|
||
- 返回值
|
||
|
||
| <div style="width: 4em">数据类型</div> | 说明 |
|
||
| :--- | :--- |
|
||
| dict | 成功:返回使用过后的物品字典;失败:返回None |
|
||
|
||
- 备注
|
||
- 无攻击力的物品,将会没有伤害。
|
||
- 有耐久的物品在攻击后,将会扣除部分耐久。
|
||
- 可通过DamageEvent等事件修改伤害值。
|
||
- 如果itemDict写入了不可添加到该物品的附魔,该附魔效果将不会生效,返回的itemDict也不会带有该附魔信息。如果有需求,可考虑将附魔信息写入userData。
|
||
|
||
- 示例
|
||
|
||
```python
|
||
import mod.server.extraServerApi as serverApi
|
||
levelId = serverApi.GetLevelId()
|
||
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
|
||
itemDict = {
|
||
"newItemName": "minecraft:iron_sword",
|
||
"newAuxValue": 0,
|
||
"count": 1,
|
||
"durability": 256,
|
||
"enchantData": [(9,1)]
|
||
}
|
||
print(comp.UseItemAttackEntity(itemDict, entityId))
|
||
```
|
||
|
||
|
||
|