Search in sources :

Example 1 with MinimumUseDurationProperty

use of org.lanternpowered.server.item.property.MinimumUseDurationProperty in project LanternServer by LanternPowered.

the class PlayerInteractionHandler method handleFinishItemInteraction.

public void handleFinishItemInteraction(MessagePlayInOutFinishUsingItem message) {
    final Optional<HandType> activeHand = this.player.get(LanternKeys.ACTIVE_HAND).orElse(Optional.empty());
    // The player is already interacting
    if (!activeHand.isPresent() || this.activeHandStartTime == -1L) {
        return;
    }
    // Try the action of the hotbar item first
    final AbstractSlot slot = activeHand.get() == HandTypes.MAIN_HAND ? this.player.getInventory().getHotbar().getSelectedSlot() : this.player.getInventory().getOffhand();
    final ItemStack rawItemStack = slot.getRawItemStack();
    if (rawItemStack == null) {
        return;
    }
    // Require a minimum amount of ticks for the interaction to succeed
    final MinimumUseDurationProperty property = rawItemStack.getProperty(MinimumUseDurationProperty.class).orElse(null);
    if (property != null) {
        final long time = LanternGame.currentTimeTicks();
        if (time - this.activeHandStartTime < property.getValue()) {
            resetItemUseTime();
            return;
        }
    }
    handleFinishItemInteraction0(slot, activeHand.get());
}
Also used : AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) HandType(org.spongepowered.api.data.type.HandType) MinimumUseDurationProperty(org.lanternpowered.server.item.property.MinimumUseDurationProperty) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 2 with MinimumUseDurationProperty

use of org.lanternpowered.server.item.property.MinimumUseDurationProperty in project LanternServer by LanternPowered.

the class PropertyProviders method useDuration.

public static PropertyProviderCollection useDuration(int minimum, int maximum) {
    final MaximumUseDurationProperty maxProperty = new MaximumUseDurationProperty(maximum);
    final MinimumUseDurationProperty minProperty = new MinimumUseDurationProperty(minimum);
    return PropertyProviderCollection.builder().add(MaximumUseDurationProperty.class, (itemType, itemStack) -> maxProperty).add(MinimumUseDurationProperty.class, (itemType, itemStack) -> minProperty).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) MaximumUseDurationProperty(org.lanternpowered.server.item.property.MaximumUseDurationProperty) MinimumUseDurationProperty(org.lanternpowered.server.item.property.MinimumUseDurationProperty)

Aggregations

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