Search in sources :

Example 1 with Fish

use of org.bukkit.entity.Fish in project Mohist by MohistMC.

the class CraftEventFactory method callPlayerFishBucketEvent.

/**
 * Player Fish Bucket Event
 */
public static PlayerBucketEntityEvent callPlayerFishBucketEvent(LivingEntity fish, net.minecraft.world.entity.player.Player entityHuman, ItemStack originalBucket, ItemStack entityBucket) {
    Player player = (Player) entityHuman.getBukkitEntity();
    PlayerBucketEntityEvent event;
    if (fish instanceof AbstractFish) {
        event = new PlayerBucketFishEvent(player, (Fish) fish.getBukkitEntity(), CraftItemStack.asBukkitCopy(originalBucket), CraftItemStack.asBukkitCopy(entityBucket));
    } else {
        event = new PlayerBucketEntityEvent(player, fish.getBukkitEntity(), CraftItemStack.asBukkitCopy(originalBucket), CraftItemStack.asBukkitCopy(entityBucket));
    }
    Bukkit.getPluginManager().callEvent(event);
    return event;
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer) Player(org.bukkit.entity.Player) PlayerBucketFishEvent(org.bukkit.event.player.PlayerBucketFishEvent) AbstractFish(net.minecraft.world.entity.animal.AbstractFish) AbstractFish(net.minecraft.world.entity.animal.AbstractFish) Fish(org.bukkit.entity.Fish) PlayerBucketEntityEvent(org.bukkit.event.player.PlayerBucketEntityEvent)

Example 2 with Fish

use of org.bukkit.entity.Fish in project CumServerPro by MCUmbrella.

the class EntityFishHook method catchingFish.

private void catchingFish(BlockPos p_190621_1_) {
    WorldServer worldserver = (WorldServer) this.world;
    int i = 1;
    BlockPos blockpos = p_190621_1_.up();
    if (this.rand.nextFloat() < 0.25F && this.world.isRainingAt(blockpos)) {
        ++i;
    }
    if (this.rand.nextFloat() < 0.5F && !this.world.canSeeSky(blockpos)) {
        --i;
    }
    if (this.ticksCatchable > 0) {
        --this.ticksCatchable;
        if (this.ticksCatchable <= 0) {
            this.ticksCaughtDelay = 0;
            this.ticksCatchableDelay = 0;
            PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.angler.getBukkitEntity(), null, (Fish) this.getBukkitEntity(), PlayerFishEvent.State.FAILED_ATTEMPT);
            this.world.getServer().getPluginManager().callEvent(playerFishEvent);
        } else {
            this.motionY -= 0.2D * (double) this.rand.nextFloat() * (double) this.rand.nextFloat();
        }
    } else if (this.ticksCatchableDelay > 0) {
        this.ticksCatchableDelay -= i;
        if (this.ticksCatchableDelay > 0) {
            this.fishApproachAngle = (float) ((double) this.fishApproachAngle + this.rand.nextGaussian() * 4.0D);
            float f = this.fishApproachAngle * 0.017453292F;
            float f1 = MathHelper.sin(f);
            float f2 = MathHelper.cos(f);
            double d0 = this.posX + (double) (f1 * (float) this.ticksCatchableDelay * 0.1F);
            double d1 = (double) ((float) MathHelper.floor(this.getEntityBoundingBox().minY) + 1.0F);
            double d2 = this.posZ + (double) (f2 * (float) this.ticksCatchableDelay * 0.1F);
            IBlockState state = worldserver.getBlockState(new BlockPos(d0, d1 - 1.0D, d2));
            if (state.getMaterial() == Material.WATER) {
                if (this.rand.nextFloat() < 0.15F) {
                    worldserver.spawnParticle(EnumParticleTypes.WATER_BUBBLE, d0, d1 - 0.10000000149011612D, d2, 1, (double) f1, 0.1D, (double) f2, 0.0D);
                }
                float f3 = f1 * 0.04F;
                float f4 = f2 * 0.04F;
                worldserver.spawnParticle(EnumParticleTypes.WATER_WAKE, d0, d1, d2, 0, (double) f4, 0.01D, (double) (-f3), 1.0D);
                worldserver.spawnParticle(EnumParticleTypes.WATER_WAKE, d0, d1, d2, 0, (double) (-f4), 0.01D, (double) f3, 1.0D);
            }
        } else {
            PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.angler.getBukkitEntity(), null, (Fish) this.getBukkitEntity(), PlayerFishEvent.State.BITE);
            this.world.getServer().getPluginManager().callEvent(playerFishEvent);
            if (playerFishEvent.isCancelled()) {
                return;
            }
            this.motionY = (double) (-0.4F * MathHelper.nextFloat(this.rand, 0.6F, 1.0F));
            this.playSound(SoundEvents.ENTITY_BOBBER_SPLASH, 0.25F, 1.0F + (this.rand.nextFloat() - this.rand.nextFloat()) * 0.4F);
            double d3 = this.getEntityBoundingBox().minY + 0.5D;
            worldserver.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX, d3, this.posZ, (int) (1.0F + this.width * 20.0F), (double) this.width, 0.0D, (double) this.width, 0.20000000298023224D);
            worldserver.spawnParticle(EnumParticleTypes.WATER_WAKE, this.posX, d3, this.posZ, (int) (1.0F + this.width * 20.0F), (double) this.width, 0.0D, (double) this.width, 0.20000000298023224D);
            this.ticksCatchable = MathHelper.getInt(this.rand, 20, 40);
        }
    } else if (this.ticksCaughtDelay > 0) {
        this.ticksCaughtDelay -= i;
        float f5 = 0.15F;
        if (this.ticksCaughtDelay < 20) {
            f5 = (float) ((double) f5 + (double) (20 - this.ticksCaughtDelay) * 0.05D);
        } else if (this.ticksCaughtDelay < 40) {
            f5 = (float) ((double) f5 + (double) (40 - this.ticksCaughtDelay) * 0.02D);
        } else if (this.ticksCaughtDelay < 60) {
            f5 = (float) ((double) f5 + (double) (60 - this.ticksCaughtDelay) * 0.01D);
        }
        if (this.rand.nextFloat() < f5) {
            float f6 = MathHelper.nextFloat(this.rand, 0.0F, 360.0F) * 0.017453292F;
            float f7 = MathHelper.nextFloat(this.rand, 25.0F, 60.0F);
            double d4 = this.posX + (double) (MathHelper.sin(f6) * f7 * 0.1F);
            double d5 = (double) ((float) MathHelper.floor(this.getEntityBoundingBox().minY) + 1.0F);
            double d6 = this.posZ + (double) (MathHelper.cos(f6) * f7 * 0.1F);
            IBlockState state = worldserver.getBlockState(new BlockPos((int) d4, (int) d5 - 1, (int) d6));
            if (state.getMaterial() == Material.WATER) {
                worldserver.spawnParticle(EnumParticleTypes.WATER_SPLASH, d4, d5, d6, 2 + this.rand.nextInt(2), 0.10000000149011612D, 0.0D, 0.10000000149011612D, 0.0D);
            }
        }
        if (this.ticksCaughtDelay <= 0) {
            this.fishApproachAngle = MathHelper.nextFloat(this.rand, 0.0F, 360.0F);
            this.ticksCatchableDelay = MathHelper.getInt(this.rand, 20, 80);
        }
    } else {
        this.ticksCaughtDelay = MathHelper.getInt(this.rand, 100, 600);
        this.ticksCaughtDelay -= this.lureSpeed * 20 * 5;
    }
}
Also used : Player(org.bukkit.entity.Player) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IBlockState(net.minecraft.block.state.IBlockState) PlayerFishEvent(org.bukkit.event.player.PlayerFishEvent) Fish(org.bukkit.entity.Fish) WorldServer(net.minecraft.world.WorldServer) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with Fish

use of org.bukkit.entity.Fish in project CumServerPro by MCUmbrella.

the class EntityFishHook method handleHookRetraction.

public int handleHookRetraction() {
    if (!this.world.isRemote && this.angler != null) {
        int i = 0;
        net.minecraftforge.event.entity.player.ItemFishedEvent event = null;
        if (this.caughtEntity != null) {
            PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.angler.getBukkitEntity(), this.caughtEntity.getBukkitEntity(), (Fish) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_ENTITY);
            this.world.getServer().getPluginManager().callEvent(playerFishEvent);
            if (playerFishEvent.isCancelled()) {
                return 0;
            }
            this.bringInHookedEntity();
            this.world.setEntityState(this, (byte) 31);
            i = this.caughtEntity instanceof EntityItem ? 3 : 5;
        } else if (this.ticksCatchable > 0) {
            LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer) this.world);
            // Forge: add player & looted entity to LootContext
            lootcontext$builder.withLuck((float) this.luck + this.angler.getLuck()).withPlayer(this.angler).withLootedEntity(this);
            List<ItemStack> result = this.world.getLootTableManager().getLootTableFromLocation(LootTableList.GAMEPLAY_FISHING).generateLootForPools(this.rand, lootcontext$builder.build());
            event = new net.minecraftforge.event.entity.player.ItemFishedEvent(result, this.inGround ? 2 : 1, this);
            net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event);
            if (event.isCanceled()) {
                this.setDead();
                return event.getRodDamage();
            }
            for (ItemStack itemstack : result) {
                EntityItem entityitem = new EntityItem(this.world, this.posX, this.posY, this.posZ, itemstack);
                PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.angler.getBukkitEntity(), entityitem.getBukkitEntity(), (Fish) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_FISH);
                playerFishEvent.setExpToDrop(this.rand.nextInt(6) + 1);
                this.world.getServer().getPluginManager().callEvent(playerFishEvent);
                if (playerFishEvent.isCancelled()) {
                    return 0;
                }
                double d0 = this.angler.posX - this.posX;
                double d1 = this.angler.posY - this.posY;
                double d2 = this.angler.posZ - this.posZ;
                double d3 = (double) MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
                double d4 = 0.1D;
                entityitem.motionX = d0 * 0.1D;
                entityitem.motionY = d1 * 0.1D + (double) MathHelper.sqrt(d3) * 0.08D;
                entityitem.motionZ = d2 * 0.1D;
                this.world.spawnEntity(entityitem);
                // CraftBukkit start - this.random.nextInt(6) + 1 -> playerFishEvent.getExpToDrop()
                if (playerFishEvent.getExpToDrop() > 0) {
                    this.angler.world.spawnEntity(new EntityXPOrb(this.angler.world, this.angler.posX, this.angler.posY + 0.5D, this.angler.posZ + 0.5D, playerFishEvent.getExpToDrop()));
                }
                // CraftBukkit end
                Item item = itemstack.getItem();
                if (item == Items.FISH || item == Items.COOKED_FISH) {
                    this.angler.addStat(StatList.FISH_CAUGHT, 1);
                }
            }
            i = 1;
        }
        if (this.inGround) {
            PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.angler.getBukkitEntity(), null, (Fish) this.getBukkitEntity(), PlayerFishEvent.State.IN_GROUND);
            this.world.getServer().getPluginManager().callEvent(playerFishEvent);
            if (playerFishEvent.isCancelled()) {
                return 0;
            }
            i = 2;
        }
        if (i == 0) {
            PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.angler.getBukkitEntity(), null, (Fish) this.getBukkitEntity(), PlayerFishEvent.State.FAILED_ATTEMPT);
            this.world.getServer().getPluginManager().callEvent(playerFishEvent);
            if (playerFishEvent.isCancelled()) {
                return 0;
            }
        }
        this.setDead();
        return event == null ? i : event.getRodDamage();
    } else {
        return 0;
    }
}
Also used : Player(org.bukkit.entity.Player) EntityPlayer(net.minecraft.entity.player.EntityPlayer) PlayerFishEvent(org.bukkit.event.player.PlayerFishEvent) LootContext(net.minecraft.world.storage.loot.LootContext) WorldServer(net.minecraft.world.WorldServer) Item(net.minecraft.item.Item) EntityItem(net.minecraft.entity.item.EntityItem) Fish(org.bukkit.entity.Fish) StatList(net.minecraft.stats.StatList) LootTableList(net.minecraft.world.storage.loot.LootTableList) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) EntityXPOrb(net.minecraft.entity.item.EntityXPOrb)

Example 4 with Fish

use of org.bukkit.entity.Fish in project NachoSpigot by CobbleSword.

the class EntityFishingHook method l.

public int l() {
    if (this.world.isClientSide) {
        return 0;
    } else {
        byte b0 = 0;
        if (this.hooked != null) {
            // CraftBukkit start
            PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.owner.getBukkitEntity(), this.hooked.getBukkitEntity(), (Fish) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_ENTITY);
            this.world.getServer().getPluginManager().callEvent(playerFishEvent);
            if (playerFishEvent.isCancelled()) {
                return 0;
            }
            // CraftBukkit end
            double d0 = this.owner.locX - this.locX;
            double d1 = this.owner.locY - this.locY;
            double d2 = this.owner.locZ - this.locZ;
            double d3 = (double) MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
            double d4 = 0.1D;
            this.hooked.motX += d0 * d4;
            this.hooked.motY += d1 * d4 + (double) MathHelper.sqrt(d3) * 0.08D;
            this.hooked.motZ += d2 * d4;
            b0 = 3;
        } else if (this.av > 0) {
            EntityItem entityitem = new EntityItem(this.world, this.locX, this.locY, this.locZ, this.m());
            // CraftBukkit start
            PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.owner.getBukkitEntity(), entityitem.getBukkitEntity(), (Fish) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_FISH);
            playerFishEvent.setExpToDrop(this.random.nextInt(6) + 1);
            this.world.getServer().getPluginManager().callEvent(playerFishEvent);
            if (playerFishEvent.isCancelled()) {
                return 0;
            }
            // CraftBukkit end
            double d5 = this.owner.locX - this.locX;
            double d6 = this.owner.locY - this.locY;
            double d7 = this.owner.locZ - this.locZ;
            double d8 = (double) MathHelper.sqrt(d5 * d5 + d6 * d6 + d7 * d7);
            double d9 = 0.1D;
            entityitem.motX = d5 * d9;
            entityitem.motY = d6 * d9 + (double) MathHelper.sqrt(d8) * 0.08D;
            entityitem.motZ = d7 * d9;
            this.world.addEntity(entityitem);
            // CraftBukkit start - this.random.nextInt(6) + 1 -> playerFishEvent.getExpToDrop()
            if (playerFishEvent.getExpToDrop() > 0) {
                this.owner.world.addEntity(new EntityExperienceOrb(this.owner.world, this.owner.locX, this.owner.locY + 0.5D, this.owner.locZ + 0.5D, playerFishEvent.getExpToDrop()));
            }
            // CraftBukkit end
            b0 = 1;
        }
        if (this.as) {
            // CraftBukkit start
            PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.owner.getBukkitEntity(), null, (Fish) this.getBukkitEntity(), PlayerFishEvent.State.IN_GROUND);
            this.world.getServer().getPluginManager().callEvent(playerFishEvent);
            if (playerFishEvent.isCancelled()) {
                return 0;
            }
            // CraftBukkit end
            b0 = 2;
        }
        // CraftBukkit start
        if (b0 == 0) {
            PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.owner.getBukkitEntity(), null, (Fish) this.getBukkitEntity(), PlayerFishEvent.State.FAILED_ATTEMPT);
            this.world.getServer().getPluginManager().callEvent(playerFishEvent);
            if (playerFishEvent.isCancelled()) {
                return 0;
            }
        }
        // CraftBukkit end
        this.die();
        this.owner.hookedFish = null;
        return b0;
    }
}
Also used : Player(org.bukkit.entity.Player) PlayerFishEvent(org.bukkit.event.player.PlayerFishEvent) Fish(org.bukkit.entity.Fish)

Example 5 with Fish

use of org.bukkit.entity.Fish in project WindSpigot by Wind-Development.

the class EntityFishingHook method l.

public int l() {
    if (this.world.isClientSide) {
        return 0;
    } else {
        byte b0 = 0;
        if (this.hooked != null) {
            // CraftBukkit start
            PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.owner.getBukkitEntity(), this.hooked.getBukkitEntity(), (Fish) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_ENTITY);
            this.world.getServer().getPluginManager().callEvent(playerFishEvent);
            if (playerFishEvent.isCancelled()) {
                return 0;
            }
            // CraftBukkit end
            double d0 = this.owner.locX - this.locX;
            double d1 = this.owner.locY - this.locY;
            double d2 = this.owner.locZ - this.locZ;
            double d3 = MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
            double d4 = 0.1D;
            this.hooked.motX += d0 * d4;
            this.hooked.motY += d1 * d4 + MathHelper.sqrt(d3) * 0.08D;
            this.hooked.motZ += d2 * d4;
            b0 = 3;
        } else if (this.av > 0) {
            EntityItem entityitem = new EntityItem(this.world, this.locX, this.locY, this.locZ, this.m());
            // CraftBukkit start
            PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.owner.getBukkitEntity(), entityitem.getBukkitEntity(), (Fish) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_FISH);
            playerFishEvent.setExpToDrop(this.random.nextInt(6) + 1);
            this.world.getServer().getPluginManager().callEvent(playerFishEvent);
            if (playerFishEvent.isCancelled()) {
                return 0;
            }
            // CraftBukkit end
            double d5 = this.owner.locX - this.locX;
            double d6 = this.owner.locY - this.locY;
            double d7 = this.owner.locZ - this.locZ;
            double d8 = MathHelper.sqrt(d5 * d5 + d6 * d6 + d7 * d7);
            double d9 = 0.1D;
            entityitem.motX = d5 * d9;
            entityitem.motY = d6 * d9 + MathHelper.sqrt(d8) * 0.08D;
            entityitem.motZ = d7 * d9;
            this.world.addEntity(entityitem);
            // playerFishEvent.getExpToDrop()
            if (playerFishEvent.getExpToDrop() > 0) {
                this.owner.world.addEntity(new EntityExperienceOrb(this.owner.world, this.owner.locX, this.owner.locY + 0.5D, this.owner.locZ + 0.5D, playerFishEvent.getExpToDrop()));
            }
            // CraftBukkit end
            b0 = 1;
        }
        if (this.as) {
            // CraftBukkit start
            PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.owner.getBukkitEntity(), null, (Fish) this.getBukkitEntity(), PlayerFishEvent.State.IN_GROUND);
            this.world.getServer().getPluginManager().callEvent(playerFishEvent);
            if (playerFishEvent.isCancelled()) {
                return 0;
            }
            // CraftBukkit end
            b0 = 2;
        }
        // CraftBukkit start
        if (b0 == 0) {
            PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.owner.getBukkitEntity(), null, (Fish) this.getBukkitEntity(), PlayerFishEvent.State.FAILED_ATTEMPT);
            this.world.getServer().getPluginManager().callEvent(playerFishEvent);
            if (playerFishEvent.isCancelled()) {
                return 0;
            }
        }
        // CraftBukkit end
        this.die();
        this.owner.hookedFish = null;
        return b0;
    }
}
Also used : Player(org.bukkit.entity.Player) PlayerFishEvent(org.bukkit.event.player.PlayerFishEvent) Fish(org.bukkit.entity.Fish)

Aggregations

Fish (org.bukkit.entity.Fish)5 Player (org.bukkit.entity.Player)5 PlayerFishEvent (org.bukkit.event.player.PlayerFishEvent)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 WorldServer (net.minecraft.world.WorldServer)2 List (java.util.List)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityXPOrb (net.minecraft.entity.item.EntityXPOrb)1 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 StatList (net.minecraft.stats.StatList)1 BlockPos (net.minecraft.util.math.BlockPos)1 AbstractFish (net.minecraft.world.entity.animal.AbstractFish)1 LootContext (net.minecraft.world.storage.loot.LootContext)1 LootTableList (net.minecraft.world.storage.loot.LootTableList)1 CraftPlayer (org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer)1 PlayerBucketEntityEvent (org.bukkit.event.player.PlayerBucketEntityEvent)1 PlayerBucketFishEvent (org.bukkit.event.player.PlayerBucketFishEvent)1