use of com.infinityraider.agricraft.content.tools.ItemMagnifyingGlass in project AgriCraft by AgriCraft.
the class MagnifyingGlassViewHandler method onPlayerTick.
@SuppressWarnings("unused")
@SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true)
public void onPlayerTick(TickEvent.PlayerTickEvent event) {
this.animationCounterPrev = this.animationCounter;
if (this.isActive()) {
// Check if the player is still holding the item and if not, deactivate
if (this.getActiveHand() == null || !(this.getPlayer().getHeldItem(this.getActiveHand()).getItem() instanceof ItemMagnifyingGlass)) {
this.active = false;
this.endInspection();
return;
}
// Increment animation counter
if (this.animationCounter < ANIMATION_DURATION) {
this.animationCounter += 1;
} else {
this.animationCounter = ANIMATION_DURATION;
}
if (this.isAnimationComplete()) {
// Update inspected position
this.checkInspectedPosition();
// Tick inspector
if (this.inspector != null && this.lastTarget != null) {
World world = AgriCraft.instance.getClientWorld();
PlayerEntity player = AgriCraft.instance.getClientPlayer();
if (!this.lastTarget.onInspectionTick(world, this.inspector, player)) {
this.endInspection();
}
}
}
} else {
// Decrement animation counter
if (this.animationCounter > 0) {
this.animationCounter -= 1;
} else {
this.animationCounter = 0;
this.hand = null;
}
}
}
Aggregations