Example usage for net.minecraftforge.event.entity.player ItemFishedEvent ItemFishedEvent

List of usage examples for net.minecraftforge.event.entity.player ItemFishedEvent ItemFishedEvent

Introduction

In this page you can find the example usage for net.minecraftforge.event.entity.player ItemFishedEvent ItemFishedEvent.

Prototype

public ItemFishedEvent(List<ItemStack> stacks, int rodDamage, FishingBobberEntity hook) 

Source Link

Usage

From source file:nightkosh.gravestone_extended.entity.projectile.EntityCustomFishHook.java

License:LGPL

@Override
public int handleHookRetraction() {
    if (!this.world.isRemote && this.getAngler() != null) {
        int i = 0;

        net.minecraftforge.event.entity.player.ItemFishedEvent event = null;
        if (this.caughtEntity != null) {
            this.bringInHookedEntity();
            this.world.setEntityState(this, (byte) 31);
            i = this.caughtEntity instanceof EntityItem ? 3 : 5;
        } else if (this.ticksCatchable > 0) {
            List<ItemStack> result = this.getCatch();
            event = new ItemFishedEvent(result, this.inGround ? 2 : 1, this);
            MinecraftForge.EVENT_BUS.post(event);

            if (event.isCanceled()) {
                this.setDead();
                return event.getRodDamage();
            }/*from   w  w w  .  j  av a 2s .  c om*/

            for (ItemStack stack : result) {
                EntityItem entityitem = getCatchEntityItem(stack);
                double d0 = this.getAngler().posX - this.posX;
                double d1 = this.getAngler().posY - this.posY;
                double d2 = this.getAngler().posZ - this.posZ;
                double d3 = MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);

                entityitem.motionX = d0 * 0.1;
                entityitem.motionY = d1 * 0.1 + MathHelper.sqrt(d3) * 0.08;
                entityitem.motionZ = d2 * 0.1;
                this.world.spawnEntity(entityitem);
                this.getAngler().world.spawnEntity(new EntityXPOrb(this.getAngler().world,
                        this.getAngler().posX, this.getAngler().posY + 0.5, this.getAngler().posZ + 0.5,
                        this.rand.nextInt(6) + 1));
                Item item = stack.getItem();

                if (item == Items.FISH || item == Items.COOKED_FISH) {
                    this.getAngler().addStat(StatList.FISH_CAUGHT, 1);
                }
            }

            i = 1;
        }

        if (this.inGround) {
            i = 2;
        }

        this.setDead();
        return event == null ? i : event.getRodDamage();
    } else {
        return 0;
    }
}