Search in sources :

Example 1 with ApplicableEffectProperty

use of org.spongepowered.api.data.property.item.ApplicableEffectProperty in project LanternServer by LanternPowered.

the class PropertyProviders method applicableEffects.

public static PropertyProviderCollection applicableEffects(PotionEffect... potionEffects) {
    checkNotNull(potionEffects, "potionEffects");
    final ApplicableEffectProperty property = new ApplicableEffectProperty(ImmutableSet.copyOf(potionEffects));
    return PropertyProviderCollection.builder().add(ApplicableEffectProperty.class, (itemType, itemStack) -> property).build();
}
Also used : ArmorTypeProperty(org.spongepowered.api.data.property.item.ArmorTypeProperty) ApplicableEffectProperty(org.spongepowered.api.data.property.item.ApplicableEffectProperty) ImmutableSet(com.google.common.collect.ImmutableSet) ToolTypeProperty(org.spongepowered.api.data.property.item.ToolTypeProperty) MaximumUseDurationProperty(org.lanternpowered.server.item.property.MaximumUseDurationProperty) EquipmentType(org.spongepowered.api.item.inventory.equipment.EquipmentType) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) RecordProperty(org.spongepowered.api.data.property.item.RecordProperty) HealthRestorationProperty(org.lanternpowered.server.item.property.HealthRestorationProperty) MinimumUseDurationProperty(org.lanternpowered.server.item.property.MinimumUseDurationProperty) ArmorType(org.spongepowered.api.data.type.ArmorType) EquipmentProperty(org.spongepowered.api.data.property.item.EquipmentProperty) DualWieldProperty(org.lanternpowered.server.item.property.DualWieldProperty) FoodRestorationProperty(org.spongepowered.api.data.property.item.FoodRestorationProperty) SaturationProperty(org.spongepowered.api.data.property.item.SaturationProperty) UseLimitProperty(org.spongepowered.api.data.property.item.UseLimitProperty) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) RecordType(org.spongepowered.api.effect.sound.record.RecordType) AlwaysConsumableProperty(org.lanternpowered.server.item.property.AlwaysConsumableProperty) CooldownProperty(org.lanternpowered.server.item.property.CooldownProperty) ToolType(org.spongepowered.api.data.type.ToolType) ApplicableEffectProperty(org.spongepowered.api.data.property.item.ApplicableEffectProperty)

Example 2 with ApplicableEffectProperty

use of org.spongepowered.api.data.property.item.ApplicableEffectProperty in project LanternServer by LanternPowered.

the class PropertyProviders method applicableEffects.

public static PropertyProviderCollection applicableEffects(Collection<PotionEffect> potionEffects) {
    checkNotNull(potionEffects, "potionEffects");
    final ApplicableEffectProperty property = new ApplicableEffectProperty(ImmutableSet.copyOf(potionEffects));
    return PropertyProviderCollection.builder().add(ApplicableEffectProperty.class, (itemType, itemStack) -> property).build();
}
Also used : ArmorTypeProperty(org.spongepowered.api.data.property.item.ArmorTypeProperty) ApplicableEffectProperty(org.spongepowered.api.data.property.item.ApplicableEffectProperty) ImmutableSet(com.google.common.collect.ImmutableSet) ToolTypeProperty(org.spongepowered.api.data.property.item.ToolTypeProperty) MaximumUseDurationProperty(org.lanternpowered.server.item.property.MaximumUseDurationProperty) EquipmentType(org.spongepowered.api.item.inventory.equipment.EquipmentType) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) RecordProperty(org.spongepowered.api.data.property.item.RecordProperty) HealthRestorationProperty(org.lanternpowered.server.item.property.HealthRestorationProperty) MinimumUseDurationProperty(org.lanternpowered.server.item.property.MinimumUseDurationProperty) ArmorType(org.spongepowered.api.data.type.ArmorType) EquipmentProperty(org.spongepowered.api.data.property.item.EquipmentProperty) DualWieldProperty(org.lanternpowered.server.item.property.DualWieldProperty) FoodRestorationProperty(org.spongepowered.api.data.property.item.FoodRestorationProperty) SaturationProperty(org.spongepowered.api.data.property.item.SaturationProperty) UseLimitProperty(org.spongepowered.api.data.property.item.UseLimitProperty) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) RecordType(org.spongepowered.api.effect.sound.record.RecordType) AlwaysConsumableProperty(org.lanternpowered.server.item.property.AlwaysConsumableProperty) CooldownProperty(org.lanternpowered.server.item.property.CooldownProperty) ToolType(org.spongepowered.api.data.type.ToolType) ApplicableEffectProperty(org.spongepowered.api.data.property.item.ApplicableEffectProperty)

Example 3 with ApplicableEffectProperty

use of org.spongepowered.api.data.property.item.ApplicableEffectProperty in project LanternServer by LanternPowered.

the class ConsumableInteractionBehavior method tryUse.

@Override
public BehaviorResult tryUse(BehaviorPipeline<Behavior> pipeline, BehaviorContext context) {
    final Optional<Player> optPlayer = context.getContext(ContextKeys.PLAYER);
    if (optPlayer.isPresent()) {
        final Player player = optPlayer.get();
        final ItemStack itemStack = context.requireContext(ContextKeys.USED_ITEM_STACK);
        final FoodRestorationProperty foodRestorationProperty = itemStack.getProperty(FoodRestorationProperty.class).orElse(null);
        if (foodRestorationProperty != null && foodRestorationProperty.getValue() != 0.0) {
            final Optional<Integer> maxFood = player.get(LanternKeys.MAX_FOOD_LEVEL);
            final Optional<Integer> optFoodLevel = player.get(Keys.FOOD_LEVEL);
            if (optFoodLevel.isPresent()) {
                player.offer(Keys.FOOD_LEVEL, Math.min(optFoodLevel.get() + foodRestorationProperty.getValue(), maxFood.orElse(Integer.MAX_VALUE)));
            }
        }
        final HealthRestorationProperty healthRestorationProperty = itemStack.getProperty(HealthRestorationProperty.class).orElse(null);
        if (healthRestorationProperty != null && healthRestorationProperty.getValue() != 0.0) {
            final Optional<Double> maxHealth = player.get(Keys.MAX_HEALTH);
            final Optional<Double> optHealth = player.get(Keys.HEALTH);
            if (optHealth.isPresent()) {
                player.offer(Keys.HEALTH, Math.min(optHealth.get() + healthRestorationProperty.getValue(), maxHealth.orElse(Double.MAX_VALUE)));
            }
        }
        final SaturationProperty saturationProperty = itemStack.getProperty(SaturationProperty.class).orElse(null);
        if (saturationProperty != null && saturationProperty.getValue() != 0.0) {
            final Optional<Double> optSaturation = player.get(Keys.SATURATION);
            if (optSaturation.isPresent()) {
                player.offer(Keys.SATURATION, Math.min(optSaturation.get() + saturationProperty.getValue(), player.get(Keys.FOOD_LEVEL).orElse(20)));
            }
        }
        final ApplicableEffectProperty applicableEffectProperty = itemStack.getProperty(ApplicableEffectProperty.class).orElse(null);
        if (applicableEffectProperty != null && !applicableEffectProperty.getValue().isEmpty()) {
            final List<PotionEffect> potionEffects = player.get(Keys.POTION_EFFECTS).orElse(Collections.emptyList());
            player.offer(Keys.POTION_EFFECTS, PotionEffectHelper.merge(potionEffects, applicableEffectProperty.getValue()));
        }
        if (this.consumer != null) {
            this.consumer.apply(player, pipeline, context);
        }
        if (!player.get(Keys.GAME_MODE).orElse(GameModes.NOT_SET).equals(GameModes.CREATIVE)) {
            final Slot slot = context.requireContext(ContextKeys.USED_SLOT);
            slot.poll(1);
            if (this.restItemSupplier != null) {
                if (slot.peek().isPresent()) {
                    ((LanternPlayer) player).getInventory().getMain().offer(this.restItemSupplier.get());
                } else {
                    slot.set(this.restItemSupplier.get());
                }
            }
        }
        return BehaviorResult.SUCCESS;
    }
    return BehaviorResult.PASS;
}
Also used : SaturationProperty(org.spongepowered.api.data.property.item.SaturationProperty) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer) Player(org.spongepowered.api.entity.living.player.Player) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) FoodRestorationProperty(org.spongepowered.api.data.property.item.FoodRestorationProperty) HealthRestorationProperty(org.lanternpowered.server.item.property.HealthRestorationProperty) Slot(org.spongepowered.api.item.inventory.Slot) ApplicableEffectProperty(org.spongepowered.api.data.property.item.ApplicableEffectProperty) ItemStack(org.spongepowered.api.item.inventory.ItemStack) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Aggregations

HealthRestorationProperty (org.lanternpowered.server.item.property.HealthRestorationProperty)3 ApplicableEffectProperty (org.spongepowered.api.data.property.item.ApplicableEffectProperty)3 FoodRestorationProperty (org.spongepowered.api.data.property.item.FoodRestorationProperty)3 SaturationProperty (org.spongepowered.api.data.property.item.SaturationProperty)3 PotionEffect (org.spongepowered.api.effect.potion.PotionEffect)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Collection (java.util.Collection)2 AlwaysConsumableProperty (org.lanternpowered.server.item.property.AlwaysConsumableProperty)2 CooldownProperty (org.lanternpowered.server.item.property.CooldownProperty)2 DualWieldProperty (org.lanternpowered.server.item.property.DualWieldProperty)2 MaximumUseDurationProperty (org.lanternpowered.server.item.property.MaximumUseDurationProperty)2 MinimumUseDurationProperty (org.lanternpowered.server.item.property.MinimumUseDurationProperty)2 ArmorTypeProperty (org.spongepowered.api.data.property.item.ArmorTypeProperty)2 EquipmentProperty (org.spongepowered.api.data.property.item.EquipmentProperty)2 RecordProperty (org.spongepowered.api.data.property.item.RecordProperty)2 ToolTypeProperty (org.spongepowered.api.data.property.item.ToolTypeProperty)2 UseLimitProperty (org.spongepowered.api.data.property.item.UseLimitProperty)2 ArmorType (org.spongepowered.api.data.type.ArmorType)2 ToolType (org.spongepowered.api.data.type.ToolType)2