Search in sources :

Example 1 with ArrowAccessor

use of org.spongepowered.common.accessor.world.entity.projectile.ArrowAccessor in project SpongeCommon by SpongePowered.

the class ArrowData method register.

// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
    registrator.asMutable(Arrow.class).create(Keys.POTION_EFFECTS).get(h -> {
        final Set<MobEffectInstance> effects = ((ArrowAccessor) h).accessor$effects();
        return effects.stream().map(effect -> (PotionEffect) new MobEffectInstance(effect.getEffect(), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.isVisible())).collect(Collectors.toList());
    }).set((h, v) -> {
        ((ArrowAccessor) h).accessor$effects().clear();
        for (final PotionEffect effect : v) {
            final MobEffectInstance mcEffect = new MobEffectInstance(((MobEffectInstance) effect).getEffect(), (int) effect.duration().ticks(), effect.amplifier(), effect.isAmbient(), effect.showsParticles());
            h.addEffect(mcEffect);
        }
    });
}
Also used : Arrow(net.minecraft.world.entity.projectile.Arrow) Keys(org.spongepowered.api.data.Keys) Arrow(net.minecraft.world.entity.projectile.Arrow) DataProviderRegistrator(org.spongepowered.common.data.provider.DataProviderRegistrator) Set(java.util.Set) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) ArrowAccessor(org.spongepowered.common.accessor.world.entity.projectile.ArrowAccessor) Collectors(java.util.stream.Collectors) Set(java.util.Set) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance)

Aggregations

Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 MobEffectInstance (net.minecraft.world.effect.MobEffectInstance)1 Arrow (net.minecraft.world.entity.projectile.Arrow)1 Keys (org.spongepowered.api.data.Keys)1 PotionEffect (org.spongepowered.api.effect.potion.PotionEffect)1 ArrowAccessor (org.spongepowered.common.accessor.world.entity.projectile.ArrowAccessor)1 DataProviderRegistrator (org.spongepowered.common.data.provider.DataProviderRegistrator)1