18 KiB
sidebarDepth
| sidebarDepth |
|---|
| 1 |
实体管理
CreateEngineEntityByTypeStr
服务端
method in mod.server.system.serverSystem.ServerSystem
-
描述
创建指定identifier的实体
-
参数
参数名 数据类型说明 engineTypeStr str 实体identifier,例如'minecraft:husk' pos tuple(float,float,float) 生成坐标 rot tuple(float,float) 生物面向 dimensionId int 生成的维度,默认值为0(0为主世界,1为地狱,2为末地) isNpc bool 是否为npc,默认值为False。npc不会移动、转向、存盘。 -
返回值
数据类型说明 str或None 实体Id或者None -
备注
- 在未加载的chunk无法创建 生成村民请使用"minecraft:villager_v2"
-
示例
import mod.server.extraServerApi as serverApi
ServerSystem = serverApi.GetServerSystemCls()
class MyServerSystem(ServerSystem):
def createMob(self):
# 在主世界(0,5,0)的位置创建一个朝向为(0, 0)的尸壳
entityId = self.CreateEngineEntityByTypeStr('minecraft:husk', (0, 5, 0), (0, 0), 0)
CreateEngineItemEntity
服务端
method in mod.server.system.serverSystem.ServerSystem
-
描述
用于创建物品实体(即掉落物),返回物品实体的entityId
-
参数
参数名 数据类型说明 itemDict dict 物品信息字典 dimensionId int 设置dimension,默认为主世界 pos tuple(float,float,float) 生成坐标 -
返回值
数据类型说明 str或None 实体Id或者None -
示例
import mod.server.extraServerApi as serverApi
itemDict = {
'itemName': 'minecraft:bow',
'count': 1,
'enchantData': [(serverApi.GetMinecraftEnum().EnchantType.BowDamage, 1),],
'auxValue': 0,
'customTips':'§c new item §r',
'extraId': 'abc',
'userData': { 'color': { '__type__':8, '__value__':'gray'} },
}
itemEntityId = self.CreateEngineItemEntity(itemDict, 0, (0, 5, 0))
CreateExperienceOrb
服务端
method in mod.server.component.expCompServer.ExpComponentServer
-
描述
创建专属经验球
-
参数
参数名 数据类型说明 exp int 经验球经验 position tuple(float,float,float) 创建的位置 isSpecial bool 是否专属经验球 -
返回值
数据类型说明 bool 设置是否成功 -
备注
- 设置经验球经验,entityId是人的entityId。专属的经验球只有entityId的人才能拾取
-
示例
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateExp(entityId)
comp.CreateExperienceOrb(25,(10,10,10),False)
CreateProjectileEntity
服务端
method in mod.server.component.projectileCompServer.ProjectileComponentServer
-
描述
创建抛射物(直接发射)
-
参数
参数名 数据类型说明 spawnerId str 创建者Id entityIdentifier str 创建抛射物的identifier,如minecraft:snowball param dict 默认为None,详细说明请见备注 -
返回值
数据类型说明 str 创建抛射物的Id,失败时为“-1” -
备注
- param参数解释如下:
参数 类型 解释 position tuple(float,float,float) 初始位置 direction tuple(float,float,float) 初始朝向 power float 投掷的力量值 gravity float 抛射物重力因子,默认为json配置中的值 damage float 抛射物伤害值,默认为json配置中的值 targetId str 抛射物目标(指定了target之后,会和潜影贝生物发射的跟踪导弹的那个投掷物是一个效果),默认不指定 isDamageOwner bool 对创建者是否造成伤害,默认不造成伤害
- param参数解释如下:
-
示例
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateProjectile(levelId)
param = {
'position': (1,1,1),
'direction': (1,1,1)
}
comp.CreateProjectileEntity(playerId, "minecraft:snowball", param)
DestroyEntity
服务端
method in mod.server.system.serverSystem.ServerSystem
-
描述
销毁实体
-
参数
参数名 数据类型说明 entityId str 销毁的实体ID -
返回值
数据类型说明 bool 是否销毁成功 -
示例
import mod.server.extraServerApi as serverApi
ServerSystem = serverApi.GetServerSystemCls()
class FpsServerSystem(ServerSystem):
def testDestroyEntity(self, entityId):
self.DestroyEntity(entityId)
GetDroppedItem
服务端
method in mod.server.component.itemCompServer.ItemCompServer
-
描述
获取掉落物的物品信息
-
参数
参数名 数据类型说明 itemEntityId str 掉落物的entityId getUserData bool 是否获取userData,默认为False -
返回值
数据类型说明 dict 信息 -
备注
- 如果掉落物实体不存在,返回值为None
-
示例
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(levelId)
comp.GetDroppedItem(entityId)
GetEngineActor
服务端
method in mod.server.extraServerApi
-
描述
获取所有实体(不包含玩家)。
-
参数
无
-
返回值
数据类型说明 dict 当前地图中的所有实体信息,key:实体id,value:实体dict -
备注
- 实体信息字典 entityDict
关键字 数据类型 说明 dimensionId int 维度id identifier str 实体identifier
- 实体信息字典 entityDict
-
示例
import mod.server.extraServerApi as serverApi
entityDicts = serverApi.GetEngineActor()
GetLocalPlayerId
客户端
method in mod.client.extraClientApi
-
描述
获取本地玩家的id
-
参数
无
-
返回值
数据类型说明 str 客户端玩家Id -
示例
import mod.client.extraClientApi as clientApi
localId = clientApi.GetLocalPlayerId()
GetPlayerList
服务端
method in mod.server.extraServerApi
-
描述
获取level中所有玩家的id列表
-
参数
无
-
返回值
数据类型说明 list(str) 返回玩家id列表 -
备注
- 由于引擎中的玩家id是无序存储的,所以该接口返回列表的先后顺序没有实际意义,仅为在多平台下表现一致。
-
示例
import mod.server.extraServerApi as serverApi
print serverApi.GetPlayerList()
HasEntity
客户端
method in mod.client.component.gameCompClient.GameComponentClient
-
描述
判断 entity 是否存在
-
参数
参数名 数据类型说明 entityId str 实体id -
返回值
数据类型说明 int 0表示不存在,1表示存在 -
示例
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(levelId)
exist = comp.HasEntity(entityId)
IsEntityAlive
服务端客户端
服务端接口
method in mod.server.component.gameCompServer.GameComponentServer
-
描述
判断生物实体是否存活或非生物实体是否存在
-
参数
参数名 数据类型说明 entityId str 实体id -
返回值
数据类型说明 bool false表示生物实体已死亡或非生物实体已销毁,true表示生物实体存活或非生物实体存在 -
备注
- 注意,如果检测的实体所在的区块被卸载,则该接口返回False。因此,需要注意实体所在的区块是否被加载。
- 区块卸载:游戏只会加载玩家周围的区块,玩家移动到别的区域时,原来所在区域的区块会被卸载,参考区块介绍
-
示例
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
alive = comp.IsEntityAlive(entityId)
客户端接口
method in mod.client.component.gameCompClient.GameComponentClient
-
描述
判断生物实体是否存活或非生物实体是否存在
-
参数
参数名 数据类型说明 entityId str 实体id -
返回值
数据类型说明 bool false表示生物实体已死亡或非生物实体已销毁,true表示生物实体存活或非生物实体存在 -
备注
- 注意,如果检测的实体所在的区块被卸载,则该接口返回False。因此,需要注意实体所在的区块是否被加载。
- 区块卸载:游戏只会加载玩家周围的区块,玩家移动到别的区域时,原来所在区域的区块会被卸载,参考区块介绍
-
示例
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(levelId)
alive = comp.IsEntityAlive(entityId)
KillEntity
服务端
method in mod.server.component.gameCompServer.GameComponentServer
-
描述
杀死某个Entity
-
参数
参数名 数据类型说明 entityId str 要杀死的目标的entityId -
返回值
数据类型说明 bool 是否杀死成功 -
示例
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.KillEntity(entityId)
SpawnItemToLevel
服务端
method in mod.server.component.itemCompServer.ItemCompServer
-
描述
生成物品掉落物,如果需要获取物品的entityId,可以调用服务端系统接口CreateEngineItemEntity
-
参数
参数名 数据类型说明 itemDict dict 物品信息字典 dimensionId int 设置dimension pos tuple(float,float,float) 生成位置 -
返回值
数据类型说明 bool 设置结果 -
示例
import mod.server.extraServerApi as serverApi
itemDict = {
'itemName': 'minecraft:bow',
'count': 1,
'enchantData': [(serverApi.GetMinecraftEnum().EnchantType.BowDamage, 1),],
'auxValue': 0,
'customTips':'§c new item §r',
'extraId': 'abc',
'userData': {},
}
comp = serverApi.GetEngineCompFactory().CreateItem(levelId)
comp.SpawnItemToLevel(itemDict, 0, (0,80,20))
# 当最大生成数量为 1 时,可以继续调用生成 2 个物品
comp.SpawnItemToLevel(itemDict, 0, (0,80,20))
SpawnLootTable
服务端
method in mod.server.component.actorLootCompServer.ActorLootComponentServer
-
描述
使用生物类型模拟一次随机掉落,生成的物品与json定义的概率有关
-
参数
参数名 数据类型说明 pos tuple(int,int,int) 掉落位置 identifier str 实体identifier,如minecraft:guardian playerKillerId str 玩家杀手(只能是玩家),默认None damageCauseEntityId str 伤害来源实体Id(掉落与该实体手持物品的抢夺附魔等级有关),默认None -
返回值
数据类型说明 bool 是否成功生成掉落 -
备注
- 需要在对应的player实体附近生成,否则会生成失败。对于某些特殊的生物,如minecraft:sheep,需要使用SpawnLootTableWithActor接口来模拟随机掉落。
-
示例
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateActorLoot(playerId)
result = comp.SpawnLootTable((1, 4, 5), 'minecraft:guardian')
SpawnLootTableWithActor
服务端
method in mod.server.component.actorLootCompServer.ActorLootComponentServer
-
描述
使用生物实例模拟一次随机掉落,生成的物品与json定义的概率有关
-
参数
参数名 数据类型说明 pos tuple(int,int,int) 掉落位置 entityId str 模拟生物的生物Id playerKillerId str 玩家杀手(只能是玩家),默认None damageCauseEntityId str 伤害来源实体Id(掉落与该实体手持物品的抢夺附魔等级有关),默认None -
返回值
数据类型说明 bool 是否成功生成掉落 -
备注
- 需要在对应的player实体附近生成,否则会生成失败
-
示例
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateActorLoot(playerId)
result = comp.SpawnLootTableWithActor((1, 4, 5), '-335007449086')
SpawnResources
服务端
method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer
-
描述
产生方块随机掉落(该方法不适用于实体方块)
-
参数
参数名 数据类型说明 identifier str 方块的identifier,如minecraft:wool pos tuple(int,int,int) 掉落位置 aux int 方块的附加值 probability float 掉落概率,范围为[0, 1],0为不掉落,1为100%掉落 bonusLootLevel int 时运等级,默认为0 dimensionId int 掉落方块的维度,默认值为-1,传入非负值时用于获取产生方块掉落的维度;否则将随机挑选一个存在玩家的维度产生掉落 allowRandomness bool 是否允许随机采集,默认为True,如果为False,掉落概率probability无效 -
返回值
数据类型说明 bool 是否成功 -
备注
- 时运等级[bonusLootLevel]只对部分方块生效 掉落概率[probability]对部分农作物树叶不生效
- 可在对应维度的常加载区块产生掉落
-
示例
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBlockInfo(levelId)
# 金矿石掉落
result = comp.SpawnResources('minecraft:gold_ore', (1,1,1), 7, 1.0, 10)
# 指定维度产生掉落
comp = serverApi.GetEngineCompFactory().CreateBlockInfo(levelId)
result = comp.SpawnResources('minecraft:gold_ore', (1,1,1), 7, 1.0, 10, 0)
SpawnResourcesSilkTouched
服务端
method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer
-
描述
模拟方块精准采集掉落
-
参数
参数名 数据类型说明 identifier str 方块的identifier,如minecraft:wool pos tuple(int,int,int) 掉落位置 aux int 方块的附加值 dimensionId int 掉落方块的维度,默认值为-1,传入非负值时用于获取产生方块掉落的维度;否则将随机挑选一个存在玩家的维度产生掉落 -
返回值
数据类型说明 bool 是否成功 -
备注
- 如果指定方块不属于精准采集方块,返回False
-
示例
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBlockInfo(levelId)
result = comp.SpawnResourcesSilkTouched('minecraft:gold_ore', (1,1,1), 7)