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());
}
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();
}
Aggregations