当前位置: 首页>>代码示例>>Java>>正文


Java Attribute.setValue方法代码示例

本文整理汇总了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);
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:25,代码来源:BinaryStream.java

示例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);
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:24,代码来源:BinaryStream.java

示例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);
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:30,代码来源:BinaryStream.java

示例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);
}
 
开发者ID:solo5star,项目名称:BossBarAPI_Nukkit,代码行数:28,代码来源:PacketAPI.java

示例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);
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:10,代码来源:DummyBossBar.java

示例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;
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:38,代码来源:Player.java

示例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;
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:50,代码来源:Player.java


注:本文中的cn.nukkit.entity.Attribute.setValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。