cn.nukkit.entity.data.ShortEntityData Java Examples

The following examples show how to use cn.nukkit.entity.data.ShortEntityData. 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: Entity.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
protected final void init(FullChunk chunk, CompoundTag nbt) {
    if ((chunk == null || chunk.getProvider() == null)) {
        throw new ChunkException("Invalid garbage Chunk given to Entity");
    }

    this.timing = Timings.getEntityTiming(this);

    this.isPlayer = this instanceof Player;
    this.temporalVector = new Vector3();

    this.id = Entity.entityCount++;
    this.justCreated = true;
    this.namedTag = nbt;

    this.chunk = chunk;
    this.setLevel(chunk.getProvider().getLevel());
    this.server = chunk.getProvider().getLevel().getServer();

    this.boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);

    ListTag<DoubleTag> posList = this.namedTag.getList("Pos", DoubleTag.class);
    ListTag<FloatTag> rotationList = this.namedTag.getList("Rotation", FloatTag.class);
    ListTag<DoubleTag> motionList = this.namedTag.getList("Motion", DoubleTag.class);
    this.setPositionAndRotation(
            this.temporalVector.setComponents(
                    posList.get(0).data,
                    posList.get(1).data,
                    posList.get(2).data
            ),
            rotationList.get(0).data,
            rotationList.get(1).data
    );

    this.setMotion(this.temporalVector.setComponents(
            motionList.get(0).data,
            motionList.get(1).data,
            motionList.get(2).data
    ));

    if (!this.namedTag.contains("FallDistance")) {
        this.namedTag.putFloat("FallDistance", 0);
    }
    this.fallDistance = this.namedTag.getFloat("FallDistance");
    this.highestPosition = this.y + this.namedTag.getFloat("FallDistance");

    if (!this.namedTag.contains("Fire") || this.namedTag.getShort("Fire") > 32767) {
        this.namedTag.putShort("Fire", 0);
    }
    this.fireTicks = this.namedTag.getShort("Fire");

    if (!this.namedTag.contains("Air")) {
        this.namedTag.putShort("Air", 300);
    }
    this.setDataProperty(new ShortEntityData(DATA_AIR, this.namedTag.getShort("Air")), false);

    if (!this.namedTag.contains("OnGround")) {
        this.namedTag.putBoolean("OnGround", false);
    }
    this.onGround = this.namedTag.getBoolean("OnGround");

    if (!this.namedTag.contains("Invulnerable")) {
        this.namedTag.putBoolean("Invulnerable", false);
    }
    this.invulnerable = this.namedTag.getBoolean("Invulnerable");

    if (!this.namedTag.contains("Scale")) {
        this.namedTag.putFloat("Scale", 1);
    }
    this.scale = this.namedTag.getFloat("Scale");
    this.setDataProperty(new FloatEntityData(DATA_SCALE, scale), false);

    this.chunk.addEntity(this);
    this.level.addEntity(this);

    this.initEntity();

    this.lastUpdate = this.server.getTick();
    this.server.getPluginManager().callEvent(new EntitySpawnEvent(this));

    this.scheduleUpdate();
}
 
Example #2
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 #3
Source File: EntityLiving.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void setAirTicks(int ticks) {
    this.setDataProperty(new ShortEntityData(DATA_AIR, ticks));
}