Java Code Examples for cn.nukkit.entity.Entity#DATA_TYPE_FLOAT
The following examples show how to use
cn.nukkit.entity.Entity#DATA_TYPE_FLOAT .
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: DataPacketEidReplacer.java From SynapseAPI with GNU General Public License v3.0 | 6 votes |
private static String dataTypeToString(int type) { switch (type) { case Entity.DATA_TYPE_BYTE: return "Byte"; case Entity.DATA_TYPE_SHORT: return "Short"; case Entity.DATA_TYPE_INT: return "Int"; case Entity.DATA_TYPE_FLOAT: return "Float"; case Entity.DATA_TYPE_STRING: return "String"; case Entity.DATA_TYPE_NBT: return "Slot"; case Entity.DATA_TYPE_POS: return "Pos"; case Entity.DATA_TYPE_LONG: return "Long"; case Entity.DATA_TYPE_VECTOR3F: return "Vector3f"; } return "Unknown"; }
Example 2
Source File: FloatEntityData.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public int getType() { return Entity.DATA_TYPE_FLOAT; }
Example 3
Source File: Binary.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public static byte[] writeMetadata(EntityMetadata metadata) { BinaryStream stream = new BinaryStream(); Map<Integer, EntityData> map = metadata.getMap(); stream.putUnsignedVarInt(map.size()); for (int id : map.keySet()) { EntityData d = map.get(id); stream.putUnsignedVarInt(id); stream.putUnsignedVarInt(d.getType()); switch (d.getType()) { case Entity.DATA_TYPE_BYTE: stream.putByte(((ByteEntityData) d).getData().byteValue()); break; case Entity.DATA_TYPE_SHORT: stream.putLShort(((ShortEntityData) d).getData()); break; case Entity.DATA_TYPE_INT: stream.putVarInt(((IntEntityData) d).getData()); break; case Entity.DATA_TYPE_FLOAT: stream.putLFloat(((FloatEntityData) d).getData()); break; case Entity.DATA_TYPE_STRING: String s = ((StringEntityData) d).getData(); stream.putUnsignedVarInt(s.getBytes(StandardCharsets.UTF_8).length); stream.put(s.getBytes(StandardCharsets.UTF_8)); break; case Entity.DATA_TYPE_SLOT: SlotEntityData slot = (SlotEntityData) d; stream.putLShort(slot.blockId); stream.putByte((byte) slot.meta); stream.putLShort(slot.count); break; case Entity.DATA_TYPE_POS: IntPositionEntityData pos = (IntPositionEntityData) d; stream.putVarInt(pos.x); stream.putByte((byte) pos.y); stream.putVarInt(pos.z); break; case Entity.DATA_TYPE_LONG: stream.putVarLong(((LongEntityData) d).getData()); break; case Entity.DATA_TYPE_VECTOR3F: Vector3fEntityData v3data = (Vector3fEntityData) d; stream.putLFloat(v3data.x); stream.putLFloat(v3data.y); stream.putLFloat(v3data.z); break; } } return stream.getBuffer(); }
Example 4
Source File: FloatEntityData.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public int getType() { return Entity.DATA_TYPE_FLOAT; }
Example 5
Source File: Binary.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public static byte[] writeMetadata(EntityMetadata metadata) { BinaryStream stream = new BinaryStream(); Map<Integer, EntityData> map = metadata.getMap(); stream.putUnsignedVarInt(map.size()); for (int id : map.keySet()) { EntityData d = map.get(id); stream.putUnsignedVarInt(id); stream.putUnsignedVarInt(d.getType()); switch (d.getType()) { case Entity.DATA_TYPE_BYTE: stream.putByte(((ByteEntityData) d).getData().byteValue()); break; case Entity.DATA_TYPE_SHORT: stream.putLShort(((ShortEntityData) d).getData()); break; case Entity.DATA_TYPE_INT: stream.putVarInt(((IntEntityData) d).getData()); break; case Entity.DATA_TYPE_FLOAT: stream.putLFloat(((FloatEntityData) d).getData()); break; case Entity.DATA_TYPE_STRING: String s = ((StringEntityData) d).getData(); stream.putUnsignedVarInt(s.getBytes(StandardCharsets.UTF_8).length); stream.put(s.getBytes(StandardCharsets.UTF_8)); break; case Entity.DATA_TYPE_NBT: NBTEntityData slot = (NBTEntityData) d; try { stream.put(NBTIO.write(slot.getData(), ByteOrder.LITTLE_ENDIAN, true)); } catch (IOException e) { throw new RuntimeException(e); } break; case Entity.DATA_TYPE_POS: IntPositionEntityData pos = (IntPositionEntityData) d; stream.putVarInt(pos.x); stream.putVarInt(pos.y); stream.putVarInt(pos.z); break; case Entity.DATA_TYPE_LONG: stream.putVarLong(((LongEntityData) d).getData()); break; case Entity.DATA_TYPE_VECTOR3F: Vector3fEntityData v3data = (Vector3fEntityData) d; stream.putLFloat(v3data.x); stream.putLFloat(v3data.y); stream.putLFloat(v3data.z); break; } } return stream.getBuffer(); }
Example 6
Source File: Binary.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public static EntityMetadata readMetadata(byte[] payload) { BinaryStream stream = new BinaryStream(); stream.setBuffer(payload); long count = stream.getUnsignedVarInt(); EntityMetadata m = new EntityMetadata(); for (int i = 0; i < count; i++) { int key = (int) stream.getUnsignedVarInt(); int type = (int) stream.getUnsignedVarInt(); EntityData value = null; switch (type) { case Entity.DATA_TYPE_BYTE: value = new ByteEntityData(key, stream.getByte()); break; case Entity.DATA_TYPE_SHORT: value = new ShortEntityData(key, stream.getLShort()); break; case Entity.DATA_TYPE_INT: value = new IntEntityData(key, stream.getVarInt()); break; case Entity.DATA_TYPE_FLOAT: value = new FloatEntityData(key, stream.getLFloat()); break; case Entity.DATA_TYPE_STRING: value = new StringEntityData(key, stream.getString()); break; case Entity.DATA_TYPE_NBT: int offset = stream.getOffset(); FastByteArrayInputStream fbais = new FastByteArrayInputStream(stream.get()); try { CompoundTag tag = NBTIO.read(fbais, ByteOrder.LITTLE_ENDIAN, true); value = new NBTEntityData(key, tag); } catch (IOException e) { throw new RuntimeException(e); } stream.setOffset(offset + (int) fbais.position()); break; case Entity.DATA_TYPE_POS: BlockVector3 v3 = stream.getSignedBlockPosition(); value = new IntPositionEntityData(key, v3.x, v3.y, v3.z); break; case Entity.DATA_TYPE_LONG: value = new LongEntityData(key, stream.getVarLong()); break; case Entity.DATA_TYPE_VECTOR3F: value = new Vector3fEntityData(key, stream.getVector3f()); break; } if (value != null) m.put(value); } return m; }
Example 7
Source File: FloatEntityData.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public int getType() { return Entity.DATA_TYPE_FLOAT; }
Example 8
Source File: Binary.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public static byte[] writeMetadata(EntityMetadata metadata) { BinaryStream stream = new BinaryStream(); Map<Integer, EntityData> map = metadata.getMap(); stream.putUnsignedVarInt(map.size()); for (int id : map.keySet()) { EntityData d = map.get(id); stream.putUnsignedVarInt(id); stream.putUnsignedVarInt(d.getType()); switch (d.getType()) { case Entity.DATA_TYPE_BYTE: stream.putByte(((ByteEntityData) d).getData().byteValue()); break; case Entity.DATA_TYPE_SHORT: stream.putLShort(((ShortEntityData) d).getData()); break; case Entity.DATA_TYPE_INT: stream.putVarInt(((IntEntityData) d).getData()); break; case Entity.DATA_TYPE_FLOAT: stream.putLFloat(((FloatEntityData) d).getData()); break; case Entity.DATA_TYPE_STRING: String s = ((StringEntityData) d).getData(); stream.putUnsignedVarInt(s.getBytes(StandardCharsets.UTF_8).length); stream.put(s.getBytes(StandardCharsets.UTF_8)); break; case Entity.DATA_TYPE_SLOT: SlotEntityData slot = (SlotEntityData) d; stream.putSlot(slot.getData()); break; case Entity.DATA_TYPE_POS: IntPositionEntityData pos = (IntPositionEntityData) d; stream.putVarInt(pos.x); stream.putVarInt(pos.y); stream.putVarInt(pos.z); break; case Entity.DATA_TYPE_LONG: stream.putVarLong(((LongEntityData) d).getData()); break; case Entity.DATA_TYPE_VECTOR3F: Vector3fEntityData v3data = (Vector3fEntityData) d; stream.putLFloat(v3data.x); stream.putLFloat(v3data.y); stream.putLFloat(v3data.z); break; } } return stream.getBuffer(); }
Example 9
Source File: Binary.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public static EntityMetadata readMetadata(byte[] payload) { BinaryStream stream = new BinaryStream(); stream.setBuffer(payload); long count = stream.getUnsignedVarInt(); EntityMetadata m = new EntityMetadata(); for (int i = 0; i < count; i++) { int key = (int) stream.getUnsignedVarInt(); int type = (int) stream.getUnsignedVarInt(); EntityData value = null; switch (type) { case Entity.DATA_TYPE_BYTE: value = new ByteEntityData(key, stream.getByte()); break; case Entity.DATA_TYPE_SHORT: value = new ShortEntityData(key, stream.getLShort()); break; case Entity.DATA_TYPE_INT: value = new IntEntityData(key, stream.getVarInt()); break; case Entity.DATA_TYPE_FLOAT: value = new FloatEntityData(key, stream.getLFloat()); break; case Entity.DATA_TYPE_STRING: value = new StringEntityData(key, stream.getString()); break; case Entity.DATA_TYPE_SLOT: Item item = stream.getSlot(); value = new SlotEntityData(key, item.getId(), item.getDamage(), item.getCount()); break; case Entity.DATA_TYPE_POS: BlockVector3 v3 = stream.getSignedBlockPosition(); value = new IntPositionEntityData(key, v3.x, v3.y, v3.z); break; case Entity.DATA_TYPE_LONG: value = new LongEntityData(key, stream.getVarLong()); break; case Entity.DATA_TYPE_VECTOR3F: value = new Vector3fEntityData(key, stream.getVector3f()); break; } if (value != null) m.put(value); } return m; }