package net.minecraft.client.resources.sounds;

import net.minecraft.world.level.Level;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.BubbleColumnBlock;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.client.player.LocalPlayer;

public class BubbleColumnAmbientSoundHandler implements AmbientSoundHandler {
    private final LocalPlayer player;
    private boolean wasInBubbleColumn;
    private boolean firstTick;
    
    public BubbleColumnAmbientSoundHandler(final LocalPlayer ebf) {
        this.firstTick = true;
        this.player = ebf;
    }
    
    @Override
    public void tick() {
        final Level bqb2 = this.player.level;
        final BlockState cfj2 = bqb2.getBlockStatesIfLoaded(this.player.getBoundingBox().inflate(0.0, -0.4000000059604645, 0.0).deflate(0.001)).filter(cfj -> cfj.is(Blocks.BUBBLE_COLUMN)).findFirst().orElse(null);
        if (cfj2 != null) {
            if (!this.wasInBubbleColumn && !this.firstTick && cfj2.is(Blocks.BUBBLE_COLUMN) && !this.player.isSpectator()) {
                final boolean boolean4 = cfj2.<Boolean>getValue((Property<Boolean>)BubbleColumnBlock.DRAG_DOWN);
                if (boolean4) {
                    this.player.playSound(SoundEvents.BUBBLE_COLUMN_WHIRLPOOL_INSIDE, 1.0f, 1.0f);
                }
                else {
                    this.player.playSound(SoundEvents.BUBBLE_COLUMN_UPWARDS_INSIDE, 1.0f, 1.0f);
                }
            }
            this.wasInBubbleColumn = true;
        }
        else {
            this.wasInBubbleColumn = false;
        }
        this.firstTick = false;
    }
}
