“方法大全”中的常用方法
罗列出一些常用的方法,会在本章中大量用到。
AttributeComponent
JavaScript
//返回值:Unit
//描述:是否跳过过滤,跳过的话不管属性值是否 >0.0 都会触发,否则只有玩家属性值 >=1.0 是才会触发
attr.setSkipFilter(Boolean skip)JavaScript
//返回值:AttributeData
//描述:获得实体的属性数据
attr.getData(LivingEntity entity, AttributeHandle handle)
//返回值:Array<Number>
//描述:获得实体某一属性的属性值数据
attr.getAttributeValue(LivingEntity entity, String defaultAttributeName, AttributeHandle handle)
//返回值:Number
//描述:获取实体某一属性的随机值。调用该方法会将所获取的属性值储存至临时数据,相当于自动调用 storageValue() 方法
attr.getRandomValue(LivingEntity entity, String defaultAttributeName, AttributeHandle handle)
//返回值:Number
//描述:获取实体此次属性处理事件对对方所造成的伤害。attacker / killer 则为攻击者所造成的伤害 (例如 物理伤害)。entity 则为被攻击者的反击伤害 (例如 反弹伤害)
attr.getDamage(LivingEntity entity, AttributeHandle handle)
//返回值:Unit
//描述:设置实体此次属性处理事件对对方所造成的伤害
attr.setDamage(LivingEntity entity, Double value, AttributeHandle handle)
//返回值:Unit
//描述:增加实体此次属性处理事件对对方所造成的伤害
attr.addDamage(LivingEntity entity, Double value, AttributeHandle handle)
//返回值:Unit
//描述:减少实体此次属性处理事件对对方所造成的伤害
attr.takeDamage(LivingEntity entity, Double value, AttributeHandle handle)
//返回值:Unit
//描述:取消此次属性处理事件的处理,相当于此次所有属性都不处理,也不会受到伤害
attr.setCancelled(Boolean flag, AttributeHandle handle)
//返回值:Boolean
//描述:几率触发
attr.chance(Double value)Utils
JavaScript
//返回值:Unit
//描述:快捷注册 OTHER 类属性
Utils.registerOtherAttribute(String attributeName, Double combatPower, String placeholder)
//返回值:Unit
//描述:恢复目标生命值
Utils.safeHeal(LivingEntity entity, Double heal)
//返回值:List<Entity>
//描述:获取实体周围内的实体
Utils.getNearbyEntities(LivingEntity entity, Double x, Double y, Double z, Boolean self)
//返回值:List<Entity>
//描述:获取实体周围内的指定类型实体
Utils.getNearbyEntities(LivingEntity entity, Double x, Double y, Double z, Boolean self, List<EntityType> type)AttributeAPI
JavaScript
//返回值:AttributeData
//描述:此处留空
AttributeAPI.getAttrData(LivingEntity entity)
//返回值:void
//描述:此处留空
//kotlin版本号.jvm.functions.Function0
AttributeAPI.runEntityTask(long millis, String id, LivingEntity entity, Boolean skipStateCheck, Function0<Unit> block)
//返回值:void
//描述:此处留空
AttributeAPI.addSourceAttribute(AttributeData data, String source, List<String> list)
//返回值:void
//描述:此处留空
AttributeAPI.takeSourceAttribute(AttributeData attributeData, String source)