This commit is contained in:
boybook
2025-12-01 20:59:16 +08:00
parent 12738a142c
commit 760c2dd9ad
5535 changed files with 21070 additions and 2021 deletions

View File

@@ -0,0 +1,56 @@
---
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))
```