package net.minecraft.core.dispenser;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.entity.Entity;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.DispenserBlock;
import net.minecraft.core.Direction;
import net.minecraft.world.item.ItemStack;
import net.minecraft.core.BlockSource;
import net.minecraft.world.entity.vehicle.Boat;

public class BoatDispenseItemBehavior extends DefaultDispenseItemBehavior {
    private final DefaultDispenseItemBehavior defaultDispenseItemBehavior;
    private final Boat.Type type;
    
    public BoatDispenseItemBehavior(final Boat.Type b) {
        this.defaultDispenseItemBehavior = new DefaultDispenseItemBehavior();
        this.type = b;
    }
    
    public ItemStack execute(final BlockSource fl, final ItemStack ben) {
        final Direction fp4 = fl.getBlockState().<Direction>getValue((Property<Direction>)DispenserBlock.FACING);
        final Level bjw5 = fl.getLevel();
        final double double6 = fl.x() + fp4.getStepX() * 1.125f;
        final double double7 = fl.y() + fp4.getStepY() * 1.125f;
        final double double8 = fl.z() + fp4.getStepZ() * 1.125f;
        final BlockPos fk12 = fl.getPos().relative(fp4);
        double double9;
        if (bjw5.getFluidState(fk12).is(FluidTags.WATER)) {
            double9 = 1.0;
        }
        else {
            if (!bjw5.getBlockState(fk12).isAir() || !bjw5.getFluidState(fk12.below()).is(FluidTags.WATER)) {
                return this.defaultDispenseItemBehavior.dispense(fl, ben);
            }
            double9 = 0.0;
        }
        final Boat azz15 = new Boat(bjw5, double6, double7 + double9, double8);
        azz15.setType(this.type);
        azz15.yRot = fp4.toYRot();
        bjw5.addFreshEntity(azz15);
        ben.shrink(1);
        return ben;
    }
    
    @Override
    protected void playSound(final BlockSource fl) {
        fl.getLevel().levelEvent(1000, fl.getPos(), 0);
    }
}
