本文整理汇总了Java中cn.nukkit.entity.Attribute.setValue方法的典型用法代码示例。如果您正苦于以下问题:Java Attribute.setValue方法的具体用法?Java Attribute.setValue怎么用?Java Attribute.setValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cn.nukkit.entity.Attribute
的用法示例。
在下文中一共展示了Attribute.setValue方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例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: 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);
}
示例4: 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);
}
示例5: 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);
}
示例6: updateBossBar
import cn.nukkit.entity.Attribute; //导入方法依赖的package包/类
/**
* Updates a BossBar
*
* @param text The new BossBar message
* @param length The new BossBar length
* @param bossBarId The BossBar ID
*/
public void updateBossBar(String text, int length, long bossBarId) {
// First we update the boss bar length
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 };
this.dataPacket(pkAttributes);
// And then the boss bar text
SetEntityDataPacket pkMetadata = new SetEntityDataPacket();
pkMetadata.eid = bossBarId;
pkMetadata.metadata = new EntityMetadata()
// Default Metadata tags
.putLong(DATA_FLAGS, 0)
.putShort(DATA_AIR, 400)
.putShort(DATA_MAX_AIR, 400)
.putLong(DATA_LEAD_HOLDER_EID, -1)
.putFloat(DATA_SCALE, 1f)
.putString(Entity.DATA_NAMETAG, text) // Set the entity name
.putInt(Entity.DATA_SCALE, 0); // And make it invisible
this.dataPacket(pkMetadata);
// And now we send the bossbar packet
BossEventPacket pkBoss = new BossEventPacket();
pkBoss.eid = bossBarId;
pkBoss.type = BossEventPacket.UPDATE;
this.dataPacket(pkBoss);
return;
}
示例7: createBossBar
import cn.nukkit.entity.Attribute; //导入方法依赖的package包/类
/**
* Creates and sends a BossBar to the player
*
* @param text The BossBar message
* @param length The BossBar percentage
* @return bossBarId The BossBar ID, you should store it if you want to remove or update the BossBar later
*/
public long createBossBar(String text, int length) {
// First we spawn a entity
long bossBarId = 1095216660480L + ThreadLocalRandom.current().nextLong(0, 0x7fffffffL);
AddEntityPacket pkAdd = new AddEntityPacket();
pkAdd.type = EntityCreeper.NETWORK_ID;
pkAdd.entityUniqueId = bossBarId;
pkAdd.entityRuntimeId = bossBarId;
pkAdd.x = (float) this.x;
pkAdd.y = (float) -10; // Below the bedrock
pkAdd.z = (float) this.z;
pkAdd.speedX = (float) this.motionX;
pkAdd.speedY = (float) this.motionY;
pkAdd.speedZ = (float) this.motionZ;
EntityMetadata metadata = new EntityMetadata()
// Default Metadata tags
.putLong(DATA_FLAGS, 0)
.putShort(DATA_AIR, 400)
.putShort(DATA_MAX_AIR, 400)
.putLong(DATA_LEAD_HOLDER_EID, -1)
.putFloat(DATA_SCALE, 1f)
.putString(Entity.DATA_NAMETAG, text) // Set the entity name
.putInt(Entity.DATA_SCALE, 0); // And make it invisible
pkAdd.metadata = metadata;
this.dataPacket(pkAdd);
// Now we send the entity attributes
// TODO: Attributes should be sent on AddEntityPacket, however it doesn't work (client bug?)
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 };
this.dataPacket(pkAttributes);
// And now we send the bossbar packet
BossEventPacket pkBoss = new BossEventPacket();
pkBoss.eid = bossBarId;
pkBoss.type = BossEventPacket.ADD;
this.dataPacket(pkBoss);
return bossBarId;
}