use of com.nukkitx.protocol.bedrock.data.entity.EntityDataMap in project Protocol by CloudburstMC.
the class BedrockPacketHelper_v361 method writeEntityData.
@Override
public void writeEntityData(ByteBuf buffer, EntityDataMap entityDataMap) {
Preconditions.checkNotNull(buffer, "buffer");
Preconditions.checkNotNull(entityDataMap, "entityDataDictionary");
VarInts.writeUnsignedInt(buffer, entityDataMap.size());
for (Map.Entry<EntityData, Object> entry : entityDataMap.entrySet()) {
int index = buffer.writerIndex();
VarInts.writeUnsignedInt(buffer, this.entityData.get(entry.getKey()));
Object object = entry.getValue();
EntityData.Type type = EntityData.Type.from(object);
VarInts.writeUnsignedInt(buffer, this.entityDataTypes.get(type));
switch(type) {
case BYTE:
buffer.writeByte((byte) object);
break;
case SHORT:
buffer.writeShortLE((short) object);
break;
case INT:
VarInts.writeInt(buffer, (int) object);
break;
case FLOAT:
buffer.writeFloatLE((float) object);
break;
case STRING:
writeString(buffer, (String) object);
break;
case NBT:
NbtMap tag;
if (object instanceof NbtMap) {
tag = (NbtMap) object;
} else {
ItemData item = (ItemData) object;
tag = item.getTag();
if (tag == null) {
tag = NbtMap.EMPTY;
}
}
this.writeTag(buffer, tag);
break;
case VECTOR3I:
writeVector3i(buffer, (Vector3i) object);
break;
case FLAGS:
int flagsIndex = entry.getKey() == EntityData.FLAGS_2 ? 1 : 0;
object = ((EntityFlags) object).get(flagsIndex, this.entityFlags);
case LONG:
VarInts.writeLong(buffer, (long) object);
break;
case VECTOR3F:
writeVector3f(buffer, (Vector3f) object);
break;
default:
buffer.writerIndex(index);
break;
}
}
}
Aggregations