package net.minecraft.world.level.block.piston;

import net.minecraft.world.level.block.state.StateHolder;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.CollisionContext;
import java.util.Collections;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.item.ItemStack;
import java.util.List;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import javax.annotation.Nullable;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.properties.PistonType;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.block.BaseEntityBlock;

public class MovingPistonBlock extends BaseEntityBlock {
    public static final DirectionProperty FACING;
    public static final EnumProperty<PistonType> TYPE;
    
    public MovingPistonBlock(final Properties c) {
        super(c);
        this.registerDefaultState((((StateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)MovingPistonBlock.FACING, Direction.NORTH)).<PistonType, PistonType>setValue(MovingPistonBlock.TYPE, PistonType.DEFAULT));
    }
    
    @Nullable
    @Override
    public BlockEntity newBlockEntity(final BlockGetter bpg) {
        return null;
    }
    
    public static BlockEntity newMovingBlockEntity(final BlockState cfj, final Direction fz, final boolean boolean3, final boolean boolean4) {
        return new PistonMovingBlockEntity(cfj, fz, boolean3, boolean4);
    }
    
    @Override
    public void onRemove(final BlockState cfj1, final Level bqb, final BlockPos fu, final BlockState cfj4, final boolean boolean5) {
        if (cfj1.is(cfj4.getBlock())) {
            return;
        }
        final BlockEntity cdl7 = bqb.getBlockEntity(fu);
        if (cdl7 instanceof PistonMovingBlockEntity) {
            ((PistonMovingBlockEntity)cdl7).finalTick();
        }
    }
    
    @Override
    public void destroy(final LevelAccessor bqc, final BlockPos fu, final BlockState cfj) {
        final BlockPos fu2 = fu.relative(cfj.<Direction>getValue((Property<Direction>)MovingPistonBlock.FACING).getOpposite());
        final BlockState cfj2 = bqc.getBlockState(fu2);
        if (cfj2.getBlock() instanceof PistonBaseBlock && cfj2.<Boolean>getValue((Property<Boolean>)PistonBaseBlock.EXTENDED)) {
            bqc.removeBlock(fu2, false);
        }
    }
    
    @Override
    public InteractionResult use(final BlockState cfj, final Level bqb, final BlockPos fu, final Player bec, final InteractionHand anf, final BlockHitResult deh) {
        if (!bqb.isClientSide && bqb.getBlockEntity(fu) == null) {
            bqb.removeBlock(fu, false);
            return InteractionResult.CONSUME;
        }
        return InteractionResult.PASS;
    }
    
    @Override
    public List<ItemStack> getDrops(final BlockState cfj, final LootContext.Builder a) {
        final PistonMovingBlockEntity cff4 = this.getBlockEntity(a.getLevel(), a.<BlockPos>getParameter(LootContextParams.BLOCK_POS));
        if (cff4 == null) {
            return Collections.<ItemStack>emptyList();
        }
        return cff4.getMovedState().getDrops(a);
    }
    
    @Override
    public VoxelShape getShape(final BlockState cfj, final BlockGetter bpg, final BlockPos fu, final CollisionContext der) {
        return Shapes.empty();
    }
    
    @Override
    public VoxelShape getCollisionShape(final BlockState cfj, final BlockGetter bpg, final BlockPos fu, final CollisionContext der) {
        final PistonMovingBlockEntity cff6 = this.getBlockEntity(bpg, fu);
        if (cff6 != null) {
            return cff6.getCollisionShape(bpg, fu);
        }
        return Shapes.empty();
    }
    
    @Nullable
    private PistonMovingBlockEntity getBlockEntity(final BlockGetter bpg, final BlockPos fu) {
        final BlockEntity cdl4 = bpg.getBlockEntity(fu);
        if (cdl4 instanceof PistonMovingBlockEntity) {
            return (PistonMovingBlockEntity)cdl4;
        }
        return null;
    }
    
    @Override
    public ItemStack getCloneItemStack(final BlockGetter bpg, final BlockPos fu, final BlockState cfj) {
        return ItemStack.EMPTY;
    }
    
    @Override
    public BlockState rotate(final BlockState cfj, final Rotation cap) {
        return ((StateHolder<O, BlockState>)cfj).<Comparable, Direction>setValue((Property<Comparable>)MovingPistonBlock.FACING, cap.rotate(cfj.<Direction>getValue((Property<Direction>)MovingPistonBlock.FACING)));
    }
    
    @Override
    public BlockState mirror(final BlockState cfj, final Mirror bzj) {
        return cfj.rotate(bzj.getRotation(cfj.<Direction>getValue((Property<Direction>)MovingPistonBlock.FACING)));
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(MovingPistonBlock.FACING, MovingPistonBlock.TYPE);
    }
    
    @Override
    public boolean isPathfindable(final BlockState cfj, final BlockGetter bpg, final BlockPos fu, final PathComputationType czg) {
        return false;
    }
    
    static {
        FACING = PistonHeadBlock.FACING;
        TYPE = PistonHeadBlock.TYPE;
    }
}
