Advertisement
Guest User

Untitled

a guest
Jun 5th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. // Then serialized into bytes (on server)
  2. @Override
  3. public void toBytes(ByteBuf buf) {
  4.     // Loop through nutrients and add to buffer
  5.     for (Nutrient nutrient : NutrientList.get()) {
  6.         ByteBufUtils.writeUTF8String(buf, nutrient.name); // Write name as identifier
  7.         buf.writeFloat(serverPlayer.getCapability(CapProvider.NUTRITION_CAPABILITY, null).get(nutrient)); // Write float as value
  8.     }
  9. }
  10.  
  11. // Then deserialized (on the client)
  12. @Override
  13. public void fromBytes(ByteBuf buf) {
  14.     // Loop through buffer stream to build nutrition data
  15.     clientNutrients = new HashMap<>();
  16.     while(buf.isReadable()) {
  17.         String identifier = ByteBufUtils.readUTF8String(buf);
  18.         Float value = buf.readFloat();
  19.         clientNutrients.put(NutrientList.getByName(identifier), value);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement