cn.nukkit.entity.data.EntityMetadata Java Examples

The following examples show how to use cn.nukkit.entity.data.EntityMetadata. 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: EntityXPOrb.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void spawnTo(Player player) {
    AddEntityPacket packet = new AddEntityPacket();
    packet.type = getNetworkId();
    packet.entityUniqueId = this.getId();
    packet.entityRuntimeId = getId();
    packet.x = (float) this.x;
    packet.y = (float) this.y;
    packet.z = (float) this.z;
    packet.speedX = (float) this.motionX;
    packet.speedY = (float) this.motionY;
    packet.speedZ = (float) this.motionZ;
    packet.metadata = new EntityMetadata();
    player.dataPacket(packet);
    //this.sendData(player);

    super.spawnTo(player);
}
 
Example #2
Source File: DummyBossBar.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
private void createBossEntity() {
    AddEntityPacket pkAdd = new AddEntityPacket();
    pkAdd.type = EntityCreeper.NETWORK_ID;
    pkAdd.entityUniqueId = bossBarId;
    pkAdd.entityRuntimeId = bossBarId;
    pkAdd.x = (float) player.x;
    pkAdd.y = (float) -10; // Below the bedrock
    pkAdd.z = (float) player.z;
    pkAdd.speedX = 0;
    pkAdd.speedY = 0;
    pkAdd.speedZ = 0;
    pkAdd.metadata = new EntityMetadata()
            // Default Metadata tags
            .putLong(Entity.DATA_FLAGS, 0)
            .putShort(Entity.DATA_AIR, 400)
            .putShort(Entity.DATA_MAX_AIR, 400)
            .putLong(Entity.DATA_LEAD_HOLDER_EID, -1)
            .putString(Entity.DATA_NAMETAG, text) // Set the entity name
            .putFloat(Entity.DATA_SCALE, 0); // And make it invisible

    player.dataPacket(pkAdd);
}
 
Example #3
Source File: EntityXPOrb.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void spawnTo(Player player) {
    AddEntityPacket packet = new AddEntityPacket();
    packet.type = getNetworkId();
    packet.entityUniqueId = this.getId();
    packet.entityRuntimeId = getId();
    packet.x = (float) this.x;
    packet.y = (float) this.y;
    packet.z = (float) this.z;
    packet.speedX = (float) this.motionX;
    packet.speedY = (float) this.motionY;
    packet.speedZ = (float) this.motionZ;
    packet.metadata = new EntityMetadata();
    player.dataPacket(packet);
    //this.sendData(player);

    super.spawnTo(player);
}
 
Example #4
Source File: DummyBossBar.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
private void createBossEntity() {
    AddEntityPacket pkAdd = new AddEntityPacket();
    pkAdd.type = EntityCreeper.NETWORK_ID;
    pkAdd.entityUniqueId = bossBarId;
    pkAdd.entityRuntimeId = bossBarId;
    pkAdd.x = (float) player.x;
    pkAdd.y = (float) -10; // Below the bedrock
    pkAdd.z = (float) player.z;
    pkAdd.speedX = 0;
    pkAdd.speedY = 0;
    pkAdd.speedZ = 0;
    pkAdd.metadata = new EntityMetadata()
            // Default Metadata tags
            .putLong(Entity.DATA_FLAGS, 0)
            .putShort(Entity.DATA_AIR, 400)
            .putShort(Entity.DATA_MAX_AIR, 400)
            .putLong(Entity.DATA_LEAD_HOLDER_EID, -1)
            .putString(Entity.DATA_NAMETAG, text) // Set the entity name
            .putFloat(Entity.DATA_SCALE, 0); // And make it invisible

    player.dataPacket(pkAdd);
}
 
Example #5
Source File: Entity.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void sendData(Player player, EntityMetadata data) {
    SetEntityDataPacket pk = new SetEntityDataPacket();
    pk.entityRuntimeId = this.getId();
    pk.metadata = data == null ? this.dataProperties : data;

    player.dataPacket(pk);
}
 
Example #6
Source File: Entity.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void sendData(Player[] players, EntityMetadata data) {
    SetEntityDataPacket pk = new SetEntityDataPacket();
    pk.entityRuntimeId = this.getId();
    pk.metadata = data == null ? this.dataProperties : data;

    for (Player player : players) {
        if (player == this) {
            continue;
        }
        player.dataPacket(pk.clone());
    }
    if (this instanceof Player) {
        ((Player) this).dataPacket(pk);
    }
}
 
Example #7
Source File: Entity.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public boolean setDataProperty(EntityData data, boolean send) {
    if (!Objects.equals(data, this.getDataProperties().get(data.getId()))) {
        this.getDataProperties().put(data);
        if (send)
            this.sendData(this.hasSpawned.values().stream().toArray(Player[]::new), new EntityMetadata().put(this.dataProperties.get(data.getId())));
        return true;
    }
    return false;
}
 
Example #8
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 #9
Source File: DataPacketEidReplacer.java    From SynapseAPI with GNU General Public License v3.0 5 votes vote down vote up
private static EntityMetadata cloneMetadata(EntityMetadata data) {
    EntityMetadata newData = new EntityMetadata();

    for (EntityData value : data.getMap().values()) {
        newData.put(value);
    }

    return newData;
}
 
Example #10
Source File: Entity.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public EntityMetadata getDataProperties() {
    return this.dataProperties;
}
 
Example #11
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();
}
 
Example #12
Source File: DummyBossBar.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
private void updateBossEntityNameTag() {
    SetEntityDataPacket pk = new SetEntityDataPacket();
    pk.eid = this.bossBarId;
    pk.metadata = new EntityMetadata().putString(Entity.DATA_NAMETAG, this.text);
    player.dataPacket(pk);
}
 
Example #13
Source File: DummyBossBar.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
private void updateBossEntityNameTag() {
    SetEntityDataPacket pk = new SetEntityDataPacket();
    pk.eid = this.bossBarId;
    pk.metadata = new EntityMetadata().putString(Entity.DATA_NAMETAG, this.text);
    player.dataPacket(pk);
}