Search in sources :

Example 1 with IFishableLiquidBlock

use of stevekung.mods.moreplanets.utils.blocks.IFishableLiquidBlock in project MorePlanets by SteveKunG.

the class EntitySpaceFishHook method handleHookRetraction.

@Override
public int handleHookRetraction() {
    if (!this.world.isRemote && this.angler != null) {
        int i = 0;
        if (this.caughtEntity != null) {
            this.bringInHookedEntity();
            this.world.setEntityState(this, (byte) 31);
            i = this.caughtEntity instanceof EntityItem ? 3 : 5;
        } else if (this.ticksCatchable > 0) {
            LootContext.Builder lootBuilder = new LootContext.Builder((WorldServer) this.world);
            lootBuilder.withLuck(this.luck + this.angler.getLuck());
            double x = MathHelper.floor(this.posX);
            double y = MathHelper.floor(this.getEntityBoundingBox().minY) + 1.0F;
            double z = MathHelper.floor(this.posZ);
            Block block = this.world.getBlockState(new BlockPos(x, y - 1, z)).getBlock();
            ResourceLocation resource = block instanceof IFishableLiquidBlock ? ((IFishableLiquidBlock) block).getLootTable() : this.world.provider instanceof IGalacticraftWorldProvider ? MPLootTables.SPACE_FISHING : LootTableList.GAMEPLAY_FISHING;
            for (ItemStack itemStack : this.world.getLootTableManager().getLootTableFromLocation(resource).generateLootForPools(this.rand, lootBuilder.build())) {
                EntityItem entityItem = new EntityItem(this.world, this.posX, this.posY, this.posZ, itemStack);
                double d0 = this.angler.posX - this.posX;
                double d1 = this.angler.posY - this.posY;
                double d2 = this.angler.posZ - this.posZ;
                double d3 = MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
                entityItem.motionX = d0 * 0.1D;
                entityItem.motionY = d1 * 0.1D + MathHelper.sqrt(d3) * 0.08D;
                entityItem.motionZ = d2 * 0.1D;
                this.world.spawnEntity(entityItem);
                this.angler.world.spawnEntity(new EntityXPOrb(this.angler.world, this.angler.posX, this.angler.posY + 0.5D, this.angler.posZ + 0.5D, this.rand.nextInt(6) + 1));
                Item item = itemStack.getItem();
                if (item == Items.FISH || item == Items.COOKED_FISH) {
                    this.angler.addStat(StatList.FISH_CAUGHT, 1);
                }
            }
            i = 1;
        }
        if (this.inGround) {
            i = 2;
        }
        this.setDead();
        return i;
    } else {
        return 0;
    }
}
Also used : IFishableLiquidBlock(stevekung.mods.moreplanets.utils.blocks.IFishableLiquidBlock) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) LootContext(net.minecraft.world.storage.loot.LootContext) WorldServer(net.minecraft.world.WorldServer) Item(net.minecraft.item.Item) EntityItem(net.minecraft.entity.item.EntityItem) ResourceLocation(net.minecraft.util.ResourceLocation) Block(net.minecraft.block.Block) IFishableLiquidBlock(stevekung.mods.moreplanets.utils.blocks.IFishableLiquidBlock) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) EntityXPOrb(net.minecraft.entity.item.EntityXPOrb)

Example 2 with IFishableLiquidBlock

use of stevekung.mods.moreplanets.utils.blocks.IFishableLiquidBlock in project MorePlanets by SteveKunG.

the class EntitySpaceFishHook method catchingFish.

private void catchingFish(BlockPos pos) {
    WorldServer worldserver = (WorldServer) this.world;
    int i = 1;
    BlockPos blockpos = pos.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;
        } else {
            this.motionY -= 0.2D * this.rand.nextFloat() * this.rand.nextFloat();
        }
    } else if (this.ticksCatchableDelay > 0) {
        this.ticksCatchableDelay -= i;
        if (this.ticksCatchableDelay > 0) {
            this.fishApproachAngle = (float) (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 + f1 * this.ticksCatchableDelay * 0.1F;
            double d1 = MathHelper.floor(this.getEntityBoundingBox().minY) + 1.0F;
            double d2 = this.posZ + f2 * this.ticksCatchableDelay * 0.1F;
            Block block = worldserver.getBlockState(new BlockPos(d0, d1 - 1.0D, d2)).getBlock();
            if (block == Blocks.WATER || block == Blocks.FLOWING_WATER || block instanceof IFishableLiquidBlock) {
                if (this.rand.nextFloat() < 0.15F) {
                    worldserver.spawnParticle(EnumParticleTypes.WATER_BUBBLE, d0, d1 - 0.10000000149011612D, d2, 1, f1, 0.1D, f2, 0.0D, new int[0]);
                }
                float f3 = f1 * 0.04F;
                float f4 = f2 * 0.04F;
                worldserver.spawnParticle(EnumParticleTypes.WATER_WAKE, d0, d1, d2, 0, f4, 0.01D, -f3, 1.0D, new int[0]);
                worldserver.spawnParticle(EnumParticleTypes.WATER_WAKE, d0, d1, d2, 0, -f4, 0.01D, f3, 1.0D, new int[0]);
            }
        } else {
            this.motionY = -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), this.width, 0.0D, this.width, 0.20000000298023224D, new int[0]);
            worldserver.spawnParticle(EnumParticleTypes.WATER_WAKE, this.posX, d3, this.posZ, (int) (1.0F + this.width * 20.0F), this.width, 0.0D, this.width, 0.20000000298023224D, new int[0]);
            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) (f5 + (20 - this.ticksCaughtDelay) * 0.05D);
        } else if (this.ticksCaughtDelay < 40) {
            f5 = (float) (f5 + (40 - this.ticksCaughtDelay) * 0.02D);
        } else if (this.ticksCaughtDelay < 60) {
            f5 = (float) (f5 + (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 + MathHelper.sin(f6) * f7 * 0.1F;
            double d5 = MathHelper.floor(this.getEntityBoundingBox().minY) + 1.0F;
            double d6 = this.posZ + MathHelper.cos(f6) * f7 * 0.1F;
            Block block1 = worldserver.getBlockState(new BlockPos((int) d4, (int) d5 - 1, (int) d6)).getBlock();
            if (block1 == Blocks.WATER || block1 == Blocks.FLOWING_WATER || block1 instanceof IFishableLiquidBlock) {
                worldserver.spawnParticle(EnumParticleTypes.WATER_SPLASH, d4, d5, d6, 2 + this.rand.nextInt(2), 0.10000000149011612D, 0.0D, 0.10000000149011612D, 0.0D, new int[0]);
            }
        }
        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 : IFishableLiquidBlock(stevekung.mods.moreplanets.utils.blocks.IFishableLiquidBlock) Block(net.minecraft.block.Block) IFishableLiquidBlock(stevekung.mods.moreplanets.utils.blocks.IFishableLiquidBlock) WorldServer(net.minecraft.world.WorldServer)

Aggregations

Block (net.minecraft.block.Block)2 WorldServer (net.minecraft.world.WorldServer)2 IFishableLiquidBlock (stevekung.mods.moreplanets.utils.blocks.IFishableLiquidBlock)2 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)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 ResourceLocation (net.minecraft.util.ResourceLocation)1 LootContext (net.minecraft.world.storage.loot.LootContext)1