Search in sources :

Example 1 with ItemMagnifyingGlass

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;
        }
    }
}
Also used : World(net.minecraft.world.World) ItemMagnifyingGlass(com.infinityraider.agricraft.content.tools.ItemMagnifyingGlass) AbstractClientPlayerEntity(net.minecraft.client.entity.player.AbstractClientPlayerEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

ItemMagnifyingGlass (com.infinityraider.agricraft.content.tools.ItemMagnifyingGlass)1 AbstractClientPlayerEntity (net.minecraft.client.entity.player.AbstractClientPlayerEntity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1