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

import net.minecraft.world.level.block.state.AbstractStateHolder;
import net.minecraft.world.level.pathfinder.PathComputationType;
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.Block;
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((((AbstractStateHolder<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 bjg) {
        return null;
    }
    
    public static BlockEntity newMovingBlockEntity(final BlockState byj, final Direction fp, final boolean boolean3, final boolean boolean4) {
        return new PistonMovingBlockEntity(byj, fp, boolean3, boolean4);
    }
    
    @Override
    public void onRemove(final BlockState byj1, final Level bjw, final BlockPos fk, final BlockState byj4, final boolean boolean5) {
        if (byj1.getBlock() == byj4.getBlock()) {
            return;
        }
        final BlockEntity bwl7 = bjw.getBlockEntity(fk);
        if (bwl7 instanceof PistonMovingBlockEntity) {
            ((PistonMovingBlockEntity)bwl7).finalTick();
        }
    }
    
    @Override
    public void destroy(final LevelAccessor bjx, final BlockPos fk, final BlockState byj) {
        final BlockPos fk2 = fk.relative(byj.<Direction>getValue((Property<Direction>)MovingPistonBlock.FACING).getOpposite());
        final BlockState byj2 = bjx.getBlockState(fk2);
        if (byj2.getBlock() instanceof PistonBaseBlock && byj2.<Boolean>getValue((Property<Boolean>)PistonBaseBlock.EXTENDED)) {
            bjx.removeBlock(fk2, false);
        }
    }
    
    @Override
    public boolean isRedstoneConductor(final BlockState byj, final BlockGetter bjg, final BlockPos fk) {
        return false;
    }
    
    @Override
    public boolean isSuffocating(final BlockState byj, final BlockGetter bjg, final BlockPos fk) {
        return false;
    }
    
    @Override
    public InteractionResult use(final BlockState byj, final Level bjw, final BlockPos fk, final Player ayj, final InteractionHand ajk, final BlockHitResult cvg) {
        if (!bjw.isClientSide && bjw.getBlockEntity(fk) == null) {
            bjw.removeBlock(fk, false);
            return InteractionResult.CONSUME;
        }
        return InteractionResult.PASS;
    }
    
    @Override
    public List<ItemStack> getDrops(final BlockState byj, final LootContext.Builder a) {
        final PistonMovingBlockEntity byf4 = this.getBlockEntity(a.getLevel(), a.<BlockPos>getParameter(LootContextParams.BLOCK_POS));
        if (byf4 == null) {
            return Collections.<ItemStack>emptyList();
        }
        return byf4.getMovedState().getDrops(a);
    }
    
    @Override
    public VoxelShape getShape(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final CollisionContext cvq) {
        return Shapes.empty();
    }
    
    @Override
    public VoxelShape getCollisionShape(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final CollisionContext cvq) {
        final PistonMovingBlockEntity byf6 = this.getBlockEntity(bjg, fk);
        if (byf6 != null) {
            return byf6.getCollisionShape(bjg, fk);
        }
        return Shapes.empty();
    }
    
    @Nullable
    private PistonMovingBlockEntity getBlockEntity(final BlockGetter bjg, final BlockPos fk) {
        final BlockEntity bwl4 = bjg.getBlockEntity(fk);
        if (bwl4 instanceof PistonMovingBlockEntity) {
            return (PistonMovingBlockEntity)bwl4;
        }
        return null;
    }
    
    @Override
    public ItemStack getCloneItemStack(final BlockGetter bjg, final BlockPos fk, final BlockState byj) {
        return ItemStack.EMPTY;
    }
    
    @Override
    public BlockState rotate(final BlockState byj, final Rotation btu) {
        return ((AbstractStateHolder<O, BlockState>)byj).<Comparable, Direction>setValue((Property<Comparable>)MovingPistonBlock.FACING, btu.rotate(byj.<Direction>getValue((Property<Direction>)MovingPistonBlock.FACING)));
    }
    
    @Override
    public BlockState mirror(final BlockState byj, final Mirror bsu) {
        return byj.rotate(bsu.getRotation(byj.<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 byj, final BlockGetter bjg, final BlockPos fk, final PathComputationType cqr) {
        return false;
    }
    
    static {
        FACING = PistonHeadBlock.FACING;
        TYPE = PistonHeadBlock.TYPE;
    }
}
