package net.minecraft.core.dispenser;

import net.minecraft.core.BlockPos;
import net.minecraft.world.item.Item;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.world.item.DirectionalPlaceContext;
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.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.core.BlockSource;

public class ShulkerBoxDispenseBehavior extends OptionalDispenseItemBehavior {
    @Override
    protected ItemStack execute(final BlockSource fl, final ItemStack ben) {
        this.success = false;
        final Item bei4 = ben.getItem();
        if (bei4 instanceof BlockItem) {
            final Direction fp5 = fl.getBlockState().<Direction>getValue((Property<Direction>)DispenserBlock.FACING);
            final BlockPos fk6 = fl.getPos().relative(fp5);
            final Direction fp6 = fl.getLevel().isEmptyBlock(fk6.below()) ? fp5 : Direction.UP;
            this.success = (((BlockItem)bei4).place(new DirectionalPlaceContext(fl.getLevel(), fk6, fp5, ben, fp6)) == InteractionResult.SUCCESS);
        }
        return ben;
    }
}
