本文整理汇总了Java中cn.nukkit.entity.Attribute类的典型用法代码示例。如果您正苦于以下问题:Java Attribute类的具体用法?Java Attribute怎么用?Java Attribute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Attribute类属于cn.nukkit.entity包,在下文中一共展示了Attribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encode
import cn.nukkit.entity.Attribute; //导入依赖的package包/类
public void encode() {
this.reset();
this.putEntityRuntimeId(this.entityId);
if (this.entries == null) {
this.putUnsignedVarInt(0);
} else {
this.putUnsignedVarInt(this.entries.length);
for (Attribute entry : this.entries) {
this.putLFloat(entry.getMinValue());
this.putLFloat(entry.getMaxValue());
this.putLFloat(entry.getValue());
this.putLFloat(entry.getDefaultValue());
this.putString(entry.getName());
}
}
}
示例2: getAttributeList
import cn.nukkit.entity.Attribute; //导入依赖的package包/类
/**
* Reads a list of Attributes from the stream.
*
* @return Attribute[]
*/
public Attribute[] getAttributeList() throws Exception {
List<Attribute> list = new ArrayList<>();
long count = this.getUnsignedVarInt();
for (int i = 0; i < count; ++i) {
String name = this.getString();
Attribute attr = Attribute.getAttributeByName(name);
if (attr != null) {
attr.setMinValue(this.getLFloat());
attr.setValue(this.getLFloat());
attr.setMaxValue(this.getLFloat());
list.add(attr);
} else {
throw new Exception("Unknown attribute type \"" + name + "\"");
}
}
return list.stream().toArray(Attribute[]::new);
}
示例3: encode
import cn.nukkit.entity.Attribute; //导入依赖的package包/类
public void encode() {
this.reset();
this.putEntityRuntimeId(this.entityRuntimeId);
if (this.entries == null) {
this.putUnsignedVarInt(0);
} else {
this.putUnsignedVarInt(this.entries.length);
for (Attribute entry : this.entries) {
this.putLFloat(entry.getMinValue());
this.putLFloat(entry.getMaxValue());
this.putLFloat(entry.getValue());
this.putLFloat(entry.getDefaultValue());
this.putString(entry.getName());
}
}
}
示例4: getAttributeList
import cn.nukkit.entity.Attribute; //导入依赖的package包/类
/**
* Reads a list of Attributes from the stream.
* @return Attribute[]
*/
public Attribute[] getAttributeList() throws Exception {
List<Attribute> list = new ArrayList<>();
long count = this.getUnsignedVarInt();
for(int i = 0; i < count; ++i){
String name = this.getString();
Attribute attr = Attribute.getAttributeByName(name);
if(attr != null){
attr.setMinValue(this.getLFloat());
attr.setValue(this.getLFloat());
attr.setMaxValue(this.getLFloat());
list.add(attr);
}else{
throw new Exception("Unknown attribute type \"" + name + "\"");
}
}
return list.stream().toArray(Attribute[]::new);
}
示例5: setHealth
import cn.nukkit.entity.Attribute; //导入依赖的package包/类
/**
* プレイヤーの体力を設定します。
* @param health 設定する体力量
* @return void
*/
@Override
public void setHealth(float health) {
if (health < 1) {
health = 0;
}
super.setHealth(health);
Attribute attr = Attribute.getAttribute(Attribute.MAX_HEALTH).setMaxValue(this.getAbsorption() % 2 != 0 ? this.getMaxHealth() + 1 : this.getMaxHealth()).setValue(health > 0 ? (health < getMaxHealth() ? health : getMaxHealth()) : 0);
if (this.spawned) {
UpdateAttributesPacket pk = new UpdateAttributesPacket();
pk.entries = new Attribute[]{attr};
pk.entityRuntimeId = this.id;
this.dataPacket(pk);
}
}
示例6: encode
import cn.nukkit.entity.Attribute; //导入依赖的package包/类
public void encode() {
this.reset();
this.putVarLong(this.entityId);
if (this.entries == null) {
this.putUnsignedVarInt(0);
} else {
this.putUnsignedVarInt(this.entries.length);
for (Attribute entry : this.entries) {
this.putLFloat(entry.getMinValue());
this.putLFloat(entry.getMaxValue());
this.putLFloat(entry.getValue());
this.putLFloat(entry.getDefaultValue());
this.putString(entry.getName());
}
}
}
示例7: getAttributeList
import cn.nukkit.entity.Attribute; //导入依赖的package包/类
/**
* Reads a list of Attributes from the stream.
* @return Attribute[]
*/
public Attribute[] getAttributeList() throws Exception {
List<Attribute> list = new ArrayList<>();
long count = this.getUnsignedVarInt();
for(int i = 0; i < count; ++i){
float min = this.getLFloat();
float max = this.getLFloat();
float current = this.getLFloat();
float defaultValue = this.getLFloat();
String name = this.getString();
Attribute attr = Attribute.getAttributeByName(name);
if(attr != null){
attr.setMinValue(min);
attr.setMaxValue(max);
attr.setValue(current);
attr.setDefaultValue(defaultValue);
list.add(attr);
}else{
throw new Exception("Unknown attribute type \"" + name + "\"");
}
}
return list.stream().toArray(Attribute[]::new);
}
示例8: sendPercentage
import cn.nukkit.entity.Attribute; //导入依赖的package包/类
/**
* Sets how many % the bar is full by EID
*
* @param double percentage
* 0-100
* @param int eid
*/
public static void sendPercentage(Player player, int eid, double percentage){
if(percentage > 100){
percentage = 100;
}
if(percentage < 0){
percentage = 0;
}
UpdateAttributesPacket upk = new UpdateAttributesPacket(); // Change health of fake wither . bar progress
upk.entityId = eid;
Attribute attr = Attribute.getAttribute(Attribute.MAX_HEALTH);
attr.setMaxValue(100);
attr.setValue((float) percentage);
upk.entries = new Attribute[]{ attr };
player.dataPacket(upk);
BossEventPacket bpk = new BossEventPacket(); // This updates the bar
bpk.eid = eid;
bpk.type = 1; // UPDATE
player.dataPacket(bpk);
}
示例9: encode
import cn.nukkit.entity.Attribute; //导入依赖的package包/类
public void encode() {
this.reset();
this.putLong(this.entityId);
if (this.entries == null) {
this.putShort(0);
} else {
this.putShort(this.entries.length);
for (Attribute entry : this.entries) {
this.putFloat(entry.getMinValue());
this.putFloat(entry.getMaxValue());
this.putFloat(entry.getValue());
this.putString(entry.getName());
}
}
}
示例10: sendAttributes
import cn.nukkit.entity.Attribute; //导入依赖的package包/类
private void sendAttributes() {
UpdateAttributesPacket pkAttributes = new UpdateAttributesPacket();
pkAttributes.entityId = bossBarId;
Attribute attr = Attribute.getAttribute(Attribute.MAX_HEALTH);
attr.setMaxValue(100); // Max value - We need to change the max value first, or else the "setValue" will return a IllegalArgumentException
attr.setValue(length); // Entity health
pkAttributes.entries = new Attribute[]{attr};
player.dataPacket(pkAttributes);
}
示例11: putAttributeList
import cn.nukkit.entity.Attribute; //导入依赖的package包/类
/**
* Writes a list of Attributes to the packet buffer using the standard format.
*/
public void putAttributeList(Attribute[] attributes) {
this.putUnsignedVarInt(attributes.length);
for (Attribute attribute : attributes) {
this.putString(attribute.getName());
this.putLFloat(attribute.getMinValue());
this.putLFloat(attribute.getValue());
this.putLFloat(attribute.getMaxValue());
}
}
示例12: putAttributeList
import cn.nukkit.entity.Attribute; //导入依赖的package包/类
/**
* Writes a list of Attributes to the packet buffer using the standard format.
*/
public void putAttributeList(Attribute[] attributes){
this.putUnsignedVarInt(attributes.length);
for (Attribute attribute: attributes) {
this.putString(attribute.getName());
this.putLFloat(attribute.getMinValue());
this.putLFloat(attribute.getValue());
this.putLFloat(attribute.getMaxValue());
}
}
示例13: sendAttributes
import cn.nukkit.entity.Attribute; //导入依赖的package包/类
public void sendAttributes() {
UpdateAttributesPacket pk = new UpdateAttributesPacket();
pk.entityRuntimeId = this.getId();
pk.entries = new Attribute[]{
Attribute.getAttribute(Attribute.MAX_HEALTH).setMaxValue(this.getMaxHealth()).setValue(health > 0 ? (health < getMaxHealth() ? health : getMaxHealth()) : 0),
Attribute.getAttribute(Attribute.MAX_HUNGER).setValue(this.getFoodData().getLevel()),
Attribute.getAttribute(Attribute.MOVEMENT_SPEED).setValue(this.getMovementSpeed()),
Attribute.getAttribute(Attribute.EXPERIENCE_LEVEL).setValue(this.getExperienceLevel()),
Attribute.getAttribute(Attribute.EXPERIENCE).setValue(((float) this.getExperience()) / calculateRequireExperience(this.getExperienceLevel()))
};
this.dataPacket(pk);
}
示例14: setMovementSpeed
import cn.nukkit.entity.Attribute; //导入依赖的package包/类
@Override
public void setMovementSpeed(float speed) {
super.setMovementSpeed(speed);
if (this.spawned) {
Attribute attribute = Attribute.getAttribute(Attribute.MOVEMENT_SPEED).setValue(speed);
this.setAttribute(attribute);
}
}
示例15: sendAttributes
import cn.nukkit.entity.Attribute; //导入依赖的package包/类
public void sendAttributes() {
UpdateAttributesPacket pk = new UpdateAttributesPacket();
pk.entityId = this.getId();
pk.entries = new Attribute[]{
Attribute.getAttribute(Attribute.MAX_HEALTH).setMaxValue(this.getMaxHealth()).setValue(health > 0 ? (health < getMaxHealth() ? health : getMaxHealth()) : 0),
Attribute.getAttribute(Attribute.MAX_HUNGER).setValue(this.getFoodData().getLevel()),
Attribute.getAttribute(Attribute.MOVEMENT_SPEED).setValue(this.getMovementSpeed()),
Attribute.getAttribute(Attribute.EXPERIENCE_LEVEL).setValue(this.getExperienceLevel()),
Attribute.getAttribute(Attribute.EXPERIENCE).setValue(((float) this.getExperience()) / calculateRequireExperience(this.getExperienceLevel()))
};
this.dataPacket(pk);
}