use of riskyken.armourersWorkshop.common.network.messages.client.MessageClientSkinPart in project Armourers-Workshop by RiskyKen.
the class SkinUploadHelper method uploadSkinToServer.
public static void uploadSkinToServer(Skin skin) {
if (!ConfigHandler.allowClientsToUploadSkins) {
return;
}
skin.requestId = new SkinIdentifier(skin);
ModLogger.log("Uploading skin to server: " + skin);
byte[] skinData = ByteBufHelper.convertSkinToByteArray(skin);
ArrayList<MessageClientSkinPart> packetQueue = new ArrayList<MessageClientSkinPart>();
int packetsNeeded = (int) Math.ceil((double) skinData.length / (double) MAX_PACKET_SIZE);
int bytesLeftToSend = skinData.length;
int bytesSent = 0;
for (int i = 0; i < packetsNeeded; i++) {
boolean lastPacket = i == packetsNeeded - 1;
byte[] messageData;
if (lastPacket) {
messageData = new byte[bytesLeftToSend];
} else {
messageData = new byte[MAX_PACKET_SIZE];
}
System.arraycopy(skinData, bytesSent, messageData, 0, messageData.length);
MessageClientSkinPart skinMessage = new MessageClientSkinPart(skin.lightHash(), (byte) i, messageData);
packetQueue.add(skinMessage);
bytesLeftToSend -= messageData.length;
bytesSent += messageData.length;
}
for (int i = 0; i < packetQueue.size(); i++) {
PacketHandler.networkWrapper.sendToServer(packetQueue.get(i));
}
}
Aggregations