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