Search in sources :

Example 1 with PotionEffectSerializer

use of org.lanternpowered.server.data.io.store.misc.PotionEffectSerializer in project LanternServer by LanternPowered.

the class EntityStore method serializeValues.

@Override
public void serializeValues(T object, SimpleValueContainer valueContainer, DataView dataView) {
    // Here will we remove all the vanilla properties and delegate the
    // rest through the default serialization system
    valueContainer.remove(Keys.VELOCITY).ifPresent(v -> dataView.set(VELOCITY, toDoubleList(v)));
    valueContainer.remove(Keys.FIRE_TICKS).ifPresent(v -> dataView.set(FIRE_TICKS, v));
    valueContainer.remove(Keys.FALL_DISTANCE).ifPresent(v -> dataView.set(FALL_DISTANCE, v));
    valueContainer.remove(Keys.HEALTH).ifPresent(v -> dataView.set(HEALTH, v.floatValue()));
    valueContainer.remove(Keys.REMAINING_AIR).ifPresent(v -> dataView.set(REMAINING_AIR, v));
    valueContainer.remove(Keys.ABSORPTION).ifPresent(v -> dataView.set(ABSORPTION_AMOUNT, v.floatValue()));
    final DataView spongeView = getOrCreateView(dataView, SPONGE_DATA);
    valueContainer.remove(Keys.MAX_AIR).ifPresent(v -> spongeView.set(MAX_AIR, v));
    valueContainer.remove(Keys.CAN_GRIEF).ifPresent(v -> spongeView.set(CAN_GRIEF, (byte) (v ? 1 : 0)));
    valueContainer.remove(Keys.DISPLAY_NAME).ifPresent(v -> dataView.set(DISPLAY_NAME, LanternTexts.toLegacy(v)));
    valueContainer.remove(Keys.CUSTOM_NAME_VISIBLE).ifPresent(v -> dataView.set(CUSTOM_NAME_VISIBLE, (byte) (v ? 1 : 0)));
    valueContainer.remove(Keys.INVULNERABLE).ifPresent(v -> dataView.set(INVULNERABLE, (byte) (v ? 1 : 0)));
    valueContainer.remove(LanternKeys.PORTAL_COOLDOWN_TICKS).ifPresent(v -> dataView.set(PORTAL_COOLDOWN_TICKS, v));
    valueContainer.remove(Keys.AI_ENABLED).ifPresent(v -> dataView.set(NO_AI, (byte) (v ? 0 : 1)));
    valueContainer.remove(Keys.PERSISTS).ifPresent(v -> dataView.set(PERSISTS, (byte) (v ? 1 : 0)));
    valueContainer.remove(LanternKeys.CAN_PICK_UP_LOOT).ifPresent(v -> dataView.set(CAN_PICK_UP_LOOT, (byte) (v ? 1 : 0)));
    valueContainer.remove(Keys.DISPLAY_NAME).ifPresent(v -> dataView.set(CUSTOM_NAME, LanternTexts.toLegacy(v)));
    valueContainer.remove(Keys.POTION_EFFECTS).ifPresent(v -> {
        if (v.isEmpty()) {
            return;
        }
        // TODO: Allow out impl to use integers as amplifier and use a string as effect id,
        // without breaking the official format
        dataView.set(POTION_EFFECTS, v.stream().map(PotionEffectSerializer::serialize).collect(Collectors.toList()));
    });
    valueContainer.remove(Keys.FOOD_LEVEL).ifPresent(v -> dataView.set(FOOD_LEVEL, v));
    valueContainer.remove(Keys.EXHAUSTION).ifPresent(v -> dataView.set(EXHAUSTION, v.floatValue()));
    valueContainer.remove(Keys.SATURATION).ifPresent(v -> dataView.set(SATURATION, v.floatValue()));
    valueContainer.remove(LanternKeys.IS_ELYTRA_FLYING).ifPresent(v -> dataView.set(IS_ELYTRA_FLYING, (byte) (v ? 1 : 0)));
    valueContainer.remove(Keys.GLOWING).ifPresent(v -> dataView.set(IS_GLOWING, (byte) (v ? 1 : 0)));
    super.serializeValues(object, valueContainer, dataView);
}
Also used : DataView(org.spongepowered.api.data.DataView) PotionEffectSerializer(org.lanternpowered.server.data.io.store.misc.PotionEffectSerializer)

Aggregations

PotionEffectSerializer (org.lanternpowered.server.data.io.store.misc.PotionEffectSerializer)1 DataView (org.spongepowered.api.data.DataView)1