/*
 * This file is part of Sponge, licensed under the MIT License (MIT).
 *
 * Copyright (c) SpongePowered <https://www.spongepowered.org>
 * Copyright (c) contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.spongepowered.common.data.processor.value.entity;

import org.spongepowered.api.data.DataTransactionResult;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.value.ValueContainer;
import org.spongepowered.api.data.value.immutable.ImmutableValue;
import org.spongepowered.api.data.value.mutable.Value;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.EntitySnapshot;
import org.spongepowered.common.data.processor.common.AbstractSpongeValueProcessor;
import org.spongepowered.common.data.util.EntityUtil;
import org.spongepowered.common.data.value.immutable.ImmutableSpongeValue;
import org.spongepowered.common.data.value.immutable.common.ImmutableSpongeEntityValue;
import org.spongepowered.common.data.value.mutable.SpongeValue;
import org.spongepowered.common.data.value.mutable.common.SpongeEntityValue;

import java.util.Optional;

public class VehicleValueProcessor extends AbstractSpongeValueProcessor<net.minecraft.entity.Entity, EntitySnapshot, Value<EntitySnapshot>> {

    public VehicleValueProcessor() {
        super(net.minecraft.entity.Entity.class, Keys.VEHICLE);
    }

    @Override
    public boolean supports(ValueContainer<?> container) {
        return container instanceof net.minecraft.entity.Entity;
    }

    @Override
    public DataTransactionResult removeFrom(ValueContainer<?> container) {
        if (container instanceof net.minecraft.entity.Entity) {
            net.minecraft.entity.Entity entity = ((net.minecraft.entity.Entity) container);
            if (entity.isRiding()) {
                Entity ridingEntity = (Entity) entity.ridingEntity;
                entity.mountEntity(null);
                return DataTransactionResult.successResult(new ImmutableSpongeValue<>(Keys.VEHICLE, ridingEntity.createSnapshot()));
            }
            return DataTransactionResult.builder().result(DataTransactionResult.Type.SUCCESS).build();
        } else {
            return DataTransactionResult.failNoData();
        }
    }

    @Override
    protected Value<EntitySnapshot> constructValue(EntitySnapshot defaultValue) {
        return new SpongeValue<>(this.getKey(), defaultValue);
    }

    @Override
    protected boolean set(net.minecraft.entity.Entity container, EntitySnapshot value) {
        return EntityUtil.setVehicle(container, (net.minecraft.entity.Entity) value);
    }

    @Override
    protected Optional<EntitySnapshot> getVal(net.minecraft.entity.Entity container) {
        Entity entity = (Entity) container.ridingEntity;
        if (entity == null) {
            return Optional.empty();
        } else {
            return Optional.of(entity.createSnapshot());
        }
    }

    @Override
    protected ImmutableValue<EntitySnapshot> constructImmutableValue(EntitySnapshot value) {
        return new ImmutableSpongeValue<>(this.getKey(), value);
    }

}

@@ -3624,24 +3624,47 @@
 ntity) value
+.restore().orElse(null)
 );%0A    %7D%0A%0A  

Fix invalid cast in VehicleValueProcessor