cn.nukkit.entity.data.LongEntityData Java Examples

The following examples show how to use cn.nukkit.entity.data.LongEntityData. 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: EntityProjectile.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public EntityProjectile(FullChunk chunk, CompoundTag nbt, Entity shootingEntity) {
    super(chunk, nbt);
    this.shootingEntity = shootingEntity;
    if (shootingEntity != null) {
        this.setDataProperty(new LongEntityData(DATA_SHOOTER_ID, shootingEntity.getId()));
    }
}
 
Example #2
Source File: EntityProjectile.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public EntityProjectile(FullChunk chunk, CompoundTag nbt, Entity shootingEntity) {
    super(chunk, nbt);
    this.shootingEntity = shootingEntity;
    if (shootingEntity != null) {
        this.setDataProperty(new LongEntityData(DATA_SHOOTER_ID, shootingEntity.getId()));
    }
}
 
Example #3
Source File: DataPacketEidReplacer.java    From SynapseAPI with GNU General Public License v3.0 5 votes vote down vote up
private static EntityMetadata replaceMetadata(EntityMetadata data, long from, long to) {
    boolean changed = false;

    for (Integer key : replaceMetadata) {
        try {
            EntityData ed = data.get(key);

            if (ed == null) {
                continue;
            }

            if (ed.getType() != Entity.DATA_TYPE_LONG) {
                MainLogger.getLogger().info("Wrong entity data type (" + key + ") expected 'Long' got '" + dataTypeToString(ed.getType()) + "'");
                continue;
            }

            long value = ((LongEntityData) ed).getData();

            if (value == from) {
                if (!changed) {
                    data = cloneMetadata(data);
                    changed = true;
                }

                data.putLong(key, to);
            }
        } catch (Exception e) {
            MainLogger.getLogger().error("Exception while replacing metadata '" + key + "'", e);
        }
    }

    if (!changed) return null;

    return data;
}
 
Example #4
Source File: EntityProjectile.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public EntityProjectile(FullChunk chunk, CompoundTag nbt, Entity shootingEntity) {
    super(chunk, nbt);
    this.shootingEntity = shootingEntity;
    if (shootingEntity != null) {
        this.setDataProperty(new LongEntityData(DATA_SHOOTER_ID, shootingEntity.getId()));
    }
}
 
Example #5
Source File: Binary.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
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();
}