cn.nukkit.entity.Attribute Java Examples
The following examples show how to use
cn.nukkit.entity.Attribute.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UpdateAttributesPacket.java From Jupiter with GNU General Public License v3.0 | 6 votes |
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()); } } }
Example #2
Source File: BinaryStream.java From Jupiter with GNU General Public License v3.0 | 6 votes |
/** * 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); }
Example #3
Source File: UpdateAttributesPacket.java From Nukkit with GNU General Public License v3.0 | 6 votes |
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()); } } }
Example #4
Source File: BinaryStream.java From Nukkit with GNU General Public License v3.0 | 6 votes |
/** * 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.toArray(new Attribute[0]); }
Example #5
Source File: UpdateAttributesPacket.java From Nukkit with GNU General Public License v3.0 | 6 votes |
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()); } } }
Example #6
Source File: BinaryStream.java From Nukkit with GNU General Public License v3.0 | 6 votes |
/** * 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); }
Example #7
Source File: BinaryStream.java From Jupiter with GNU General Public License v3.0 | 5 votes |
/** * 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()); } }
Example #8
Source File: DummyBossBar.java From Nukkit with GNU General Public License v3.0 | 5 votes |
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); }
Example #9
Source File: BinaryStream.java From Nukkit with GNU General Public License v3.0 | 5 votes |
/** * 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()); } }
Example #10
Source File: DummyBossBar.java From Nukkit with GNU General Public License v3.0 | 5 votes |
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); }
Example #11
Source File: BinaryStream.java From Nukkit with GNU General Public License v3.0 | 5 votes |
/** * 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()); } }
Example #12
Source File: PlayerFood.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public void sendFoodLevel(int foodLevel) { if (this.getPlayer().spawned) { this.getPlayer().setAttribute(Attribute.getAttribute(Attribute.MAX_HUNGER).setValue(foodLevel)); } }
Example #13
Source File: PlayerFood.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void sendFoodLevel(int foodLevel) { if (this.getPlayer().spawned) { this.getPlayer().setAttribute(Attribute.getAttribute(Attribute.MAX_HUNGER).setValue(foodLevel)); } }
Example #14
Source File: PlayerFood.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void sendFoodLevel(int foodLevel) { if (this.getPlayer().spawned) { this.getPlayer().setAttribute(Attribute.getAttribute(Attribute.MAX_HUNGER).setValue(foodLevel)); } }