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.world.level.material.Fluid;
import net.minecraft.tags.Tag;
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 fv, final ItemStack bki) {
        final Direction fz4 = fv.getBlockState().<Direction>getValue((Property<Direction>)DispenserBlock.FACING);
        final Level bqb5 = fv.getLevel();
        final double double6 = fv.x() + fz4.getStepX() * 1.125f;
        final double double7 = fv.y() + fz4.getStepY() * 1.125f;
        final double double8 = fv.z() + fz4.getStepZ() * 1.125f;
        final BlockPos fu12 = fv.getPos().relative(fz4);
        double double9;
        if (bqb5.getFluidState(fu12).is(FluidTags.WATER)) {
            double9 = 1.0;
        }
        else {
            if (!bqb5.getBlockState(fu12).isAir() || !bqb5.getFluidState(fu12.below()).is(FluidTags.WATER)) {
                return this.defaultDispenseItemBehavior.dispense(fv, bki);
            }
            double9 = 0.0;
        }
        final Boat bft15 = new Boat(bqb5, double6, double7 + double9, double8);
        bft15.setType(this.type);
        bft15.yRot = fz4.toYRot();
        bqb5.addFreshEntity(bft15);
        bki.shrink(1);
        return bki;
    }
    
    @Override
    protected void playSound(final BlockSource fv) {
        fv.getLevel().levelEvent(1000, fv.getPos(), 0);
    }
}
