• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Attribute类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中cn.nukkit.entity.Attribute的典型用法代码示例。如果您正苦于以下问题:Java Attribute类的具体用法?Java Attribute怎么用?Java Attribute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Attribute类属于cn.nukkit.entity包,在下文中一共展示了Attribute类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: setHealth

import cn.nukkit.entity.Attribute; //导入依赖的package包/类
@Override
public void setHealth(float health) {
    if (health < 1) {
        health = 0;
    }

    super.setHealth(health);
    Attribute attr = Attribute.getAttribute(Attribute.MAX_HEALTH).setMaxValue(this.getMaxHealth()).setValue(health > 0 ? (health < getMaxHealth() ? health : getMaxHealth()) : 0);
    if (this.spawned) {
        UpdateAttributesPacket pk = new UpdateAttributesPacket();
        pk.entries = new Attribute[]{attr};
        pk.entityId = this.id;
        this.dataPacket(pk);
    }
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:16,代码来源:Player.java


示例17: 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


示例18: 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.putLFloat(attribute.getMinValue());
        this.putLFloat(attribute.getMaxValue());
        this.putLFloat(attribute.getValue());
        this.putLFloat(attribute.getDefaultValue());
        this.putString(attribute.getName());
    }
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:14,代码来源:BinaryStream.java


示例19: setHealth

import cn.nukkit.entity.Attribute; //导入依赖的package包/类
@Override
public void setHealth(float health) {
    super.setHealth(health);
    Attribute attr = Attribute.getAttribute(Attribute.MAX_HEALTH).setMaxValue(this.getMaxHealth()).setValue(health > 0 ? (health < getMaxHealth() ? health : getMaxHealth()) : 0);
    if (this.spawned) {
        UpdateAttributesPacket pk = new UpdateAttributesPacket();
        pk.entries = new Attribute[]{attr};
        pk.entityId = 0;
        this.dataPacket(pk);
    }
}
 
开发者ID:Creeperface01,项目名称:NukkitGT,代码行数:12,代码来源:Player.java


示例20: sendAttributes

import cn.nukkit.entity.Attribute; //导入依赖的package包/类
public void sendAttributes() {
    UpdateAttributesPacket pk = new UpdateAttributesPacket();
    pk.entityId = 0;
    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:NycuRO,项目名称:Apollo-OLD,代码行数:13,代码来源:Player.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TwinklingRefreshLayout类代码示例发布时间:2022-05-22
下一篇:
Java TextFileInputField类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap