Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Then serialized into bytes (on server)
- @Override
- public void toBytes(ByteBuf buf) {
- // Loop through nutrients and add to buffer
- for (Nutrient nutrient : NutrientList.get()) {
- ByteBufUtils.writeUTF8String(buf, nutrient.name); // Write name as identifier
- buf.writeFloat(serverPlayer.getCapability(CapProvider.NUTRITION_CAPABILITY, null).get(nutrient)); // Write float as value
- }
- }
- // Then deserialized (on the client)
- @Override
- public void fromBytes(ByteBuf buf) {
- // Loop through buffer stream to build nutrition data
- clientNutrients = new HashMap<>();
- while(buf.isReadable()) {
- String identifier = ByteBufUtils.readUTF8String(buf);
- Float value = buf.readFloat();
- clientNutrients.put(NutrientList.getByName(identifier), value);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement