CCCPaste

ee6decc641f26

    protected boolean canPushLine(World world, int x, int y, int z, Direction direction, int maxPushedBlocks) {
        int xo = x + direction.getOffsetX();
        int yo = y + direction.getOffsetY();
        int zo = z + direction.getOffsetZ();
        int blocks = 0;
        boolean didCrush = false;

        while(true) {
            if (blocks < maxPushedBlocks + 1) {
                if (yo < 0 || yo >= world.getHeightBlocks()) {
                    return false;
                }

                int id = world.getBlockId(xo, yo, zo);
                if (id != 0) {
                    if (!this.isPushable(id, world, xo, yo, zo, true)) {
                        if (blocks != 1 || !BlockTags.PISTON_CRUSHING.appliesTo(Blocks.getBlock(id)) || !this.tryCrush(world, x, y, z, direction)) {
                            return false;
                        }

                        didCrush = true;
                    } else if (Blocks.blocksList[id].getPistonPushReaction(world, xo, yo, zo) != 1) {
                        if (blocks == maxPushedBlocks) {
                            return false;
                        }

                        xo += direction.getOffsetX();
                        yo += direction.getOffsetY();
                        zo += direction.getOffsetZ();
                        ++blocks;
                        continue;
                    }
                }
            }

            if (!didCrush && blocks == 1) {
                xo = x + direction.getOffsetX();
                yo = y + direction.getOffsetY();
                zo = z + direction.getOffsetZ();
                Block block = world.getBlock(xo, yo, zo);
                if (block == null) {
                    return true;
                }

                int blockMeta = world.getBlockMetadata(xo, yo, zo);
                TileEntity tileEntity = world.getTileEntity(xo, yo, zo);
                world.removeBlockTileEntity(xo, yo, zo);
                world.setBlockWithNotify(xo, yo, zo, 0);
                if (!world.isClientSide) {
                    EntityFallingBlock entityFallingBlock = new EntityFallingBlock(world, (double)xo + (double)0.5F, (double)yo + (double)0.5F, (double)zo + (double)0.5F, block.id(), blockMeta, tileEntity);
                    entityFallingBlock.hasRemovedBlock = true;
                    if (tileEntity instanceof IVehicle) {
                        Entity rider = ((IVehicle)tileEntity).getPassenger();
                        ((IVehicle)tileEntity).ejectRider();
                        if (rider != null) {
                            rider.startRiding(entityFallingBlock);
                        }
                    }

                    world.entityJoinedWorld(entityFallingBlock);
                    double speed = (double)2.0F;
                    entityFallingBlock.fling((double)direction.getOffsetX() * (double)2.0F, (double)direction.getOffsetY() * (double)2.0F, (double)direction.getOffsetZ() * (double)2.0F, 1.0F);
                    this.flungBlock = entityFallingBlock;
                }
            }

            return true;
        }
    }