Search in sources :

Example 1 with MaximumUseDurationProperty

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

the class PlayerInteractionHandler method pulse.

/**
 * Pulses the interaction handler.
 */
void pulse() {
    if (this.diggingBlock != null) {
        final int breakState = (int) Math.round(((double) Math.max(0, this.diggingEndTime - System.nanoTime()) / (double) this.diggingDuration) * 10.0);
        if (this.lastBreakState != breakState) {
            sendBreakUpdate(breakState);
            this.lastBreakState = breakState;
        }
    }
    final HandType activeHand = this.player.get(LanternKeys.ACTIVE_HAND).orElse(Optional.empty()).orElse(null);
    final AbstractSlot slot = activeHand == null ? null : activeHand == HandTypes.MAIN_HAND ? this.player.getInventory().getHotbar().getSelectedSlot() : this.player.getInventory().getOffhand();
    // The interaction just started
    if (!Objects.equals(activeHand, this.lastActiveHand)) {
        this.lastActiveHand = activeHand;
        this.lastActiveItemStack = slot == null ? null : slot.getRawItemStack();
    } else if (activeHand != null) {
        if (this.activeHandStartTime == -1L) {
            this.activeHandStartTime = LanternGame.currentTimeTicks();
        }
        final ItemStack itemStack = slot.getRawItemStack();
        if (itemStack == null || this.lastActiveItemStack != itemStack) {
            // Stop the interaction
            resetItemUseTime();
        } else {
            final MaximumUseDurationProperty property = itemStack.getProperty(MaximumUseDurationProperty.class).orElse(null);
            if (property != null) {
                // Check if the interaction reached it's max time
                final long time = LanternGame.currentTimeTicks();
                if (time - this.activeHandStartTime > property.getValue()) {
                    handleFinishItemInteraction0(slot, activeHand);
                }
            }
        }
    }
}
Also used : MaximumUseDurationProperty(org.lanternpowered.server.item.property.MaximumUseDurationProperty) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) HandType(org.spongepowered.api.data.type.HandType) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 2 with MaximumUseDurationProperty

use of org.lanternpowered.server.item.property.MaximumUseDurationProperty 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

MaximumUseDurationProperty (org.lanternpowered.server.item.property.MaximumUseDurationProperty)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 MinimumUseDurationProperty (org.lanternpowered.server.item.property.MinimumUseDurationProperty)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