cn.nukkit.entity.data.StringEntityData Java Examples

The following examples show how to use cn.nukkit.entity.data.StringEntityData. 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: EntityTameable.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void initEntity() {
    super.initEntity();
    if (getDataProperty(DATA_TAMED_FLAG) == null) {
        setDataProperty(new ByteEntityData(DATA_TAMED_FLAG, (byte) 0));
    }

    if (getDataProperty(DATA_OWNER_NAME) == null) {
        setDataProperty(new StringEntityData(DATA_OWNER_NAME, ""));
    }

    String ownerName = "";

    if (namedTag != null) {
        if (namedTag.contains("Owner")) {
            ownerName = namedTag.getString("Owner");
        }

        if (ownerName.length() > 0) {
            this.setOwnerName(ownerName);
            this.setTamed(true);
        }

        this.setSitting(namedTag.getBoolean("Sitting"));
    }
}
 
Example #2
Source File: EntityTameable.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void initEntity() {
    super.initEntity();
    if (getDataProperty(DATA_TAMED_FLAG) == null) {
        setDataProperty(new ByteEntityData(DATA_TAMED_FLAG, (byte) 0));
    }

    if (getDataProperty(DATA_OWNER_NAME) == null) {
        setDataProperty(new StringEntityData(DATA_OWNER_NAME, ""));
    }

    String ownerName = "";

    if (namedTag != null) {
        if (namedTag.contains("Owner")) {
            ownerName = namedTag.getString("Owner");
        }

        if (ownerName.length() > 0) {
            this.setOwnerName(ownerName);
            this.setTamed(true);
        }

        this.setSitting(namedTag.getBoolean("Sitting"));
    }
}
 
Example #3
Source File: EntityTameable.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void initEntity() {
    super.initEntity();
    if (getDataProperty(DATA_TAMED_FLAG) == null) {
        setDataProperty(new ByteEntityData(DATA_TAMED_FLAG, (byte) 0));
    }

    if (getDataProperty(DATA_OWNER_NAME) == null) {
        setDataProperty(new StringEntityData(DATA_OWNER_NAME, ""));
    }

    String ownerName = "";

    if (namedTag != null) {
        if (namedTag.contains("Owner")) {
            ownerName = namedTag.getString("Owner");
        }

        if (ownerName.length() > 0) {
            this.setOwnerName(ownerName);
            this.setTamed(true);
        }

        this.setSitting(namedTag.getBoolean("Sitting"));
    }
}
 
Example #4
Source File: Entity.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public void setNameTag(String name) {
    this.setDataProperty(new StringEntityData(DATA_NAMETAG, name));
}
 
Example #5
Source File: EntityTameable.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setOwnerName(String playerName) {
    setDataProperty(new StringEntityData(DATA_OWNER_NAME, playerName));
}
 
Example #6
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 #7
Source File: EntityTameable.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setOwnerName(String playerName) {
    setDataProperty(new StringEntityData(DATA_OWNER_NAME, playerName));
}
 
Example #8
Source File: EntityTameable.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setOwnerName(String playerName) {
    setDataProperty(new StringEntityData(DATA_OWNER_NAME, playerName));
}