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


Java Attribute类代码示例

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

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

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

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

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

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

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

示例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());
        }
    }
}
 
开发者ID:Creeperface01,项目名称:NukkitGT,代码行数:18,代码来源:UpdateAttributesPacket.java

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

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

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

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

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

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


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